+903
-838
bite.c
+903
-838
bite.c
···
1
1
#include "bite.h"
2
2
3
3
#if defined(_WIN32)
4
-
#include <windows.h>
5
-
#ifndef WINDOWS_LEAN_AND_MEAN
6
-
#define WINDOWS_LEAN_AND_MEAN 1
7
-
#endif
8
-
#include <tchar.h>
9
-
#include <gl/GL.h>
10
-
#include <gl/GLU.h>
4
+
#include <windows.h>
5
+
#ifndef WINDOWS_LEAN_AND_MEAN
6
+
#define WINDOWS_LEAN_AND_MEAN 1
7
+
#endif
8
+
#include <gl/GL.h>
9
+
#include <gl/GLU.h>
10
+
#include <tchar.h>
11
11
#elif defined(__EMSCRIPTEN__)
12
-
#include <emscripten.h>
13
-
#include <emscripten/html5.h>
14
-
#include <GLES2/gl2.h>
15
-
#include <time.h>
12
+
#include <GLES2/gl2.h>
13
+
#include <emscripten.h>
14
+
#include <emscripten/html5.h>
15
+
#include <time.h>
16
+
#else
17
+
#include <GL/gl.h>
18
+
#include <GL/glx.h>
19
+
#include <X11/Xlib.h>
20
+
#include <X11/Xutil.h>
21
+
#include <dlfcn.h>
22
+
#include <time.h>
23
+
#include <unistd.h>
24
+
#endif
25
+
26
+
#if defined(_WIN32)
27
+
char keys[512] = {
28
+
[VK_BACK] = BITEK_BACKSPACE,
29
+
[VK_TAB] = BITEK_TAB,
30
+
[VK_RETURN] = BITEK_RETURN,
31
+
[VK_SHIFT] = BITEK_SHIFT,
32
+
[VK_CONTROL] = BITEK_CONTROL,
33
+
34
+
[VK_ESCAPE] = BITEK_ESCAPE,
35
+
[VK_SPACE] = BITEK_SPACE,
36
+
[VK_PRIOR] = BITEK_PAGEUP,
37
+
[VK_NEXT] = BITEK_PAGEDOWN,
38
+
39
+
[VK_LEFT] = BITEK_LEFT,
40
+
[VK_UP] = BITEK_UP,
41
+
[VK_RIGHT] = BITEK_RIGHT,
42
+
[VK_DOWN] = BITEK_DOWN,
43
+
44
+
[VK_END] = BITEK_END,
45
+
[VK_HOME] = BITEK_HOME,
46
+
[VK_INSERT] = BITEK_INSERT,
47
+
[VK_DELETE] = BITEK_DELETE,
48
+
49
+
[0x30] = BITEK_0,
50
+
[0x31] = BITEK_1,
51
+
[0x32] = BITEK_2,
52
+
[0x33] = BITEK_3,
53
+
[0x34] = BITEK_4,
54
+
[0x35] = BITEK_5,
55
+
[0x36] = BITEK_6,
56
+
[0x37] = BITEK_7,
57
+
[0x38] = BITEK_8,
58
+
[0x39] = BITEK_9,
59
+
60
+
[0x41] = BITEK_A,
61
+
[0x42] = BITEK_B,
62
+
[0x43] = BITEK_C,
63
+
[0x44] = BITEK_D,
64
+
[0x45] = BITEK_E,
65
+
[0x46] = BITEK_F,
66
+
[0x47] = BITEK_G,
67
+
[0x48] = BITEK_H,
68
+
[0x49] = BITEK_I,
69
+
[0x4A] = BITEK_J,
70
+
[0x4B] = BITEK_K,
71
+
[0x4C] = BITEK_L,
72
+
[0x4D] = BITEK_M,
73
+
[0x4E] = BITEK_N,
74
+
[0x4F] = BITEK_O,
75
+
[0x50] = BITEK_P,
76
+
[0x51] = BITEK_Q,
77
+
[0x52] = BITEK_R,
78
+
[0x53] = BITEK_S,
79
+
[0x54] = BITEK_T,
80
+
[0x55] = BITEK_U,
81
+
[0x56] = BITEK_V,
82
+
[0x57] = BITEK_W,
83
+
[0x58] = BITEK_X,
84
+
[0x59] = BITEK_Y,
85
+
[0x5A] = BITEK_Z,
86
+
};
16
87
#else
17
-
#include <unistd.h>
18
-
#include <X11/Xlib.h>
19
-
#include <X11/Xutil.h>
20
-
#include <GL/glx.h>
21
-
#include <dlfcn.h>
22
-
#include <GL/gl.h>
23
-
#include <time.h>
88
+
char keys[512] = {
89
+
[XK_tab] = BITEK_TAB,
90
+
[XK_space] = BITEK_SPACE,
91
+
[XK_return] = BITEK_RETURN,
92
+
};
24
93
#endif
25
94
26
95
struct be_Shader {
27
-
GLuint handle;
28
-
GLint world_uniform, modelview_uniform;
96
+
GLuint handle;
97
+
GLint world_uniform, modelview_uniform;
29
98
};
30
99
31
100
struct be_Texture {
32
-
GLuint handle;
33
-
int width, height;
34
-
int filter[2];
35
-
int wrap[2];
101
+
GLuint handle;
102
+
int width, height;
103
+
int filter[2];
104
+
int wrap[2];
36
105
};
37
106
38
107
struct be_Framebuffer {
39
-
GLuint handle;
40
-
be_Texture texture;
108
+
GLuint handle;
109
+
be_Texture texture;
41
110
};
42
111
43
112
struct be_Window {
44
-
int x, y;
45
-
int width, height;
113
+
int x, y;
114
+
int width, height;
46
115
#if defined(_WIN32)
47
-
HWND handle;
48
-
HDC dev_context;
116
+
HWND handle;
117
+
HDC dev_context;
49
118
#elif defined(__EMSCRIPTEN__)
50
119
#else
51
-
Display* display;
52
-
Window handle;
53
-
Colormap map;
120
+
Display *display;
121
+
Window handle;
122
+
Colormap map;
54
123
55
-
GLXFBConfig fbconf;
124
+
GLXFBConfig fbconf;
56
125
#endif
57
126
};
58
127
59
128
typedef struct be_Render be_Render;
60
129
struct be_Render {
61
130
#if defined(_WIN32)
62
-
HGLRC gl_context;
131
+
HGLRC gl_context;
63
132
#elif defined(__EMSCRIPTEN__)
64
-
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE gl_context;
133
+
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE gl_context;
65
134
#else
66
-
GLXContext gl_context;
135
+
GLXContext gl_context;
67
136
#endif
68
137
69
-
int mode;
70
-
GLuint vao, vbo;
138
+
int mode;
139
+
GLuint vao, vbo;
71
140
};
72
141
73
142
struct be_Context {
74
-
int running;
75
-
be_Window window;
76
-
be_Render render;
77
-
be_EventCallback callbacks[BITE_EVENTS];
143
+
int running;
144
+
be_Window window;
145
+
be_Render render;
146
+
be_EventCallback callbacks[BITE_EVENTS];
78
147
};
79
148
80
149
static be_Context _context;
81
150
82
-
static const be_Config _conf = {
83
-
.window = {
84
-
.title = "bitEngine "BITE_VERSION,
85
-
.width = 640, .height = 380,
86
-
.flags = 0
87
-
}
88
-
};
151
+
static const be_Config _conf = {.window = {.title = "bitEngine " BITE_VERSION,
152
+
.width = 640,
153
+
.height = 380,
154
+
.flags = 0}};
89
155
90
156
#if defined(_WIN32)
91
-
typedef HGLRC WINAPI wglCreateContextAttribsARBProc(HDC hdc, HGLRC hShareContext, const int* attribList);
92
-
wglCreateContextAttribsARBProc* wglCreateContextAttribsARB;
157
+
typedef HGLRC WINAPI wglCreateContextAttribsARBProc(HDC hdc,
158
+
HGLRC hShareContext,
159
+
const int *attribList);
160
+
wglCreateContextAttribsARBProc *wglCreateContextAttribsARB;
93
161
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
94
162
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
95
163
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
96
164
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
97
165
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
98
166
99
-
typedef BOOL WINAPI wglChoosePixelFormatARBProc(HDC hdc, const int *piAttribIList,
100
-
const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
167
+
typedef BOOL WINAPI wglChoosePixelFormatARBProc(
168
+
HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList,
169
+
UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
101
170
wglChoosePixelFormatARBProc *wglChoosePixelFormatARB;
102
171
103
-
// See https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_pixel_format.txt for all values
104
-
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
105
-
#define WGL_ACCELERATION_ARB 0x2003
106
-
#define WGL_SUPPORT_OPENGL_ARB 0x2010
107
-
#define WGL_DOUBLE_BUFFER_ARB 0x2011
108
-
#define WGL_PIXEL_TYPE_ARB 0x2013
109
-
#define WGL_COLOR_BITS_ARB 0x2014
110
-
#define WGL_DEPTH_BITS_ARB 0x2022
111
-
#define WGL_STENCIL_BITS_ARB 0x2023
172
+
// See
173
+
// https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_pixel_format.txt
174
+
// for all values
175
+
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
176
+
#define WGL_ACCELERATION_ARB 0x2003
177
+
#define WGL_SUPPORT_OPENGL_ARB 0x2010
178
+
#define WGL_DOUBLE_BUFFER_ARB 0x2011
179
+
#define WGL_PIXEL_TYPE_ARB 0x2013
180
+
#define WGL_COLOR_BITS_ARB 0x2014
181
+
#define WGL_DEPTH_BITS_ARB 0x2022
182
+
#define WGL_STENCIL_BITS_ARB 0x2023
112
183
113
-
#define WGL_FULL_ACCELERATION_ARB 0x2027
114
-
#define WGL_TYPE_RGBA_ARB 0x202B
184
+
#define WGL_FULL_ACCELERATION_ARB 0x2027
185
+
#define WGL_TYPE_RGBA_ARB 0x202B
115
186
#elif defined(__EMSCRIPTEN__)
116
187
#else
117
-
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
118
-
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
119
-
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
188
+
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig,
189
+
GLXContext, Bool,
190
+
const int *);
191
+
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
192
+
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
120
193
#endif
121
194
122
-
#define DEFINE_GL(ret, name, ...)\
123
-
typedef ret name##Proc(__VA_ARGS__);\
124
-
static name##Proc* name = 0
195
+
#define DEFINE_GL(ret, name, ...) \
196
+
typedef ret name##Proc(__VA_ARGS__); \
197
+
static name##Proc *name = 0
125
198
126
199
#if !defined(__EMSCRIPTEN__)
127
200
#define GL_VERSION 0x1F02
128
201
#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
129
202
130
203
/* data types */
131
-
#define GL_BYTE 0x1400
132
-
#define GL_UNSIGNED_BYTE 0x1401
133
-
#define GL_SHORT 0x1402
204
+
#define GL_BYTE 0x1400
205
+
#define GL_UNSIGNED_BYTE 0x1401
206
+
#define GL_SHORT 0x1402
134
207
#define GL_UNSIGNED_SHORT 0x1403
135
-
#define GL_INT 0x1404
136
-
#define GL_UNSIGNED_INT 0x1405
137
-
#define GL_FLOAT 0x1406
138
-
#define GL_2_BYTES 0x1407
139
-
#define GL_3_BYTES 0x1408
140
-
#define GL_4_BYTES 0x1409
141
-
#define GL_DOUBLE 0x140A
208
+
#define GL_INT 0x1404
209
+
#define GL_UNSIGNED_INT 0x1405
210
+
#define GL_FLOAT 0x1406
211
+
#define GL_2_BYTES 0x1407
212
+
#define GL_3_BYTES 0x1408
213
+
#define GL_4_BYTES 0x1409
214
+
#define GL_DOUBLE 0x140A
142
215
143
216
/* Clear buffer bits */
144
-
#define GL_DEPTH_BUFFER_BIT 0x00000100
145
-
#define GL_ACCUM_BUFFER_BIT 0x00000200
217
+
#define GL_DEPTH_BUFFER_BIT 0x00000100
218
+
#define GL_ACCUM_BUFFER_BIT 0x00000200
146
219
#define GL_STENCIL_BUFFER_BIT 0x00000400
147
-
#define GL_COLOR_BUFFER_BIT 0x00004000
220
+
#define GL_COLOR_BUFFER_BIT 0x00004000
148
221
149
-
#define GL_RGB 0x1907
150
-
#define GL_RGBA 0x1908
222
+
#define GL_RGB 0x1907
223
+
#define GL_RGBA 0x1908
151
224
152
225
/* bgra */
153
-
#define GL_BGR 0x80E0
226
+
#define GL_BGR 0x80E0
154
227
#define GL_BGRA 0x80E1
155
228
156
229
/* Primitives */
157
-
#define GL_POINTS 0x0000
158
-
#define GL_LINES 0x0001
159
-
#define GL_TRIANGLES 0x0004
230
+
#define GL_POINTS 0x0000
231
+
#define GL_LINES 0x0001
232
+
#define GL_TRIANGLES 0x0004
160
233
161
234
#define GL_ARRAY_BUFFER 0x8892
162
235
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
163
236
164
-
#define GL_STREAM_DRAW 0x88E0
165
-
#define GL_STREAM_READ 0x88E1
166
-
#define GL_STREAM_COPY 0x88E2
167
-
#define GL_STATIC_DRAW 0x88E4
168
-
#define GL_STATIC_READ 0x88E5
169
-
#define GL_STATIC_COPY 0x88E6
237
+
#define GL_STREAM_DRAW 0x88E0
238
+
#define GL_STREAM_READ 0x88E1
239
+
#define GL_STREAM_COPY 0x88E2
240
+
#define GL_STATIC_DRAW 0x88E4
241
+
#define GL_STATIC_READ 0x88E5
242
+
#define GL_STATIC_COPY 0x88E6
170
243
#define GL_DYNAMIC_DRAW 0x88E8
171
244
#define GL_DYNAMIC_READ 0x88E9
172
245
#define GL_DYNAMIC_COPY 0x88EA
···
181
254
#define GL_REPEAT 0x2901
182
255
#define GL_CLAMP 0x2900
183
256
184
-
#define GL_CLAMP_TO_EDGE 0x812F /* 1.2 */
185
-
#define GL_CLAMP_TO_BORDER 0x812D /* 1.3 */
257
+
#define GL_CLAMP_TO_EDGE 0x812F /* 1.2 */
258
+
#define GL_CLAMP_TO_BORDER 0x812D /* 1.3 */
186
259
187
260
// Core
188
261
// DEFINE_GL(void, glClearColor, float, float, float, float);
···
192
265
// DEFINE_GL(void, glViewport, GLint, GLint, GLint, GLint);
193
266
194
267
// VAO
195
-
DEFINE_GL(void, glGenVertexArrays, GLsizei, GLuint*); // glGenVertexArrays
196
-
DEFINE_GL(void, glBindVertexArray, GLuint); // glBindVertexArray
197
-
DEFINE_GL(void, glDeleteVertexArrays, GLsizei, GLuint*); // glDeleteVertexArrays
198
-
DEFINE_GL(void, glVertexAttribPointer, GLuint, GLint, GLuint, GLint, GLint, const void*);
268
+
DEFINE_GL(void, glGenVertexArrays, GLsizei, GLuint *); // glGenVertexArrays
269
+
DEFINE_GL(void, glBindVertexArray, GLuint); // glBindVertexArray
270
+
DEFINE_GL(void, glDeleteVertexArrays, GLsizei,
271
+
GLuint *); // glDeleteVertexArrays
272
+
DEFINE_GL(void, glVertexAttribPointer, GLuint, GLint, GLuint, GLint, GLint,
273
+
const void *);
199
274
DEFINE_GL(void, glEnableVertexAttribArray, GLuint);
200
275
DEFINE_GL(void, glDisableVertexAttribArray, GLuint);
201
276
202
277
// Buffers
203
-
DEFINE_GL(void, glGenBuffers, GLsizei, GLuint*); // glGenBuffers
204
-
DEFINE_GL(void, glBindBuffer, GLenum, GLuint); // glBindBuffer
205
-
DEFINE_GL(void, glDeleteBuffers, GLsizei, GLuint*); // glDeleteBuffers
206
-
DEFINE_GL(void, glBufferData, GLenum, GLsizei, const void*, GLenum); // glBufferData(GLenum target, GLsizeptr size, const void* data, GLenum usage)
207
-
DEFINE_GL(void, glBufferSubData, GLenum, GLsizei, GLsizei, const void*); // glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr, size, const void* data)
278
+
DEFINE_GL(void, glGenBuffers, GLsizei, GLuint *); // glGenBuffers
279
+
DEFINE_GL(void, glBindBuffer, GLenum, GLuint); // glBindBuffer
280
+
DEFINE_GL(void, glDeleteBuffers, GLsizei, GLuint *); // glDeleteBuffers
281
+
DEFINE_GL(void, glBufferData, GLenum, GLsizei, const void *,
282
+
GLenum); // glBufferData(GLenum target, GLsizeptr size, const void*
283
+
// data, GLenum usage)
284
+
DEFINE_GL(void, glBufferSubData, GLenum, GLsizei, GLsizei,
285
+
const void *); // glBufferSubData(GLenum target, GLintptr offset,
286
+
// GLsizeiptr, size, const void* data)
208
287
209
288
// DEFINE_GL(void, glDrawArrays, GLenum, GLint, GLsizei); // glDrawArrays
210
289
···
216
295
#define GL_LINK_STATUS 0x8B82
217
296
218
297
DEFINE_GL(GLuint, glCreateShader, GLenum); // glCreateShader
219
-
DEFINE_GL(void, glShaderSource, GLuint, GLsizei, const char**, const GLint*); // glShaderSource
298
+
DEFINE_GL(void, glShaderSource, GLuint, GLsizei, const char **,
299
+
const GLint *); // glShaderSource
220
300
DEFINE_GL(void, glCompileShader, GLuint); // glCompileShader
221
301
222
302
#define GL_LINK_STATUS 0x8B82
223
-
DEFINE_GL(void, glGetShaderiv, GLuint, GLenum, GLint*); // glGetShaderiv
303
+
DEFINE_GL(void, glGetShaderiv, GLuint, GLenum, GLint *); // glGetShaderiv
224
304
const int t = GL_LINK_STATUS;
225
-
DEFINE_GL(void, glGetShaderInfoLog, GLuint, GLsizei, GLsizei*, char*); // glGetShaderInfoLog
226
-
DEFINE_GL(void, glDeleteShader, GLuint); // glDeleteShader
227
-
DEFINE_GL(GLuint, glCreateProgram, void); // glCreateProgram
228
-
DEFINE_GL(void, glAttachShader, GLuint, GLuint); // glAttachShader
229
-
DEFINE_GL(void, glLinkProgram, GLuint); // glLinkProgram
230
-
DEFINE_GL(void, glGetProgramiv, GLuint, GLenum, GLint*); // glGetProgramiv
231
-
DEFINE_GL(void, glGetProgramInfoLog, GLuint, GLsizei, GLsizei*, char*); // glGetProgramInfoLog
232
-
DEFINE_GL(void, glUseProgram, GLuint); // glUseProgram
305
+
DEFINE_GL(void, glGetShaderInfoLog, GLuint, GLsizei, GLsizei *,
306
+
char *); // glGetShaderInfoLog
307
+
DEFINE_GL(void, glDeleteShader, GLuint); // glDeleteShader
308
+
DEFINE_GL(GLuint, glCreateProgram, void); // glCreateProgram
309
+
DEFINE_GL(void, glAttachShader, GLuint, GLuint); // glAttachShader
310
+
DEFINE_GL(void, glLinkProgram, GLuint); // glLinkProgram
311
+
DEFINE_GL(void, glGetProgramiv, GLuint, GLenum, GLint *); // glGetProgramiv
312
+
DEFINE_GL(void, glGetProgramInfoLog, GLuint, GLsizei, GLsizei *,
313
+
char *); // glGetProgramInfoLog
314
+
DEFINE_GL(void, glUseProgram, GLuint); // glUseProgram
233
315
DEFINE_GL(void, glDeleteProgram, GLuint); // glUseProgram
234
316
235
-
DEFINE_GL(void, glGetActiveUniform, GLuint, GLuint, GLint, GLint*, GLint*, GLint*, char*);
236
-
DEFINE_GL(GLint, glGetUniformLocation, GLuint, const char*);
317
+
DEFINE_GL(void, glGetActiveUniform, GLuint, GLuint, GLint, GLint *, GLint *,
318
+
GLint *, char *);
319
+
DEFINE_GL(GLint, glGetUniformLocation, GLuint, const char *);
237
320
238
-
#define DEFINE_GL_UNIFORM(X, T)\
239
-
DEFINE_GL(void, glUniform1##X, GLuint, T);\
240
-
DEFINE_GL(void, glUniform2##X, GLint, T, T);\
241
-
DEFINE_GL(void, glUniform3##X, GLint, T, T, T);\
242
-
DEFINE_GL(void, glUniform4##X, GLint, T, T, T, T);\
243
-
DEFINE_GL(void, glUniform1##X##v, GLint, GLint, const T*);\
244
-
DEFINE_GL(void, glUniform2##X##v, GLint, GLint, const T*);\
245
-
DEFINE_GL(void, glUniform3##X##v, GLint, GLint, const T*);\
246
-
DEFINE_GL(void, glUniform4##X##v, GLint, GLint, const T*)
321
+
#define DEFINE_GL_UNIFORM(X, T) \
322
+
DEFINE_GL(void, glUniform1##X, GLuint, T); \
323
+
DEFINE_GL(void, glUniform2##X, GLint, T, T); \
324
+
DEFINE_GL(void, glUniform3##X, GLint, T, T, T); \
325
+
DEFINE_GL(void, glUniform4##X, GLint, T, T, T, T); \
326
+
DEFINE_GL(void, glUniform1##X##v, GLint, GLint, const T *); \
327
+
DEFINE_GL(void, glUniform2##X##v, GLint, GLint, const T *); \
328
+
DEFINE_GL(void, glUniform3##X##v, GLint, GLint, const T *); \
329
+
DEFINE_GL(void, glUniform4##X##v, GLint, GLint, const T *)
247
330
248
331
// DEFINE_GL_UNIFORM(f, float);
249
332
// DEFINE_GL_UNIFORM(i, GLint);
250
333
251
-
DEFINE_GL(void, glUniformMatrix2fv, GLint, GLint, GLint, const float*);
252
-
DEFINE_GL(void, glUniformMatrix3fv, GLint, GLint, GLint, const float*);
253
-
DEFINE_GL(void, glUniformMatrix4fv, GLint, GLint, GLint, const float*);
334
+
DEFINE_GL(void, glUniformMatrix2fv, GLint, GLint, GLint, const float *);
335
+
DEFINE_GL(void, glUniformMatrix3fv, GLint, GLint, GLint, const float *);
336
+
DEFINE_GL(void, glUniformMatrix4fv, GLint, GLint, GLint, const float *);
254
337
255
-
DEFINE_GL(GLint, glGetAttribLocation, GLuint, const char*);
256
-
DEFINE_GL(void, glGetActiveAttribe, GLuint, GLuint, GLint, GLint*, GLint*, GLuint*, char*);
257
-
DEFINE_GL(void, glBindAttribLocation, GLuint, GLuint, const char*);
338
+
DEFINE_GL(GLint, glGetAttribLocation, GLuint, const char *);
339
+
DEFINE_GL(void, glGetActiveAttribe, GLuint, GLuint, GLint, GLint *, GLint *,
340
+
GLuint *, char *);
341
+
DEFINE_GL(void, glBindAttribLocation, GLuint, GLuint, const char *);
258
342
259
343
#if defined(_WIN32)
260
-
static HMODULE _gl_sym;
344
+
static HMODULE _gl_sym;
261
345
#elif defined(__EMSCRIPTEN__)
262
346
#else
263
-
static void* _gl_sym;
264
-
#ifndef RTLD_LAZY
265
-
#define RTLD_LAZY 0x00001
266
-
#endif
267
-
#ifndef RTLD_GLOBAL
268
-
#define RTLD_GLOBAL 0x00100
269
-
#endif
347
+
static void *_gl_sym;
348
+
#ifndef RTLD_LAZY
349
+
#define RTLD_LAZY 0x00001
350
+
#endif
351
+
#ifndef RTLD_GLOBAL
352
+
#define RTLD_GLOBAL 0x00100
353
+
#endif
270
354
#endif
271
355
272
-
static void* _get_proc(const char* name);
356
+
static void *_get_proc(const char *name);
273
357
BITE_RESULT _load_gl(void);
274
358
void _setup_gl(void);
275
359
void _close_gl(void);
276
360
#endif
277
361
278
-
BITE_RESULT _init_context(be_Context* ctx, const be_Config* conf);
279
-
BITE_RESULT _init_window(be_Window* window, const be_Config* conf);
280
-
BITE_RESULT _init_render(be_Render* render, const be_Window* window, const be_Config* conf);
281
-
void _poll_events(be_Context* ctx);
282
-
362
+
BITE_RESULT _init_context(be_Context *ctx, const be_Config *conf);
363
+
BITE_RESULT _init_window(be_Window *window, const be_Config *conf);
364
+
BITE_RESULT _init_render(be_Render *render, const be_Window *window,
365
+
const be_Config *conf);
366
+
void _poll_events(be_Context *ctx);
283
367
284
368
#if defined(_WIN32)
285
369
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
286
-
be_Context* ctx = (be_Context*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
287
-
be_Event e;
288
-
e.type = 0;
289
-
be_EventCallback fn = NULL;
290
-
switch (msg) {
291
-
case WM_CREATE: return 0;
292
-
case WM_CLOSE: {
293
-
e.type = BITE_WINDOW_CLOSE;
294
-
}
295
-
break;
296
-
case WM_DESTROY: PostQuitMessage(0); break;
297
-
case WM_SYSKEYDOWN:
298
-
case WM_KEYDOWN: {
299
-
e.type = BITE_KEY_PRESSED;
300
-
e.key.keycode = (int)wParam;
301
-
}
302
-
break;
303
-
case WM_SYSKEYUP:
304
-
case WM_KEYUP: {
305
-
e.type = BITE_KEY_RELEASED;
306
-
e.key.keycode = (int)wParam;
307
-
}
308
-
break;
309
-
default:
310
-
return DefWindowProc(hwnd, msg, wParam, lParam);
311
-
}
312
-
313
-
if (ctx) fn = ctx->callbacks[e.type];
314
-
if (fn) fn(ctx, &e);
315
-
printf("Teste\n");
316
-
return 0;
370
+
be_Context *ctx = (be_Context *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
371
+
be_Event e;
372
+
e.type = 0;
373
+
be_EventCallback fn = NULL;
374
+
switch (msg) {
375
+
case WM_CREATE: return 0;
376
+
case WM_CLOSE: {
377
+
e.type = BITE_WINDOW_CLOSE;
378
+
} break;
379
+
case WM_DESTROY:
380
+
PostQuitMessage(0);
381
+
break;
382
+
case WM_SYSKEYDOWN:
383
+
case WM_KEYDOWN: {
384
+
e.type = BITE_KEY_PRESSED;
385
+
e.key.keycode = keys[(int)wParam];
386
+
} break;
387
+
case WM_SYSKEYUP:
388
+
case WM_KEYUP: {
389
+
e.type = BITE_KEY_RELEASED;
390
+
e.key.keycode = keys[(int)wParam];
391
+
printf("KeyPressed: %d\n", e.key.keycode);
392
+
} break;
393
+
default:
394
+
return DefWindowProc(hwnd, msg, wParam, lParam);
395
+
}
396
+
397
+
if (ctx)
398
+
fn = ctx->callbacks[e.type];
399
+
if (fn)
400
+
fn(ctx, &e);
401
+
printf("Teste\n");
402
+
return 0;
317
403
}
318
404
#endif
319
405
320
-
void bite_simple_triangle(be_Context* ctx) {
321
-
glClearColor(0.3f, 0.4f, 0.4f, 1.f);
322
-
glClear(GL_COLOR_BUFFER_BIT);
323
-
// fprintf(stdout, "VAO: %d\n", ctx->render.vao);
406
+
void bite_simple_triangle(be_Context *ctx) {
407
+
glClearColor(0.3f, 0.4f, 0.4f, 1.f);
408
+
glClear(GL_COLOR_BUFFER_BIT);
409
+
// fprintf(stdout, "VAO: %d\n", ctx->render.vao);
324
410
#if !defined(__EMSCRIPTEN__)
325
-
glBindVertexArray(ctx->render.vao);
411
+
glBindVertexArray(ctx->render.vao);
326
412
#else
327
-
glBindBuffer(GL_ARRAY_BUFFER, ctx->render.vbo);
413
+
glBindBuffer(GL_ARRAY_BUFFER, ctx->render.vbo);
328
414
#endif
329
-
glDrawArrays(GL_TRIANGLES, 0, 3);
415
+
glDrawArrays(GL_TRIANGLES, 0, 3);
330
416
#if !defined(__EMSCRIPTEN__)
331
-
glBindVertexArray(0);
417
+
glBindVertexArray(0);
332
418
#else
333
-
glBindBuffer(GL_ARRAY_BUFFER, 0);
419
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
334
420
#endif
335
-
// glBegin(GL_TRIANGLES);
336
-
// glColor3f(1.f, 0.f, 0.f);
337
-
// glVertex2f(0.f, 0.5f);
338
-
// glColor3f(0.f, 1.f, 0.f);
339
-
// glVertex2f(-0.5f, -0.5f);
340
-
// glColor3f(0.f, 0.f, 1.f);
341
-
// glVertex2f(0.5f, -0.5f);
342
-
// glEnd();
421
+
// glBegin(GL_TRIANGLES);
422
+
// glColor3f(1.f, 0.f, 0.f);
423
+
// glVertex2f(0.f, 0.5f);
424
+
// glColor3f(0.f, 1.f, 0.f);
425
+
// glVertex2f(-0.5f, -0.5f);
426
+
// glColor3f(0.f, 0.f, 1.f);
427
+
// glVertex2f(0.5f, -0.5f);
428
+
// glEnd();
343
429
}
344
430
345
-
be_Config bite_init_config(const char* title, int w, int h) {
346
-
be_Config c = {0};
347
-
title = title != NULL ? title : "bitEngine "BITE_VERSION;
348
-
size_t len = strlen(title);
349
-
memcpy(c.window.title, title, len);
350
-
c.window.width = w;
351
-
c.window.height = h;
352
-
return c;
431
+
be_Config bite_init_config(const char *title, int w, int h) {
432
+
be_Config c = {0};
433
+
title = title != NULL ? title : "bitEngine " BITE_VERSION;
434
+
size_t len = strlen(title);
435
+
memcpy(c.window.title, title, len);
436
+
c.window.width = w;
437
+
c.window.height = h;
438
+
return c;
353
439
}
354
440
355
-
be_Context* bite_create(const be_Config* conf) {
356
-
conf = conf ? conf : &(_conf);
357
-
be_Context* ctx = malloc(sizeof(*ctx));
358
-
if (!ctx) {
359
-
fprintf(stderr, "Failed to alloc memory for context\n");
360
-
return NULL;
361
-
}
362
-
int mag, min;
363
-
// glGetIntegerv(GL_MAJOR_VERSION, &mag);
364
-
// glGetIntegerv(GL_MINOR_VERSION, &min);
365
-
// printf("OpenGL loaded: %d.%d\n", mag, min);
366
-
ctx->running = 1;
367
-
for (int i = 0; i < BITE_EVENTS; i++) {
368
-
ctx->callbacks[i] = NULL;
369
-
}
370
-
if (_init_context(ctx, conf) < 0) {
371
-
free(ctx);
372
-
return NULL;
373
-
}
374
-
const char* ver = glGetString(GL_VERSION);
375
-
printf("OpenGL loaded: %s\n", ver);
376
-
return ctx;
441
+
be_Context *bite_create(const be_Config *conf) {
442
+
conf = conf ? conf : &(_conf);
443
+
be_Context *ctx = malloc(sizeof(*ctx));
444
+
if (!ctx) {
445
+
fprintf(stderr, "Failed to alloc memory for context\n");
446
+
return NULL;
447
+
}
448
+
int mag, min;
449
+
// glGetIntegerv(GL_MAJOR_VERSION, &mag);
450
+
// glGetIntegerv(GL_MINOR_VERSION, &min);
451
+
// printf("OpenGL loaded: %d.%d\n", mag, min);
452
+
ctx->running = 1;
453
+
for (int i = 0; i < BITE_EVENTS; i++) {
454
+
ctx->callbacks[i] = NULL;
455
+
}
456
+
if (_init_context(ctx, conf) < 0) {
457
+
free(ctx);
458
+
return NULL;
459
+
}
460
+
const char *ver = glGetString(GL_VERSION);
461
+
printf("OpenGL loaded: %s\n", ver);
462
+
return ctx;
377
463
}
378
464
379
-
void bite_destroy(be_Context* ctx) {
380
-
if (!ctx) return;
381
-
be_Window* window = &(ctx->window);
382
-
be_Render* render = &(ctx->render);
465
+
void bite_destroy(be_Context *ctx) {
466
+
if (!ctx)
467
+
return;
468
+
be_Window *window = &(ctx->window);
469
+
be_Render *render = &(ctx->render);
383
470
#if defined(_WIN32)
384
-
wglMakeCurrent(NULL, NULL);
385
-
wglDeleteContext(render->gl_context);
386
-
ReleaseDC(window->handle, window->dev_context);
387
-
DestroyWindow(window->handle);
471
+
wglMakeCurrent(NULL, NULL);
472
+
wglDeleteContext(render->gl_context);
473
+
ReleaseDC(window->handle, window->dev_context);
474
+
DestroyWindow(window->handle);
388
475
#elif defined(__EMSCRIPTEN__)
389
-
emscripten_webgl_destroy_context(render->gl_context);
476
+
emscripten_webgl_destroy_context(render->gl_context);
390
477
#else
391
-
glXDestroyContext(window->display, render->gl_context);
392
-
XDestroyWindow(window->display, window->handle);
393
-
XCloseDisplay(window->display);
478
+
glXDestroyContext(window->display, render->gl_context);
479
+
XDestroyWindow(window->display, window->handle);
480
+
XCloseDisplay(window->display);
394
481
#endif
395
-
free(ctx);
482
+
free(ctx);
396
483
}
397
484
398
-
void bite_register_callback(be_Context* ctx, int type, be_EventCallback callback) {
399
-
if (!ctx) return;
400
-
if (type < BITE_QUIT || type >= BITE_EVENTS) return;
401
-
ctx->callbacks[type] = callback;
485
+
void bite_register_callback(be_Context *ctx, int type,
486
+
be_EventCallback callback) {
487
+
if (!ctx)
488
+
return;
489
+
if (type < BITE_QUIT || type >= BITE_EVENTS)
490
+
return;
491
+
ctx->callbacks[type] = callback;
402
492
}
403
493
404
-
int bite_should_close(be_Context* ctx) {
405
-
if (!ctx) return 1;
406
-
return !(ctx->running);
494
+
int bite_should_close(be_Context *ctx) {
495
+
if (!ctx)
496
+
return 1;
497
+
return !(ctx->running);
407
498
}
408
499
409
-
void bite_set_should_close(be_Context* ctx, int should_close) {
410
-
if (!ctx) return;
411
-
ctx->running = !should_close;
500
+
void bite_set_should_close(be_Context *ctx, int should_close) {
501
+
if (!ctx)
502
+
return;
503
+
ctx->running = !should_close;
412
504
}
413
505
414
-
void bite_poll_events(be_Context* ctx) {
415
-
if (!ctx) return;
416
-
_poll_events(ctx);
506
+
void bite_poll_events(be_Context *ctx) {
507
+
if (!ctx)
508
+
return;
509
+
_poll_events(ctx);
417
510
}
418
511
419
-
void bite_swap(be_Context* ctx) {
420
-
if (!ctx) return;
421
-
be_Window* window = &(ctx->window);
512
+
void bite_swap(be_Context *ctx) {
513
+
if (!ctx)
514
+
return;
515
+
be_Window *window = &(ctx->window);
422
516
#if defined(_WIN32)
423
-
SwapBuffers(window->dev_context);
517
+
SwapBuffers(window->dev_context);
424
518
#elif defined(__EMSCRIPTEN__)
425
-
emscripten_webgl_commit_frame();
519
+
emscripten_webgl_commit_frame();
426
520
#else
427
-
glXSwapBuffers(window->display, window->handle);
521
+
glXSwapBuffers(window->display, window->handle);
428
522
#endif
429
523
}
430
524
431
525
/*********************
432
526
* Window
433
527
*********************/
434
-
void bite_set_window_width(be_Context* ctx, int width) {
528
+
void bite_set_window_width(be_Context *ctx, int width) {}
435
529
436
-
}
437
-
438
-
439
-
int bite_get_window_width(be_Context* ctx) {
440
-
if (!ctx) return -1;
441
-
return ctx->window.width;
530
+
int bite_get_window_width(be_Context *ctx) {
531
+
if (!ctx)
532
+
return -1;
533
+
return ctx->window.width;
442
534
}
443
535
444
536
/*********************
445
537
* Render
446
538
*********************/
447
539
448
-
static GLuint _compile_shader(GLenum type, const char* src) {
449
-
GLuint shader = glCreateShader(type);
450
-
glShaderSource(shader, 1, &src, NULL);
451
-
glCompileShader(shader);
540
+
static GLuint _compile_shader(GLenum type, const char *src) {
541
+
GLuint shader = glCreateShader(type);
542
+
glShaderSource(shader, 1, &src, NULL);
543
+
glCompileShader(shader);
452
544
453
-
int success;
454
-
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
455
-
if (!success) {
456
-
char info_log[512];
457
-
glGetShaderInfoLog(shader, 512, NULL, info_log);
458
-
fprintf(stderr, "Failed to compile shader: %s\n", info_log);
459
-
glDeleteShader(shader);
460
-
return 0;
461
-
}
545
+
int success;
546
+
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
547
+
if (!success) {
548
+
char info_log[512];
549
+
glGetShaderInfoLog(shader, 512, NULL, info_log);
550
+
fprintf(stderr, "Failed to compile shader: %s\n", info_log);
551
+
glDeleteShader(shader);
552
+
return 0;
553
+
}
462
554
463
-
return shader;
555
+
return shader;
464
556
}
465
557
466
558
static GLuint _create_program(GLuint vert, GLuint frag) {
467
559
#if 1
468
-
GLuint program = glCreateProgram();
469
-
glAttachShader(program, vert);
470
-
glAttachShader(program, frag);
471
-
glLinkProgram(program);
472
-
473
-
int success;
474
-
glGetProgramiv(program, GL_LINK_STATUS, &success);
475
-
if (!success) {
476
-
char info_log[512];
477
-
glGetProgramInfoLog(program, 512, NULL, info_log);
478
-
fprintf(stderr, "Failed to link program: %s\n", info_log);
479
-
glDeleteProgram(program);
480
-
return 0;
481
-
}
560
+
GLuint program = glCreateProgram();
561
+
glAttachShader(program, vert);
562
+
glAttachShader(program, frag);
563
+
glLinkProgram(program);
482
564
483
-
return program;
484
-
#endif
565
+
int success;
566
+
glGetProgramiv(program, GL_LINK_STATUS, &success);
567
+
if (!success) {
568
+
char info_log[512];
569
+
glGetProgramInfoLog(program, 512, NULL, info_log);
570
+
fprintf(stderr, "Failed to link program: %s\n", info_log);
571
+
glDeleteProgram(program);
485
572
return 0;
573
+
}
574
+
575
+
return program;
576
+
#endif
577
+
return 0;
486
578
}
487
579
488
-
be_Texture* bite_create_texture(int width, int height, int format, void* data) {
489
-
be_Texture* texture = (be_Texture*)malloc(sizeof(*texture));
490
-
if (!texture) {
491
-
fprintf(stderr, "Failed to alloc memory for texture\n");
492
-
return NULL;
493
-
}
494
-
texture->filter[0] = GL_NEAREST;
495
-
texture->filter[1] = GL_NEAREST;
496
-
texture->wrap[0] = GL_CLAMP_TO_EDGE;
497
-
texture->wrap[1] = GL_CLAMP_TO_EDGE;
498
-
texture->width = width;
499
-
texture->height = height;
580
+
be_Texture *bite_create_texture(int width, int height, int format, void *data) {
581
+
be_Texture *texture = (be_Texture *)malloc(sizeof(*texture));
582
+
if (!texture) {
583
+
fprintf(stderr, "Failed to alloc memory for texture\n");
584
+
return NULL;
585
+
}
586
+
texture->filter[0] = GL_NEAREST;
587
+
texture->filter[1] = GL_NEAREST;
588
+
texture->wrap[0] = GL_CLAMP_TO_EDGE;
589
+
texture->wrap[1] = GL_CLAMP_TO_EDGE;
590
+
texture->width = width;
591
+
texture->height = height;
500
592
501
-
glGenTextures(1, &(texture->handle));
502
-
glBindTexture(GL_TEXTURE_2D, texture->handle);
503
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
593
+
glGenTextures(1, &(texture->handle));
594
+
glBindTexture(GL_TEXTURE_2D, texture->handle);
595
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
596
+
GL_UNSIGNED_BYTE, data);
504
597
505
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->filter[0]);
506
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->filter[1]);
507
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wrap[0]);
508
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrap[1]);
509
-
glBindTexture(GL_TEXTURE_2D, 0);
510
-
return texture;
598
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->filter[0]);
599
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->filter[1]);
600
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wrap[0]);
601
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrap[1]);
602
+
glBindTexture(GL_TEXTURE_2D, 0);
603
+
return texture;
511
604
}
512
605
513
-
be_Shader* bite_create_shader(const char* vert_src, const char* frag_src) {
514
-
be_Shader* shader = NULL;
515
-
GLuint vert, frag;
516
-
vert = _compile_shader(GL_VERTEX_SHADER, vert_src);
517
-
if (vert <= 0) return shader;
518
-
frag = _compile_shader(GL_FRAGMENT_SHADER, frag_src);
519
-
if (frag <= 0) return shader;
520
-
521
-
GLuint program = _create_program(vert, frag);
522
-
if (program <= 0) return shader;
523
-
shader = malloc(sizeof(*shader));
524
-
shader->handle = program;
606
+
be_Shader *bite_create_shader(const char *vert_src, const char *frag_src) {
607
+
be_Shader *shader = NULL;
608
+
GLuint vert, frag;
609
+
vert = _compile_shader(GL_VERTEX_SHADER, vert_src);
610
+
if (vert <= 0)
611
+
return shader;
612
+
frag = _compile_shader(GL_FRAGMENT_SHADER, frag_src);
613
+
if (frag <= 0)
614
+
return shader;
525
615
616
+
GLuint program = _create_program(vert, frag);
617
+
if (program <= 0)
526
618
return shader;
619
+
shader = malloc(sizeof(*shader));
620
+
shader->handle = program;
621
+
622
+
return shader;
527
623
}
528
624
529
625
void bite_render_clear_color(float r, float g, float b, float a) {
530
-
glClearColor(r, g, b, a);
626
+
glClearColor(r, g, b, a);
531
627
}
532
628
533
-
void bite_render_clear(void) {
534
-
glClear(GL_COLOR_BUFFER_BIT);
535
-
}
629
+
void bite_render_clear(void) { glClear(GL_COLOR_BUFFER_BIT); }
536
630
537
-
void bite_bind_framebuffer(be_Framebuffer* fbo) {
631
+
void bite_bind_framebuffer(be_Framebuffer *fbo) {
538
632
#if 0
539
633
if (!fbo) glBindFramebuffer(GL_FRAMEBUFFER, 0);
540
634
else glBindFramebuffer(GL_FRAMEBUFFER, fbo->handle);
541
635
#endif
542
636
}
543
637
544
-
void bite_bind_texture(be_Texture* tex) {
545
-
if (!tex) glBindTexture(GL_TEXTURE_2D, 0);
546
-
else glBindTexture(GL_TEXTURE_2D, tex->handle);
638
+
void bite_bind_texture(be_Texture *tex) {
639
+
if (!tex)
640
+
glBindTexture(GL_TEXTURE_2D, 0);
641
+
else
642
+
glBindTexture(GL_TEXTURE_2D, tex->handle);
547
643
}
548
644
549
-
void bite_use_shader(be_Shader* shader) {
550
-
if (!shader) glUseProgram(0);
551
-
else glUseProgram(shader->handle);
645
+
void bite_use_shader(be_Shader *shader) {
646
+
if (!shader)
647
+
glUseProgram(0);
648
+
else
649
+
glUseProgram(shader->handle);
552
650
}
553
651
554
652
/*********************
···
556
654
*********************/
557
655
void bite_sleep(be_u64 ms) {
558
656
#if defined(_WIN32)
559
-
Sleep(ms);
657
+
Sleep(ms);
560
658
#elif defined(__EMSCRIPTEN__)
561
-
emscripten_sleep((be_u32)ms);
659
+
emscripten_sleep((be_u32)ms);
562
660
#else
563
-
sleep(ms / 1000);
661
+
sleep(ms / 1000);
564
662
#endif
565
663
}
566
664
567
665
be_u64 bite_tick(void) {
568
-
be_u64 tick = 0;
666
+
be_u64 tick = 0;
569
667
#if defined(_WIN32)
570
-
LARGE_INTEGER freq, count;
571
-
QueryPerformanceFrequency(&freq);
572
-
QueryPerformanceCounter(&count);
573
-
tick = (be_u64)(count.QuadPart * 1000.0 / freq.QuadPart);
668
+
LARGE_INTEGER freq, count;
669
+
QueryPerformanceFrequency(&freq);
670
+
QueryPerformanceCounter(&count);
671
+
tick = (be_u64)(count.QuadPart * 1000.0 / freq.QuadPart);
574
672
#else
575
-
struct timespec time;
576
-
clock_gettime(CLOCK_REALTIME, &time);
577
-
tick = time.tv_sec * 1000 + (time.tv_nsec / 1000000);
673
+
struct timespec time;
674
+
clock_gettime(CLOCK_REALTIME, &time);
675
+
tick = time.tv_sec * 1000 + (time.tv_nsec / 1000000);
578
676
#endif
579
-
return tick;
677
+
return tick;
580
678
}
581
679
582
680
/*********************
···
587
685
588
686
#if defined(_WIN32)
589
687
static void init_opengl_extensions(void) {
590
-
WNDCLASSA window_class = {
591
-
.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
592
-
.lpfnWndProc = DefWindowProcA,
593
-
.hInstance = GetModuleHandle(0),
594
-
.lpszClassName = "Dummy_WGL_window"
595
-
};
688
+
WNDCLASSA window_class = {.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
689
+
.lpfnWndProc = DefWindowProcA,
690
+
.hInstance = GetModuleHandle(0),
691
+
.lpszClassName = "Dummy_WGL_window"};
596
692
597
-
if (!RegisterClassA(&window_class)) {
598
-
fprintf(stderr, "Failed to register dummy OpenGL window\n");
599
-
exit(EXIT_FAILURE);
600
-
}
693
+
if (!RegisterClassA(&window_class)) {
694
+
fprintf(stderr, "Failed to register dummy OpenGL window\n");
695
+
exit(EXIT_FAILURE);
696
+
}
601
697
602
-
HWND dummy_window = CreateWindowExA(
603
-
0,
604
-
window_class.lpszClassName,
605
-
"Dummy OpenGL Window",
606
-
0,
607
-
CW_USEDEFAULT, CW_USEDEFAULT,
608
-
CW_USEDEFAULT, CW_USEDEFAULT,
609
-
0, 0,
610
-
window_class.hInstance,
611
-
0
612
-
);
698
+
HWND dummy_window =
699
+
CreateWindowExA(0, window_class.lpszClassName, "Dummy OpenGL Window", 0,
700
+
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
701
+
CW_USEDEFAULT, 0, 0, window_class.hInstance, 0);
613
702
614
-
if (!dummy_window) {
615
-
fprintf(stderr, "Failed to create dummy OpenGL window\n");
616
-
exit(EXIT_FAILURE);
617
-
}
703
+
if (!dummy_window) {
704
+
fprintf(stderr, "Failed to create dummy OpenGL window\n");
705
+
exit(EXIT_FAILURE);
706
+
}
618
707
619
-
HDC dummy_dc = GetDC(dummy_window);
708
+
HDC dummy_dc = GetDC(dummy_window);
620
709
621
-
PIXELFORMATDESCRIPTOR pfd = {
622
-
.nSize = sizeof(pfd),
623
-
.nVersion = 1,
624
-
.iPixelType = PFD_TYPE_RGBA,
625
-
.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
626
-
.cColorBits = 32,
627
-
.cAlphaBits = 8,
628
-
.iLayerType = PFD_MAIN_PLANE,
629
-
.cDepthBits = 24,
630
-
.cStencilBits = 8
631
-
};
710
+
PIXELFORMATDESCRIPTOR pfd = {.nSize = sizeof(pfd),
711
+
.nVersion = 1,
712
+
.iPixelType = PFD_TYPE_RGBA,
713
+
.dwFlags = PFD_DRAW_TO_WINDOW |
714
+
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
715
+
.cColorBits = 32,
716
+
.cAlphaBits = 8,
717
+
.iLayerType = PFD_MAIN_PLANE,
718
+
.cDepthBits = 24,
719
+
.cStencilBits = 8};
720
+
721
+
int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
722
+
if (!pixel_format) {
723
+
fprintf(stderr, "Failed to find a suitable format\n");
724
+
exit(EXIT_FAILURE);
725
+
}
726
+
if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) {
727
+
fprintf(stderr, "Failed to set the pixel format\n");
728
+
exit(EXIT_FAILURE);
729
+
}
632
730
633
-
int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
634
-
if (!pixel_format) {
635
-
fprintf(stderr, "Failed to find a suitable format\n");
636
-
exit(EXIT_FAILURE);
637
-
}
638
-
if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) {
639
-
fprintf(stderr, "Failed to set the pixel format\n");
640
-
exit(EXIT_FAILURE);
641
-
}
642
-
643
-
HGLRC dummy_context = wglCreateContext(dummy_dc);
644
-
if (!dummy_context) {
645
-
fprintf(stderr, "Failed to create dummy OpenGL context\n");
646
-
exit(EXIT_FAILURE);
647
-
}
731
+
HGLRC dummy_context = wglCreateContext(dummy_dc);
732
+
if (!dummy_context) {
733
+
fprintf(stderr, "Failed to create dummy OpenGL context\n");
734
+
exit(EXIT_FAILURE);
735
+
}
648
736
649
-
if (!wglMakeCurrent(dummy_dc, dummy_context)) {
650
-
fprintf(stderr, "Failed to activate dummy OpenGL context\n");
651
-
exit(EXIT_FAILURE);
652
-
}
653
-
wglCreateContextAttribsARB = (wglCreateContextAttribsARBProc*)wglGetProcAddress("wglCreateContextAttribsARB");
654
-
wglChoosePixelFormatARB = (wglChoosePixelFormatARBProc*)wglGetProcAddress("wglChoosePixelFormatARB");
737
+
if (!wglMakeCurrent(dummy_dc, dummy_context)) {
738
+
fprintf(stderr, "Failed to activate dummy OpenGL context\n");
739
+
exit(EXIT_FAILURE);
740
+
}
741
+
wglCreateContextAttribsARB =
742
+
(wglCreateContextAttribsARBProc *)wglGetProcAddress(
743
+
"wglCreateContextAttribsARB");
744
+
wglChoosePixelFormatARB = (wglChoosePixelFormatARBProc *)wglGetProcAddress(
745
+
"wglChoosePixelFormatARB");
655
746
656
-
printf("functions: %p %p\n", wglCreateContextAttribsARB, wglChoosePixelFormatARB);
747
+
printf("functions: %p %p\n", wglCreateContextAttribsARB,
748
+
wglChoosePixelFormatARB);
657
749
658
-
wglMakeCurrent(dummy_dc, 0);
659
-
wglDeleteContext(dummy_context);
660
-
ReleaseDC(dummy_window, dummy_dc);
661
-
DestroyWindow(dummy_window);
750
+
wglMakeCurrent(dummy_dc, 0);
751
+
wglDeleteContext(dummy_context);
752
+
ReleaseDC(dummy_window, dummy_dc);
753
+
DestroyWindow(dummy_window);
662
754
}
663
755
#else
664
-
static BITE_BOOL is_extension_supported(const char *extList, const char *extension) {
756
+
static BITE_BOOL is_extension_supported(const char *extList,
757
+
const char *extension) {
665
758
const char *start;
666
759
const char *where, *terminator;
667
-
760
+
668
761
/* Extension names should not have spaces. */
669
762
where = strchr(extension, ' ');
670
763
if (where || *extension == '\0')
···
673
766
/* It takes a bit of care to be fool-proof about parsing the
674
767
OpenGL extensions string. Don't be fooled by sub-strings,
675
768
etc. */
676
-
for (start=extList;;) {
769
+
for (start = extList;;) {
677
770
where = strstr(start, extension);
678
771
679
772
if (!where)
···
681
774
682
775
terminator = where + strlen(extension);
683
776
684
-
if ( where == start || *(where - 1) == ' ' )
685
-
if ( *terminator == ' ' || *terminator == '\0' )
777
+
if (where == start || *(where - 1) == ' ')
778
+
if (*terminator == ' ' || *terminator == '\0')
686
779
return BITE_TRUE;
687
780
688
781
start = terminator;
···
691
784
}
692
785
#endif
693
786
694
-
BITE_RESULT _init_context(be_Context* ctx, const be_Config* conf) {
695
-
if (_init_window(&(ctx->window), conf) != BITE_OK) return BITE_ERROR;
787
+
BITE_RESULT _init_context(be_Context *ctx, const be_Config *conf) {
788
+
if (_init_window(&(ctx->window), conf) != BITE_OK)
789
+
return BITE_ERROR;
696
790
#if defined(_WIN32)
697
-
SetWindowLongPtr(ctx->window.handle, GWLP_USERDATA, (LONG_PTR)ctx);
791
+
SetWindowLongPtr(ctx->window.handle, GWLP_USERDATA, (LONG_PTR)ctx);
698
792
#endif
699
-
if (_init_render(&(ctx->render), &(ctx->window), conf) != BITE_OK) return BITE_ERROR;
700
-
be_Render* render = &(ctx->render);
793
+
if (_init_render(&(ctx->render), &(ctx->window), conf) != BITE_OK)
794
+
return BITE_ERROR;
795
+
be_Render *render = &(ctx->render);
701
796
702
-
float vertices[] = {
703
-
0.f, 0.5f, 1.f, 0.f, 0.f, 1.f,
704
-
-0.5f, -0.5f, 0.f, 1.f, 0.f, 1.f,
705
-
0.5f, -0.5f, 0.f, 0.f, 1.f, 1.f
706
-
};
797
+
float vertices[] = {0.f, 0.5f, 1.f, 0.f, 0.f, 1.f, -0.5f, -0.5f, 0.f,
798
+
1.f, 0.f, 1.f, 0.5f, -0.5f, 0.f, 0.f, 1.f, 1.f};
707
799
708
800
#if !defined(__EMSCRIPTEN__)
709
-
glGenVertexArrays(1, &(render->vao));
710
-
glBindVertexArray(render->vao);
801
+
glGenVertexArrays(1, &(render->vao));
802
+
glBindVertexArray(render->vao);
711
803
#endif
712
-
glGenBuffers(1, &(render->vbo));
713
-
glBindBuffer(GL_ARRAY_BUFFER, render->vbo);
714
-
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
804
+
glGenBuffers(1, &(render->vbo));
805
+
glBindBuffer(GL_ARRAY_BUFFER, render->vbo);
806
+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
715
807
716
-
glEnableVertexAttribArray(0);
717
-
glEnableVertexAttribArray(1);
718
-
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)0);
719
-
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)(2 * sizeof(float)));
720
-
// glBindBuffer(GL_ARRAY_BUFFER, 0);
808
+
glEnableVertexAttribArray(0);
809
+
glEnableVertexAttribArray(1);
810
+
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)0);
811
+
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 6 * sizeof(float),
812
+
(void *)(2 * sizeof(float)));
813
+
// glBindBuffer(GL_ARRAY_BUFFER, 0);
721
814
#if !defined(__EMSCRIPTEN__)
722
-
glBindVertexArray(0);
815
+
glBindVertexArray(0);
723
816
#endif
724
-
return BITE_OK;
817
+
return BITE_OK;
725
818
}
726
819
727
-
BITE_RESULT _init_window(be_Window* window, const be_Config* conf) {
820
+
BITE_RESULT _init_window(be_Window *window, const be_Config *conf) {
728
821
#if defined(_WIN32)
729
-
HWND handle;
730
-
HMODULE hInstance = GetModuleHandle(0);
822
+
HWND handle;
823
+
HMODULE hInstance = GetModuleHandle(0);
731
824
732
-
const TCHAR windowClass[] = _T("bitEngine");
825
+
const TCHAR windowClass[] = _T("bitEngine");
733
826
734
-
WNDCLASSEX wc;
735
-
wc.cbSize = sizeof(WNDCLASSEX);
736
-
wc.style = CS_HREDRAW | CS_VREDRAW;
737
-
wc.lpfnWndProc = WindowProc;
738
-
wc.cbClsExtra = 0;
739
-
wc.cbWndExtra = 0;
740
-
wc.hInstance = hInstance;
741
-
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
742
-
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
743
-
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
744
-
wc.lpszMenuName = NULL;
745
-
wc.lpszClassName = windowClass;
746
-
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
827
+
WNDCLASSEX wc;
828
+
wc.cbSize = sizeof(WNDCLASSEX);
829
+
wc.style = CS_HREDRAW | CS_VREDRAW;
830
+
wc.lpfnWndProc = WindowProc;
831
+
wc.cbClsExtra = 0;
832
+
wc.cbWndExtra = 0;
833
+
wc.hInstance = hInstance;
834
+
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
835
+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
836
+
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
837
+
wc.lpszMenuName = NULL;
838
+
wc.lpszClassName = windowClass;
839
+
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
747
840
748
-
if (!RegisterClassEx(&wc)) {
749
-
MessageBox(NULL,
750
-
_T("Call to RegisterClassEx failed"),
751
-
_T("bitEngine"),
752
-
NULL);
753
-
return BITE_ERROR;
754
-
}
841
+
if (!RegisterClassEx(&wc)) {
842
+
MessageBox(NULL, _T("Call to RegisterClassEx failed"), _T("bitEngine"),
843
+
NULL);
844
+
return BITE_ERROR;
845
+
}
755
846
756
-
handle = CreateWindow(
757
-
windowClass,
758
-
conf->window.title,
759
-
WS_OVERLAPPEDWINDOW,
760
-
CW_USEDEFAULT, CW_USEDEFAULT,
761
-
conf->window.width, conf->window.height,
762
-
NULL, NULL, hInstance, NULL
763
-
);
764
-
if (!handle) {
765
-
MessageBox(NULL,
766
-
_T("Class to CreateWindow failed"),
767
-
_T("bitEngine"),
768
-
NULL
769
-
);
770
-
return BITE_ERROR;
771
-
}
772
-
window->handle = handle;
773
-
window->dev_context = GetDC(handle);
847
+
handle = CreateWindow(windowClass, conf->window.title, WS_OVERLAPPEDWINDOW,
848
+
CW_USEDEFAULT, CW_USEDEFAULT, conf->window.width,
849
+
conf->window.height, NULL, NULL, hInstance, NULL);
850
+
if (!handle) {
851
+
MessageBox(NULL, _T("Class to CreateWindow failed"), _T("bitEngine"), NULL);
852
+
return BITE_ERROR;
853
+
}
854
+
window->handle = handle;
855
+
window->dev_context = GetDC(handle);
774
856
775
-
ShowWindow(handle, SW_SHOWDEFAULT);
776
-
UpdateWindow(handle);
857
+
ShowWindow(handle, SW_SHOWDEFAULT);
858
+
UpdateWindow(handle);
777
859
#elif (__EMSCRIPTEN__)
778
860
#else
779
-
Display* dpy;
780
-
Window handle;
781
-
dpy = XOpenDisplay(NULL);
782
-
if (dpy == NULL) {
783
-
fprintf(stderr, "Could not open X11 display\n");
784
-
return BITE_ERROR;
785
-
}
786
-
int scrId = DefaultScreen(dpy);
861
+
Display *dpy;
862
+
Window handle;
863
+
dpy = XOpenDisplay(NULL);
864
+
if (dpy == NULL) {
865
+
fprintf(stderr, "Could not open X11 display\n");
866
+
return BITE_ERROR;
867
+
}
868
+
int scrId = DefaultScreen(dpy);
787
869
788
-
static int visual_attribs[] =
789
-
{
790
-
GLX_X_RENDERABLE , True,
791
-
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
792
-
GLX_RENDER_TYPE , GLX_RGBA_BIT,
793
-
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
794
-
GLX_RED_SIZE , 8,
795
-
GLX_GREEN_SIZE , 8,
796
-
GLX_BLUE_SIZE , 8,
797
-
GLX_ALPHA_SIZE , 8,
798
-
GLX_DEPTH_SIZE , 24,
799
-
GLX_STENCIL_SIZE , 8,
800
-
GLX_DOUBLEBUFFER , True,
801
-
//GLX_SAMPLE_BUFFERS , 1,
802
-
//GLX_SAMPLES , 4,
803
-
None
804
-
};
870
+
static int visual_attribs[] = {
871
+
GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
872
+
GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
873
+
GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8,
874
+
GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True,
875
+
// GLX_SAMPLE_BUFFERS , 1,
876
+
// GLX_SAMPLES , 4,
877
+
None};
878
+
879
+
GLint major, minor;
880
+
glXQueryVersion(dpy, &major, &minor);
881
+
if ((major == 1 && minor < 3) || (major < 1)) {
882
+
fprintf(stderr, "Invalid GLX version\n");
883
+
XCloseDisplay(dpy);
884
+
return BITE_ERROR;
885
+
}
805
886
806
-
GLint major, minor;
807
-
glXQueryVersion(dpy, &major, &minor);
808
-
if ((major == 1 && minor < 3) || (major < 1)) {
809
-
fprintf(stderr, "Invalid GLX version\n");
810
-
XCloseDisplay(dpy);
811
-
return BITE_ERROR;
812
-
}
887
+
int fbcount;
888
+
GLXFBConfig *fbc = glXChooseFBConfig(dpy, scrId, visual_attribs, &fbcount);
889
+
if (!fbc) {
890
+
fprintf(stderr, "Failed to retrieve a framebuffer config\n");
891
+
return BITE_ERROR;
892
+
}
813
893
814
-
int fbcount;
815
-
GLXFBConfig* fbc = glXChooseFBConfig(dpy, scrId, visual_attribs, &fbcount);
816
-
if (!fbc) {
817
-
fprintf(stderr, "Failed to retrieve a framebuffer config\n");
818
-
return BITE_ERROR;
819
-
}
894
+
int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
820
895
821
-
int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
896
+
int i;
897
+
for (i = 0; i < fbcount; ++i) {
898
+
XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, fbc[i]);
899
+
if (vi) {
900
+
int samp_buf, samples;
901
+
glXGetFBConfigAttrib(dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
902
+
glXGetFBConfigAttrib(dpy, fbc[i], GLX_SAMPLES, &samples);
822
903
823
-
int i;
824
-
for (i=0; i<fbcount; ++i) {
825
-
XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, fbc[i]);
826
-
if ( vi )
827
-
{
828
-
int samp_buf, samples;
829
-
glXGetFBConfigAttrib(dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
830
-
glXGetFBConfigAttrib(dpy, fbc[i], GLX_SAMPLES, &samples);
831
-
832
-
// printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
833
-
// " SAMPLES = %d\n",
834
-
// i, vi -> visualid, samp_buf, samples );
904
+
// printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
905
+
// " SAMPLES = %d\n",
906
+
// i, vi -> visualid, samp_buf, samples );
835
907
836
-
if ( best_fbc < 0 || samp_buf && samples > best_num_samp )
837
-
best_fbc = i, best_num_samp = samples;
838
-
if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp )
839
-
worst_fbc = i, worst_num_samp = samples;
840
-
}
841
-
XFree( vi );
908
+
if (best_fbc < 0 || samp_buf && samples > best_num_samp)
909
+
best_fbc = i, best_num_samp = samples;
910
+
if (worst_fbc < 0 || !samp_buf || samples < worst_num_samp)
911
+
worst_fbc = i, worst_num_samp = samples;
842
912
}
843
-
GLXFBConfig bestFbc = fbc[best_fbc];
844
-
XFree(fbc);
913
+
XFree(vi);
914
+
}
915
+
GLXFBConfig bestFbc = fbc[best_fbc];
916
+
XFree(fbc);
845
917
846
-
XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, bestFbc);
847
-
XSetWindowAttributes swa;
848
-
Colormap map;
849
-
swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
850
-
swa.background_pixmap = None;
851
-
swa.border_pixel = 0;
852
-
swa.event_mask = ExposureMask | StructureNotifyMask;
918
+
XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, bestFbc);
919
+
XSetWindowAttributes swa;
920
+
Colormap map;
921
+
swa.colormap =
922
+
XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
923
+
swa.background_pixmap = None;
924
+
swa.border_pixel = 0;
925
+
swa.event_mask = ExposureMask | StructureNotifyMask;
853
926
854
-
handle = XCreateWindow(
855
-
dpy, RootWindow(dpy, vi->screen),
856
-
0, 0, conf->window.width, conf->window.height,
857
-
0, vi->depth, InputOutput,
858
-
vi->visual,
859
-
CWBorderPixel | CWColormap | CWEventMask, &swa
860
-
);
927
+
handle =
928
+
XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, conf->window.width,
929
+
conf->window.height, 0, vi->depth, InputOutput, vi->visual,
930
+
CWBorderPixel | CWColormap | CWEventMask, &swa);
861
931
862
-
if (!handle) {
863
-
fprintf(stderr, "Failed to create X11 window\n");
864
-
return BITE_ERROR;
865
-
}
932
+
if (!handle) {
933
+
fprintf(stderr, "Failed to create X11 window\n");
934
+
return BITE_ERROR;
935
+
}
866
936
867
-
XFree(vi);
868
-
XStoreName(dpy, handle, conf->window.title);
869
-
XMapWindow(dpy, handle);
937
+
XFree(vi);
938
+
XStoreName(dpy, handle, conf->window.title);
939
+
XMapWindow(dpy, handle);
870
940
871
-
window->handle = handle;
872
-
window->display = dpy;
873
-
window->map = swa.colormap;
874
-
window->fbconf = bestFbc;
941
+
window->handle = handle;
942
+
window->display = dpy;
943
+
window->map = swa.colormap;
944
+
window->fbconf = bestFbc;
875
945
#endif
876
-
window->width = conf->window.width;
877
-
window->height = conf->window.height;
878
-
return BITE_OK;
946
+
window->width = conf->window.width;
947
+
window->height = conf->window.height;
948
+
return BITE_OK;
879
949
}
880
950
881
-
BITE_RESULT _init_render(be_Render* render, const be_Window* window, const be_Config* conf) {
951
+
BITE_RESULT _init_render(be_Render *render, const be_Window *window,
952
+
const be_Config *conf) {
882
953
#if defined(_WIN32)
883
-
init_opengl_extensions();
884
-
HDC hdc = window->dev_context;
885
-
int pixel_format_attribs[] = {
886
-
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
887
-
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
888
-
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
889
-
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
890
-
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
891
-
WGL_COLOR_BITS_ARB, 32,
892
-
WGL_DEPTH_BITS_ARB, 24,
893
-
WGL_STENCIL_BITS_ARB, 8,
894
-
0, 0
895
-
};
954
+
init_opengl_extensions();
955
+
HDC hdc = window->dev_context;
956
+
int pixel_format_attribs[] = {WGL_DRAW_TO_WINDOW_ARB,
957
+
GL_TRUE,
958
+
WGL_SUPPORT_OPENGL_ARB,
959
+
GL_TRUE,
960
+
WGL_DOUBLE_BUFFER_ARB,
961
+
GL_TRUE,
962
+
WGL_ACCELERATION_ARB,
963
+
WGL_FULL_ACCELERATION_ARB,
964
+
WGL_PIXEL_TYPE_ARB,
965
+
WGL_TYPE_RGBA_ARB,
966
+
WGL_COLOR_BITS_ARB,
967
+
32,
968
+
WGL_DEPTH_BITS_ARB,
969
+
24,
970
+
WGL_STENCIL_BITS_ARB,
971
+
8,
972
+
0,
973
+
0};
896
974
897
-
int pixel_format;
898
-
UINT num_formats;
899
-
wglChoosePixelFormatARB(hdc, pixel_format_attribs, 0, 1, &pixel_format, &num_formats);
900
-
if (!num_formats) {
901
-
MessageBox(
902
-
NULL,
903
-
_T("Failed to set Modern OpenGL pixel format"),
904
-
_T("bitEngine"),
905
-
NULL
906
-
);
907
-
DestroyWindow(window->handle);
908
-
return BITE_ERROR;
909
-
}
975
+
int pixel_format;
976
+
UINT num_formats;
977
+
wglChoosePixelFormatARB(hdc, pixel_format_attribs, 0, 1, &pixel_format,
978
+
&num_formats);
979
+
if (!num_formats) {
980
+
MessageBox(NULL, _T("Failed to set Modern OpenGL pixel format"),
981
+
_T("bitEngine"), NULL);
982
+
DestroyWindow(window->handle);
983
+
return BITE_ERROR;
984
+
}
910
985
911
-
PIXELFORMATDESCRIPTOR pfd;
912
-
DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd);
913
-
if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
914
-
MessageBox(
915
-
NULL,
916
-
_T("Failed to set Modern OpenGL pixel format\n"),
917
-
_T("bitEngine"),
918
-
NULL
919
-
);
920
-
DestroyWindow(window->handle);
921
-
return BITE_ERROR;
922
-
}
986
+
PIXELFORMATDESCRIPTOR pfd;
987
+
DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd);
988
+
if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
989
+
MessageBox(NULL, _T("Failed to set Modern OpenGL pixel format\n"),
990
+
_T("bitEngine"), NULL);
991
+
DestroyWindow(window->handle);
992
+
return BITE_ERROR;
993
+
}
923
994
924
-
int gl_attribs[] = {
925
-
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
926
-
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
927
-
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
928
-
0, 0
929
-
};
995
+
int gl_attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB,
996
+
3,
997
+
WGL_CONTEXT_MINOR_VERSION_ARB,
998
+
0,
999
+
WGL_CONTEXT_PROFILE_MASK_ARB,
1000
+
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
1001
+
0,
1002
+
0};
930
1003
931
-
HGLRC hglrc = wglCreateContextAttribsARB(hdc, 0, gl_attribs);
932
-
if (!hglrc) {
933
-
MessageBox(
934
-
NULL,
935
-
_T("Failed to create Modern OpenGL context"),
936
-
_T("bitEngine"),
937
-
NULL
938
-
);
939
-
DestroyWindow(window->handle);
940
-
return BITE_ERROR;
941
-
}
942
-
wglMakeCurrent(hdc, hglrc);
1004
+
HGLRC hglrc = wglCreateContextAttribsARB(hdc, 0, gl_attribs);
1005
+
if (!hglrc) {
1006
+
MessageBox(NULL, _T("Failed to create Modern OpenGL context"),
1007
+
_T("bitEngine"), NULL);
1008
+
DestroyWindow(window->handle);
1009
+
return BITE_ERROR;
1010
+
}
1011
+
wglMakeCurrent(hdc, hglrc);
943
1012
944
-
if (_load_gl() != BITE_OK) {
945
-
MessageBox(
946
-
NULL,
947
-
_T("Failed to init OpenGL loader"),
948
-
_T("bitEngine"),
949
-
NULL
950
-
);
951
-
DestroyWindow(window->handle);
952
-
return BITE_ERROR;
953
-
}
954
-
_setup_gl();
955
-
_close_gl();
1013
+
if (_load_gl() != BITE_OK) {
1014
+
MessageBox(NULL, _T("Failed to init OpenGL loader"), _T("bitEngine"), NULL);
1015
+
DestroyWindow(window->handle);
1016
+
return BITE_ERROR;
1017
+
}
1018
+
_setup_gl();
1019
+
_close_gl();
956
1020
#elif defined(__EMSCRIPTEN__)
957
-
EmscriptenWebGLContextAttributes attr;
958
-
emscripten_webgl_init_context_attributes(&attr);
959
-
attr.alpha = 0;
960
-
render->gl_context = emscripten_webgl_create_context("#canvas", &attr);
961
-
emscripten_webgl_make_context_current(render->gl_context);
1021
+
EmscriptenWebGLContextAttributes attr;
1022
+
emscripten_webgl_init_context_attributes(&attr);
1023
+
attr.alpha = 0;
1024
+
render->gl_context = emscripten_webgl_create_context("#canvas", &attr);
1025
+
emscripten_webgl_make_context_current(render->gl_context);
962
1026
#else
963
-
Display* dpy = window->display;
964
-
int scrId = DefaultScreen(dpy);
965
-
const char* glxExts = glXQueryExtensionsString(dpy, scrId);
966
-
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
967
-
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");
1027
+
Display *dpy = window->display;
1028
+
int scrId = DefaultScreen(dpy);
1029
+
const char *glxExts = glXQueryExtensionsString(dpy, scrId);
1030
+
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
1031
+
glXCreateContextAttribsARB =
1032
+
(glXCreateContextAttribsARBProc)glXGetProcAddressARB(
1033
+
(const GLubyte *)"glXCreateContextAttribsARB");
968
1034
969
-
GLXContext ctx = 0;
1035
+
GLXContext ctx = 0;
970
1036
971
-
if (!glXCreateContextAttribsARB) {
972
-
fprintf(stderr, "Failed to load glXCreateContextAttribsARB(), loading legacy OpenGL context\n");
973
-
ctx = glXCreateNewContext(dpy, window->fbconf, GLX_RGBA_TYPE, 0, True);
974
-
} else {
975
-
int context_attribs[] = {
976
-
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
977
-
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
978
-
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
979
-
None
980
-
};
1037
+
if (!glXCreateContextAttribsARB) {
1038
+
fprintf(stderr, "Failed to load glXCreateContextAttribsARB(), loading "
1039
+
"legacy OpenGL context\n");
1040
+
ctx = glXCreateNewContext(dpy, window->fbconf, GLX_RGBA_TYPE, 0, True);
1041
+
} else {
1042
+
int context_attribs[] = {GLX_CONTEXT_MAJOR_VERSION_ARB,
1043
+
2,
1044
+
GLX_CONTEXT_MINOR_VERSION_ARB,
1045
+
1,
1046
+
GLX_CONTEXT_PROFILE_MASK_ARB,
1047
+
GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
1048
+
None};
981
1049
982
-
ctx = glXCreateContextAttribsARB(dpy, window->fbconf, 0, True, context_attribs);
983
-
XSync(dpy, False);
984
-
if (!ctx) {
985
-
fprintf(stderr, "Failed to create 3.0 OpenGL context\n");
986
-
XDestroyWindow(dpy, window->handle);
987
-
XFreeColormap(dpy, window->map);
988
-
XCloseDisplay(dpy);
989
-
return BITE_ERROR;
990
-
}
991
-
glXMakeCurrent(dpy, window->handle, ctx);
992
-
render->gl_context = ctx;
993
-
if (_load_gl() != BITE_OK) {
994
-
fprintf(stderr, "Failed to init OpenGL loader\n");
995
-
XDestroyWindow(dpy, window->handle);
996
-
XFreeColormap(dpy, window->map);
997
-
XCloseDisplay(dpy);
998
-
return BITE_ERROR;
999
-
}
1050
+
ctx = glXCreateContextAttribsARB(dpy, window->fbconf, 0, True,
1051
+
context_attribs);
1052
+
XSync(dpy, False);
1053
+
if (!ctx) {
1054
+
fprintf(stderr, "Failed to create 3.0 OpenGL context\n");
1055
+
XDestroyWindow(dpy, window->handle);
1056
+
XFreeColormap(dpy, window->map);
1057
+
XCloseDisplay(dpy);
1058
+
return BITE_ERROR;
1059
+
}
1060
+
glXMakeCurrent(dpy, window->handle, ctx);
1061
+
render->gl_context = ctx;
1062
+
if (_load_gl() != BITE_OK) {
1063
+
fprintf(stderr, "Failed to init OpenGL loader\n");
1064
+
XDestroyWindow(dpy, window->handle);
1065
+
XFreeColormap(dpy, window->map);
1066
+
XCloseDisplay(dpy);
1067
+
return BITE_ERROR;
1068
+
}
1000
1069
_setup_gl();
1001
1070
_close_gl();
1002
-
}
1071
+
}
1003
1072
#endif
1004
-
return BITE_OK;
1073
+
return BITE_OK;
1005
1074
}
1006
1075
1007
1076
#if 0
···
1201
1270
return BITE_OK;
1202
1271
}
1203
1272
#endif
1204
-
void _poll_events(be_Context* ctx) {
1273
+
void _poll_events(be_Context *ctx) {
1205
1274
#if defined(_WIN32)
1206
-
MSG message;
1207
-
if (GetMessage(&message, NULL, 0, 0)) {
1208
-
TranslateMessage(&message);
1209
-
DispatchMessage(&message);
1210
-
}
1275
+
MSG message;
1276
+
if (GetMessage(&message, NULL, 0, 0)) {
1277
+
TranslateMessage(&message);
1278
+
DispatchMessage(&message);
1279
+
}
1211
1280
#elif defined(__EMSCRIPTEN__)
1212
1281
#else
1213
-
XEvent ev;
1214
-
be_Window* window = &(ctx->window);
1215
-
while (XPending(window->display)) {
1216
-
XNextEvent(window->display, &ev);
1217
-
be_Event e = {0};
1218
-
be_EventCallback fn = NULL;
1219
-
switch(ev.type) {
1220
-
case ClientMessage: {
1221
-
if (ev.xclient.data.l[0] == XInternAtom(window->display, "WM_DELETE_WINDOW", 0)) {
1222
-
e.type = BITE_WINDOW_CLOSE;
1223
-
}
1224
-
}
1225
-
break;
1226
-
case DestroyNotify: {
1227
-
e.type = BITE_QUIT;
1228
-
}
1229
-
break;
1230
-
case ConfigureNotify: {
1231
-
XConfigureEvent xce = ev.xconfigure;
1232
-
if ((xce.x != window->x) || (xce.y != window->y)) {
1233
-
window->x = xce.x;
1234
-
window->y = xce.y;
1235
-
e.type = BITE_WINDOW_MOVE;
1236
-
e.window.x = xce.x;
1237
-
e.window.y = xce.y;
1238
-
e.window.handle = window;
1239
-
}
1282
+
XEvent ev;
1283
+
be_Window *window = &(ctx->window);
1284
+
while (XPending(window->display)) {
1285
+
XNextEvent(window->display, &ev);
1286
+
be_Event e = {0};
1287
+
be_EventCallback fn = NULL;
1288
+
switch (ev.type) {
1289
+
case ClientMessage: {
1290
+
if (ev.xclient.data.l[0] ==
1291
+
XInternAtom(window->display, "WM_DELETE_WINDOW", 0)) {
1292
+
e.type = BITE_WINDOW_CLOSE;
1293
+
}
1294
+
} break;
1295
+
case DestroyNotify: {
1296
+
e.type = BITE_QUIT;
1297
+
} break;
1298
+
case ConfigureNotify: {
1299
+
XConfigureEvent xce = ev.xconfigure;
1300
+
if ((xce.x != window->x) || (xce.y != window->y)) {
1301
+
window->x = xce.x;
1302
+
window->y = xce.y;
1303
+
e.type = BITE_WINDOW_MOVE;
1304
+
e.window.x = xce.x;
1305
+
e.window.y = xce.y;
1306
+
e.window.handle = window;
1307
+
}
1240
1308
1241
-
if ((xce.width != window->width) || (xce.height != window->height)) {
1242
-
window->width = xce.width;
1243
-
window->height = xce.height;
1244
-
e.type = BITE_WINDOW_RESIZE;
1245
-
e.window.x = xce.width;
1246
-
e.window.y = xce.height;
1247
-
e.window.handle = window;
1248
-
}
1249
-
}
1250
-
break;
1251
-
case KeyPress: {
1252
-
e.type = BITE_KEY_PRESSED;
1253
-
e.key.keycode = ev.xkey.keycode;
1254
-
}
1255
-
break;
1256
-
case KeyRelease: {
1257
-
e.type = BITE_KEY_RELEASED;
1258
-
e.key.keycode = ev.xkey.keycode;
1259
-
}
1260
-
break;
1261
-
}
1262
-
fn = ctx->callbacks[e.type];
1263
-
if (fn) fn(ctx, &e);
1309
+
if ((xce.width != window->width) || (xce.height != window->height)) {
1310
+
window->width = xce.width;
1311
+
window->height = xce.height;
1312
+
e.type = BITE_WINDOW_RESIZE;
1313
+
e.window.x = xce.width;
1314
+
e.window.y = xce.height;
1315
+
e.window.handle = window;
1316
+
}
1317
+
} break;
1318
+
case KeyPress: {
1319
+
e.type = BITE_KEY_PRESSED;
1320
+
e.key.keycode = ev.xkey.keycode;
1321
+
} break;
1322
+
case KeyRelease: {
1323
+
e.type = BITE_KEY_RELEASED;
1324
+
e.key.keycode = ev.xkey.keycode;
1325
+
} break;
1264
1326
}
1327
+
fn = ctx->callbacks[e.type];
1328
+
if (fn)
1329
+
fn(ctx, &e);
1330
+
}
1265
1331
#endif
1266
1332
}
1267
1333
1268
1334
// OpenGL loader
1269
1335
1270
1336
#if !defined(__APPLE__) && !defined(__HAIKU__)
1271
-
void* (*_proc_address)(const char*);
1337
+
void *(*_proc_address)(const char *);
1272
1338
#endif
1273
1339
1274
-
#define GET_GL_PROC(name)\
1275
-
name = (name##Proc*)_get_proc(#name)
1340
+
#define GET_GL_PROC(name) name = (name##Proc *)_get_proc(#name)
1276
1341
1277
-
void* _get_proc(const char*);
1342
+
void *_get_proc(const char *);
1278
1343
1279
1344
BITE_RESULT _load_gl(void) {
1280
1345
#if defined(_WIN32)
1281
-
_gl_sym = LoadLibrary("opengl32.dll");
1282
-
if (_gl_sym == NULL) {
1283
-
fprintf(stderr, "Failed to load OpenGL32.dll\n");
1284
-
return BITE_ERROR;
1285
-
}
1286
-
_proc_address = (void*(*)(const char*))GetProcAddress(_gl_sym, "wglGetProcAddress");
1346
+
_gl_sym = LoadLibrary("opengl32.dll");
1347
+
if (_gl_sym == NULL) {
1348
+
fprintf(stderr, "Failed to load OpenGL32.dll\n");
1349
+
return BITE_ERROR;
1350
+
}
1351
+
_proc_address =
1352
+
(void *(*)(const char *))GetProcAddress(_gl_sym, "wglGetProcAddress");
1287
1353
#elif defined(__EMSCRIPTEN__)
1288
1354
#else
1289
-
#if defined(__APPLE__)
1290
-
const char *names[] = {
1291
-
"../Frameworks/OpenGL.framework/OpenGL",
1292
-
"/Library/Frameworks/OpenGL.framework/Opengl",
1293
-
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
1294
-
"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL",
1295
-
NULL,
1296
-
};
1297
-
#else
1298
-
const char *names[] = {
1299
-
"libGL.so.1",
1300
-
"libGL.so",
1301
-
NULL,
1302
-
};
1303
-
#endif
1304
-
int index;
1305
-
for (index = 0; names[index] != NULL; ++index) {
1306
-
_gl_sym = dlopen(names[index], RTLD_LAZY | RTLD_GLOBAL);
1307
-
if (_gl_sym != NULL) {
1308
-
#if defined(__APPLE__) || defined(__HAIKU__)
1309
-
return BITE_OK;
1310
-
#else
1311
-
_proc_address = (void*(*)(const char*))dlsym(_gl_sym, "glXGetProcAddress");
1312
-
return _proc_address != NULL ? BITE_OK : BITE_ERROR;
1313
-
#endif
1314
-
break;
1315
-
}
1316
-
}
1355
+
#if defined(__APPLE__)
1356
+
const char *names[] = {
1357
+
"../Frameworks/OpenGL.framework/OpenGL",
1358
+
"/Library/Frameworks/OpenGL.framework/Opengl",
1359
+
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
1360
+
"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL",
1361
+
NULL,
1362
+
};
1363
+
#else
1364
+
const char *names[] = {
1365
+
"libGL.so.1",
1366
+
"libGL.so",
1367
+
NULL,
1368
+
};
1369
+
#endif
1370
+
int index;
1371
+
for (index = 0; names[index] != NULL; ++index) {
1372
+
_gl_sym = dlopen(names[index], RTLD_LAZY | RTLD_GLOBAL);
1373
+
if (_gl_sym != NULL) {
1374
+
#if defined(__APPLE__) || defined(__HAIKU__)
1375
+
return BITE_OK;
1376
+
#else
1377
+
_proc_address =
1378
+
(void *(*)(const char *))dlsym(_gl_sym, "glXGetProcAddress");
1379
+
return _proc_address != NULL ? BITE_OK : BITE_ERROR;
1317
1380
#endif
1318
-
return BITE_OK;
1381
+
break;
1382
+
}
1383
+
}
1384
+
#endif
1385
+
return BITE_OK;
1319
1386
}
1320
1387
1321
1388
#if !defined(__EMSCRIPTEN__)
1322
1389
void _close_gl(void) {
1323
-
if (_gl_sym != NULL) {
1390
+
if (_gl_sym != NULL) {
1324
1391
#if defined(_WIN32)
1325
-
FreeLibrary(_gl_sym);
1392
+
FreeLibrary(_gl_sym);
1326
1393
#else
1327
-
dlclose(_gl_sym);
1394
+
dlclose(_gl_sym);
1328
1395
#endif
1329
-
_gl_sym = NULL;
1330
-
}
1396
+
_gl_sym = NULL;
1397
+
}
1331
1398
}
1332
1399
1333
1400
void _setup_gl(void) {
1334
-
const char* version = glGetString(GL_VERSION);
1335
-
const char* glsl = glGetString(GL_SHADING_LANGUAGE_VERSION);
1336
-
if (!version) {
1337
-
fprintf(stderr, "Failed to get OpenGL version\n");
1338
-
}
1339
-
const char* prefixes[] = {
1340
-
"OpenGL ES-CM ",
1341
-
"OpenGL ES-CL ",
1342
-
"OpenGL ES ",
1343
-
NULL
1344
-
};
1401
+
const char *version = (const char*)glGetString(GL_VERSION);
1402
+
const char *glsl = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
1403
+
if (!version) {
1404
+
fprintf(stderr, "Failed to get OpenGL version\n");
1405
+
}
1406
+
const char *prefixes[] = {"OpenGL ES-CM ", "OpenGL ES-CL ", "OpenGL ES ",
1407
+
NULL};
1345
1408
1346
-
if (version) {
1347
-
const char* ver = version;
1348
-
for (int i = 0; prefixes[i] != NULL; i++) {
1349
-
if (strncmp(ver, prefixes[i], strlen(prefixes[i])) == 0) {
1350
-
ver += strlen(prefixes[i]);
1351
-
fprintf(stdout, "Using OpenGL ES\n");
1352
-
}
1353
-
}
1409
+
if (version) {
1410
+
const char *ver = version;
1411
+
for (int i = 0; prefixes[i] != NULL; i++) {
1412
+
if (strncmp(ver, prefixes[i], strlen(prefixes[i])) == 0) {
1413
+
ver += strlen(prefixes[i]);
1414
+
fprintf(stdout, "Using OpenGL ES\n");
1415
+
}
1354
1416
}
1355
-
1356
-
fprintf(stderr, "OpenGL: %s\n", version);
1417
+
}
1357
1418
1358
-
GET_GL_PROC(glGenVertexArrays);
1359
-
GET_GL_PROC(glBindVertexArray);
1360
-
GET_GL_PROC(glDeleteVertexArrays);
1419
+
fprintf(stderr, "OpenGL: %s\n", version);
1361
1420
1362
-
GET_GL_PROC(glVertexAttribPointer);
1363
-
GET_GL_PROC(glEnableVertexAttribArray);
1364
-
GET_GL_PROC(glDisableVertexAttribArray);
1421
+
GET_GL_PROC(glGenVertexArrays);
1422
+
GET_GL_PROC(glBindVertexArray);
1423
+
GET_GL_PROC(glDeleteVertexArrays);
1365
1424
1366
-
GET_GL_PROC(glGenBuffers);
1367
-
GET_GL_PROC(glBindBuffer);
1368
-
GET_GL_PROC(glDeleteBuffers);
1369
-
GET_GL_PROC(glBufferData);
1370
-
GET_GL_PROC(glBufferSubData);
1425
+
GET_GL_PROC(glVertexAttribPointer);
1426
+
GET_GL_PROC(glEnableVertexAttribArray);
1427
+
GET_GL_PROC(glDisableVertexAttribArray);
1371
1428
1372
-
GET_GL_PROC(glCreateShader);
1373
-
GET_GL_PROC(glShaderSource);
1374
-
GET_GL_PROC(glCompileShader);
1375
-
GET_GL_PROC(glGetShaderiv);
1376
-
GET_GL_PROC(glGetShaderInfoLog);
1377
-
GET_GL_PROC(glDeleteShader);
1378
-
GET_GL_PROC(glCreateProgram);
1379
-
GET_GL_PROC(glAttachShader);
1380
-
GET_GL_PROC(glLinkProgram);
1381
-
GET_GL_PROC(glGetProgramiv);
1382
-
GET_GL_PROC(glGetProgramInfoLog);
1383
-
GET_GL_PROC(glUseProgram);
1384
-
GET_GL_PROC(glDeleteProgram);
1429
+
GET_GL_PROC(glGenBuffers);
1430
+
GET_GL_PROC(glBindBuffer);
1431
+
GET_GL_PROC(glDeleteBuffers);
1432
+
GET_GL_PROC(glBufferData);
1433
+
GET_GL_PROC(glBufferSubData);
1434
+
1435
+
GET_GL_PROC(glCreateShader);
1436
+
GET_GL_PROC(glShaderSource);
1437
+
GET_GL_PROC(glCompileShader);
1438
+
GET_GL_PROC(glGetShaderiv);
1439
+
GET_GL_PROC(glGetShaderInfoLog);
1440
+
GET_GL_PROC(glDeleteShader);
1441
+
GET_GL_PROC(glCreateProgram);
1442
+
GET_GL_PROC(glAttachShader);
1443
+
GET_GL_PROC(glLinkProgram);
1444
+
GET_GL_PROC(glGetProgramiv);
1445
+
GET_GL_PROC(glGetProgramInfoLog);
1446
+
GET_GL_PROC(glUseProgram);
1447
+
GET_GL_PROC(glDeleteProgram);
1385
1448
}
1386
1449
1387
-
static inline void* _get_proc(const char* name) {
1388
-
void* sym = NULL;
1389
-
if (_gl_sym == NULL) return sym;
1450
+
static inline void *_get_proc(const char *name) {
1451
+
void *sym = NULL;
1452
+
if (_gl_sym == NULL)
1453
+
return sym;
1390
1454
#if !defined(__APPLE__) && !defined(__HAIKU__)
1391
-
if (_proc_address != NULL) sym = _proc_address(name);
1455
+
if (_proc_address != NULL)
1456
+
sym = _proc_address(name);
1392
1457
#endif
1393
-
if (sym == NULL) {
1458
+
if (sym == NULL) {
1394
1459
#if defined(_WIN32) || defined(__CYGWWIN__)
1395
-
sym = (void*)GetProcAddress(_gl_sym, name);
1460
+
sym = (void *)GetProcAddress(_gl_sym, name);
1396
1461
#else
1397
-
sym = (void*)dlsym(_gl_sym, name);
1462
+
sym = (void *)dlsym(_gl_sym, name);
1398
1463
#endif
1399
-
}
1400
-
fprintf(stderr, "%s: %p\n", name, sym);
1401
-
return sym;
1464
+
}
1465
+
fprintf(stderr, "%s: %p\n", name, sym);
1466
+
return sym;
1402
1467
}
1403
-
#endif
1468
+
#endif
+75
-3
bite.h
+75
-3
bite.h
···
55
55
56
56
enum {
57
57
BITEK_NONE = 0,
58
+
59
+
BITEK_BACKSPACE,
60
+
BITEK_TAB,
61
+
BITEK_RETURN,
62
+
BITEK_SHIFT,
63
+
BITEK_CONTROL,
64
+
58
65
BITEK_ESCAPE,
59
-
BITEK_RETURN,
66
+
67
+
BITEK_SPACE,
68
+
69
+
BITEK_PAGEUP,
70
+
BITEK_PAGEDOWN,
71
+
72
+
BITEK_LEFT,
60
73
BITEK_UP,
61
74
BITEK_RIGHT,
62
75
BITEK_DOWN,
63
-
BITEK_LEFT
76
+
77
+
BITEK_END,
78
+
BITEK_HOME,
79
+
BITEK_INSERT,
80
+
BITEK_DELETE,
81
+
82
+
BITEK_0,
83
+
BITEK_1,
84
+
BITEK_2,
85
+
BITEK_3,
86
+
BITEK_4,
87
+
BITEK_5,
88
+
BITEK_6,
89
+
BITEK_7,
90
+
BITEK_8,
91
+
BITEK_9,
92
+
93
+
BITEK_A,
94
+
BITEK_B,
95
+
BITEK_C,
96
+
BITEK_D,
97
+
BITEK_E,
98
+
BITEK_F,
99
+
BITEK_G,
100
+
BITEK_H,
101
+
BITEK_I,
102
+
BITEK_J,
103
+
BITEK_K,
104
+
BITEK_L,
105
+
BITEK_M,
106
+
BITEK_N,
107
+
BITEK_O,
108
+
BITEK_P,
109
+
BITEK_Q,
110
+
BITEK_R,
111
+
BITEK_S,
112
+
BITEK_T,
113
+
BITEK_U,
114
+
BITEK_V,
115
+
BITEK_W,
116
+
BITEK_X,
117
+
BITEK_Y,
118
+
BITEK_Z,
119
+
120
+
BITEK_LWIN,
121
+
BITEK_RWIN,
122
+
BITEK_APPS,
123
+
124
+
BITEK_NUMPAD0,
125
+
BITEK_NUMPAD1,
126
+
BITEK_NUMPAD2,
127
+
BITEK_NUMPAD3,
128
+
BITEK_NUMPAD4,
129
+
BITEK_NUMPAD5,
130
+
BITEK_NUMPAD6,
131
+
BITEK_NUMPAD7,
132
+
BITEK_NUMPAD8,
133
+
BITEK_NUMPAD9,
134
+
BITEK_MULTIPLY,
135
+
BITEK_ADD,
64
136
};
65
137
66
138
enum {
···
172
244
}
173
245
#endif
174
246
175
-
#endif /* _BIT_ENGINE_ */
247
+
#endif /* _BIT_ENGINE_ */