-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite.h
270 lines (215 loc) · 5.74 KB
/
bite.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#ifndef _BIT_ENGINE_
#define _BIT_ENGINE_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BITE_VERSION "0.1.0"
#define BITE_API extern
typedef unsigned char be_u8;
typedef unsigned short be_u16;
typedef unsigned int be_u32;
typedef unsigned long int be_u64;
typedef struct {float x, y, w, h; } be_Rect;
typedef struct be_Context be_Context;
typedef struct be_Window be_Window;
typedef struct be_Event be_Event;
typedef struct be_Texture be_Texture;
typedef struct be_Framebuffer be_Framebuffer;
typedef struct be_Shader be_Shader;
typedef struct be_Font be_Font;
typedef void(*be_EventCallback)(be_Context*, be_Event*);
#define BITE_TRUE 1
#define BITE_FALSE 0
#define BITE_OK 0
#define BITE_ERROR -1
#define BITE_RESULT int
#define BITE_BOOL be_u8
enum {
BITE_NONE = 0,
BITE_QUIT,
BITE_KEY_PRESSED,
BITE_KEY_RELEASED,
BITE_WINDOW_RESIZE,
BITE_WINDOW_MOVE,
BITE_WINDOW_MINIMIZE,
BITE_WINDOW_MAXIMIZE,
BITE_WINDOW_RESTORE,
BITE_WINDOW_CLOSE,
BITE_EVENTS
};
enum {
BITEK_NONE = 0,
BITEK_BACKSPACE,
BITEK_TAB,
BITEK_RETURN,
BITEK_LALT,
BITEK_RALT,
BITEK_LSHIFT,
BITEK_RSHIFT,
BITEK_LCONTROL,
BITEK_RCONTROL,
BITEK_ESCAPE,
BITEK_SPACE,
BITEK_PAGEUP,
BITEK_PAGEDOWN,
BITEK_LEFT,
BITEK_UP,
BITEK_RIGHT,
BITEK_DOWN,
BITEK_END,
BITEK_HOME,
BITEK_INSERT,
BITEK_DELETE,
BITEK_0,
BITEK_1,
BITEK_2,
BITEK_3,
BITEK_4,
BITEK_5,
BITEK_6,
BITEK_7,
BITEK_8,
BITEK_9,
BITEK_A,
BITEK_B,
BITEK_C,
BITEK_D,
BITEK_E,
BITEK_F,
BITEK_G,
BITEK_H,
BITEK_I,
BITEK_J,
BITEK_K,
BITEK_L,
BITEK_M,
BITEK_N,
BITEK_O,
BITEK_P,
BITEK_Q,
BITEK_R,
BITEK_S,
BITEK_T,
BITEK_U,
BITEK_V,
BITEK_W,
BITEK_X,
BITEK_Y,
BITEK_Z,
BITEK_LSUPER,
BITEK_RSUPER,
BITEK_APPS,
BITEK_NUMPAD0,
BITEK_NUMPAD1,
BITEK_NUMPAD2,
BITEK_NUMPAD3,
BITEK_NUMPAD4,
BITEK_NUMPAD5,
BITEK_NUMPAD6,
BITEK_NUMPAD7,
BITEK_NUMPAD8,
BITEK_NUMPAD9,
BITEK_MULTIPLY,
BITEK_PLUS,
BITEK_MINUS,
BITEK_LESS,
BITEK_EQUAL,
BITEK_GREATER,
BITEK_F1,
BITEK_F2,
BITEK_F3,
BITEK_F4,
BITEK_F5,
BITEK_F6,
BITEK_F7,
BITEK_F8,
BITEK_F9,
BITEK_F10,
BITEK_F11,
BITEK_F12,
};
enum {
BITE_POINTS = 0,
BITE_LINES,
BITE_TRIANGLES
};
struct be_Event {
int type;
union {
struct {
be_Window* handle;
const char title[128];
int x, y;
void* data0;
void* data1;
} window;
struct {
int keycode;
} key;
};
};
typedef struct {
struct {
char title[128];
int width, height;
int flags;
} window;
} be_Config;
#if defined(__cplusplus)
extern "C" {
#endif
BITE_API void bite_simple_triangle(be_Context* ctx);
/*********************
* Core
*********************/
BITE_API be_Config bite_init_config(const char* title, int w, int h);
BITE_API be_Context* bite_create(const be_Config* conf);
BITE_API void bite_destroy(be_Context* ctx);
BITE_API void bite_register_callback(be_Context* ctx, int type, be_EventCallback callback);
BITE_API int bite_should_close(be_Context* ctx);
BITE_API void bite_set_should_close(be_Context* ctx, int should_close);
BITE_API void bite_poll_events(be_Context* ctx);
BITE_API void bite_swap(be_Context* ctx);
/*********************
* Window
*********************/
BITE_API void bite_set_window_width(be_Context* ctx, int width);
BITE_API void bite_set_window_height(be_Context* ctx, int height);
BITE_API void bite_set_window_size(be_Context* ctx, int width, int height);
BITE_API int bite_get_window_width(be_Context* ctx);
BITE_API int bite_get_window_height(be_Context* ctx);
BITE_API void bite_get_window_size(int* w, int* h);
BITE_API void bite_get_mouse_pos(int* x, int* y);
/*********************
* Render
*********************/
BITE_API be_Shader* bite_create_shader(const char* vert, const char* src);
BITE_API void bite_destroy_shader(be_Shader* shader);
BITE_API be_Texture* bite_create_texture(int w, int h, int format, void* data);
BITE_API void bite_destroy_texture(be_Texture* texture);
BITE_API be_Framebuffer* bite_create_framebuffer(void);
BITE_API void bite_destroy_framebuffer(be_Framebuffer* fbo);
BITE_API BITE_RESULT bite_framebuffer_attach_texture(be_Framebuffer* fbo, be_Texture* texture);
BITE_API void bite_render_clear_color(float r, float g, float b, float a);
BITE_API void bite_render_clear(void);
BITE_API void bite_bind_framebuffer(be_Framebuffer* fbo);
BITE_API void bite_bind_texture(be_Texture* tex);
BITE_API void bite_use_shader(be_Shader* shader);
BITE_API void bite_render_point(float x, float y);
BITE_API void bite_render_line(float x0, float y0, float x1, float y1);
BITE_API void bite_render_rect(be_Rect* rect);
BITE_API void bite_render_rectangle(float x, float y, float w, float h);
BITE_API void bite_render_circle(float x, float y, float radius);
BITE_API void bite_render_triangle(float x0, float y0, float x1, float y1, float x2, float y2);
BITE_API void bite_render_texture(be_Texture* tex, be_Rect* src, be_Rect* dest);
/*********************
* Timer
*********************/
BITE_API void bite_sleep(be_u64 ms);
BITE_API be_u64 bite_tick(void);
BITE_API void bite_timer_sleep(be_u64 ms);
BITE_API be_u64 bite_timer_tick(void);
#if defined(__cplusplus)
}
#endif
#endif /* _BIT_ENGINE_ */