-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.h++
119 lines (97 loc) · 2.36 KB
/
window.h++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef WINDOW_H
#define WINDOW_H
#include "shared.h++"
#include <unordered_map>
#include <filesystem>
#include <SDL2/SDL.h>
#include <GL/glew.h>
#if HAS_OPENCV
#include <opencv2/highgui/highgui.hpp>
#endif
#include "matrix.h++"
#ifdef WINDOW_DEBUG
#define _WINDOW_DEBUG 1
#else
#define _WINDOW_DEBUG 0
#endif
#ifdef WINDOW_ATTR_DEBUG
#define _WINDOW_ATTR_DEBUG 1
#else
#define _WINDOW_ATTR_DEBUG 0
#endif
#ifdef WINDOW_GL_DEBUG
#define _WINDOW_GL_DEBUG 1
#else
#define _WINDOW_GL_DEBUG 0
#endif
#ifdef WINDOW_KEY_DEBUG
#define _WINDOW_KEY_DEBUG 1
#else
#define _WINDOW_KEY_DEBUG 0
#endif
#ifdef WINDOW_WRITEFRAME_DEBUG
#define _WINDOW_WRITEFRAME_DEBUG 1
#else
#define _WINDOW_WRITEFRAME_DEBUG 0
#endif
class window_exception: public std::exception{
public:
explicit window_exception(const char* message);
virtual ~window_exception() noexcept;
virtual const char* what() const noexcept;
const char* msg;
};
class Window{
private:
SDL_GLContext gl_context;
SDL_Window *window;
int width;
int height;
GLuint program;
GLuint* handles_array;
GLuint* strides_array;
int numhandles;
public:
GLsizei draw_vertices;
#if HAS_OPENCV
private:
bool saveframes;
GLuint frameTexture;
GLuint frameBuffer;
int framestosave;
int framesdone;
cv::VideoWriter *writer;
#endif
public:
struct vertexdata {
private:
int handle;
vertexdata(int handle);
friend Window;
};
void (*onframe)(Window*,void*)=NULL;
void (*draw)(Window*,void*)=NULL;
void (*onkeyup)(Window*,SDL_Keysym,void*)=NULL;
void (*onkeydown)(Window*,SDL_Keysym,void*)=NULL;
void *data;
bool closed;
Window(int width, int height, const char* name);
void makeShader(std::filesystem::path vertex_shader_path, std::filesystem::path fragment_shader_path);
void makeShaderFromSource(char *vertex_shader_source, char *fragment_shader_source);
void mainLoop();
vertexdata addVertexData(GLfloat data[],GLint size,GLint stride);
void applyVertexData(vertexdata v,const char* name,GLint floatspervertex,GLint offset=0);
void setUniformMat4x4(const char* name,const matrix4x4 &matrix);
void setUniformVec3(const char* name,float *vec);
void setUniformFloat(const char* name,float f);
void setUniformInt(const char* name,GLuint i);
void enableSaveFrames(int frames);
#if HAS_OPENCV
private:
void setupSaveFrames();
void writeFrame();
#endif
public:
~Window();
};
#endif