at main 5.9 kB view raw
1#ifndef _BIT_ENGINE_ 2#define _BIT_ENGINE_ 3 4#include <stdio.h> 5#include <stdlib.h> 6#include <string.h> 7 8#define BITE_VERSION "0.1.0" 9#define BITE_API extern 10 11typedef unsigned char be_u8; 12typedef unsigned short be_u16; 13typedef unsigned int be_u32; 14typedef unsigned long int be_u64; 15 16typedef struct {float x, y, w, h; } be_Rect; 17 18typedef struct be_Context be_Context; 19 20typedef struct be_Window be_Window; 21typedef struct be_Event be_Event; 22 23typedef struct be_Texture be_Texture; 24typedef struct be_Framebuffer be_Framebuffer; 25typedef struct be_Shader be_Shader; 26typedef struct be_Font be_Font; 27 28typedef void(*be_EventCallback)(be_Context*, be_Event*); 29 30#define BITE_TRUE 1 31#define BITE_FALSE 0 32 33#define BITE_OK 0 34#define BITE_ERROR -1 35 36#define BITE_RESULT int 37#define BITE_BOOL be_u8 38 39enum { 40 BITE_NONE = 0, 41 BITE_QUIT, 42 43 BITE_KEY_PRESSED, 44 BITE_KEY_RELEASED, 45 46 BITE_WINDOW_RESIZE, 47 BITE_WINDOW_MOVE, 48 BITE_WINDOW_MINIMIZE, 49 BITE_WINDOW_MAXIMIZE, 50 BITE_WINDOW_RESTORE, 51 BITE_WINDOW_CLOSE, 52 53 BITE_EVENTS 54}; 55 56enum { 57 BITEK_NONE = 0, 58 59 BITEK_BACKSPACE, 60 BITEK_TAB, 61 BITEK_RETURN, 62 BITEK_LALT, 63 BITEK_RALT, 64 BITEK_LSHIFT, 65 BITEK_RSHIFT, 66 BITEK_LCONTROL, 67 BITEK_RCONTROL, 68 69 BITEK_ESCAPE, 70 71 BITEK_SPACE, 72 73 BITEK_PAGEUP, 74 BITEK_PAGEDOWN, 75 76 BITEK_LEFT, 77 BITEK_UP, 78 BITEK_RIGHT, 79 BITEK_DOWN, 80 81 BITEK_END, 82 BITEK_HOME, 83 BITEK_INSERT, 84 BITEK_DELETE, 85 86 BITEK_0, 87 BITEK_1, 88 BITEK_2, 89 BITEK_3, 90 BITEK_4, 91 BITEK_5, 92 BITEK_6, 93 BITEK_7, 94 BITEK_8, 95 BITEK_9, 96 97 BITEK_A, 98 BITEK_B, 99 BITEK_C, 100 BITEK_D, 101 BITEK_E, 102 BITEK_F, 103 BITEK_G, 104 BITEK_H, 105 BITEK_I, 106 BITEK_J, 107 BITEK_K, 108 BITEK_L, 109 BITEK_M, 110 BITEK_N, 111 BITEK_O, 112 BITEK_P, 113 BITEK_Q, 114 BITEK_R, 115 BITEK_S, 116 BITEK_T, 117 BITEK_U, 118 BITEK_V, 119 BITEK_W, 120 BITEK_X, 121 BITEK_Y, 122 BITEK_Z, 123 124 BITEK_LSUPER, 125 BITEK_RSUPER, 126 BITEK_APPS, 127 128 BITEK_NUMPAD0, 129 BITEK_NUMPAD1, 130 BITEK_NUMPAD2, 131 BITEK_NUMPAD3, 132 BITEK_NUMPAD4, 133 BITEK_NUMPAD5, 134 BITEK_NUMPAD6, 135 BITEK_NUMPAD7, 136 BITEK_NUMPAD8, 137 BITEK_NUMPAD9, 138 BITEK_MULTIPLY, 139 BITEK_PLUS, 140 BITEK_MINUS, 141 142 BITEK_LESS, 143 BITEK_EQUAL, 144 BITEK_GREATER, 145 146 BITEK_F1, 147 BITEK_F2, 148 BITEK_F3, 149 BITEK_F4, 150 BITEK_F5, 151 BITEK_F6, 152 BITEK_F7, 153 BITEK_F8, 154 BITEK_F9, 155 BITEK_F10, 156 BITEK_F11, 157 BITEK_F12, 158 159}; 160 161enum { 162 BITE_POINTS = 0, 163 BITE_LINES, 164 BITE_TRIANGLES 165}; 166 167struct be_Event { 168 int type; 169 union { 170 struct { 171 be_Window* handle; 172 const char title[128]; 173 int x, y; 174 void* data0; 175 void* data1; 176 } window; 177 struct { 178 int keycode; 179 } key; 180 }; 181}; 182 183typedef struct { 184 struct { 185 char title[128]; 186 int width, height; 187 int flags; 188 } window; 189} be_Config; 190 191#if defined(__cplusplus) 192extern "C" { 193#endif 194 195BITE_API void bite_simple_triangle(be_Context* ctx); 196 197/********************* 198 * Core 199 *********************/ 200BITE_API be_Config bite_init_config(const char* title, int w, int h); 201 202BITE_API be_Context* bite_create(const be_Config* conf); 203BITE_API void bite_destroy(be_Context* ctx); 204 205BITE_API void bite_register_callback(be_Context* ctx, int type, be_EventCallback callback); 206 207BITE_API int bite_should_close(be_Context* ctx); 208BITE_API void bite_set_should_close(be_Context* ctx, int should_close); 209 210BITE_API void bite_poll_events(be_Context* ctx); 211 212BITE_API void bite_swap(be_Context* ctx); 213 214/********************* 215 * Window 216 *********************/ 217BITE_API void bite_set_window_width(be_Context* ctx, int width); 218BITE_API void bite_set_window_height(be_Context* ctx, int height); 219BITE_API void bite_set_window_size(be_Context* ctx, int width, int height); 220 221BITE_API int bite_get_window_width(be_Context* ctx); 222BITE_API int bite_get_window_height(be_Context* ctx); 223BITE_API void bite_get_window_size(int* w, int* h); 224 225BITE_API void bite_get_mouse_pos(int* x, int* y); 226 227/********************* 228 * Render 229 *********************/ 230 231BITE_API be_Shader* bite_create_shader(const char* vert, const char* src); 232BITE_API void bite_destroy_shader(be_Shader* shader); 233 234BITE_API be_Texture* bite_create_texture(int w, int h, int format, void* data); 235BITE_API void bite_destroy_texture(be_Texture* texture); 236 237BITE_API be_Framebuffer* bite_create_framebuffer(void); 238BITE_API void bite_destroy_framebuffer(be_Framebuffer* fbo); 239BITE_API BITE_RESULT bite_framebuffer_attach_texture(be_Framebuffer* fbo, be_Texture* texture); 240 241BITE_API void bite_render_clear_color(float r, float g, float b, float a); 242BITE_API void bite_render_clear(void); 243 244BITE_API void bite_bind_framebuffer(be_Framebuffer* fbo); 245BITE_API void bite_bind_texture(be_Texture* tex); 246BITE_API void bite_use_shader(be_Shader* shader); 247 248BITE_API void bite_render_point(float x, float y); 249BITE_API void bite_render_line(float x0, float y0, float x1, float y1); 250BITE_API void bite_render_rect(be_Rect* rect); 251BITE_API void bite_render_rectangle(float x, float y, float w, float h); 252BITE_API void bite_render_circle(float x, float y, float radius); 253BITE_API void bite_render_triangle(float x0, float y0, float x1, float y1, float x2, float y2); 254 255BITE_API void bite_render_texture(be_Texture* tex, be_Rect* src, be_Rect* dest); 256 257/********************* 258 * Timer 259 *********************/ 260BITE_API void bite_sleep(be_u64 ms); 261BITE_API be_u64 bite_tick(void); 262 263BITE_API void bite_timer_sleep(be_u64 ms); 264BITE_API be_u64 bite_timer_tick(void); 265 266#if defined(__cplusplus) 267} 268#endif 269 270#endif /* _BIT_ENGINE_ */