bit engine
1#include "bite.h"
2
3#if defined(__EMSCRIPTEN__)
4 #include <emscripten.h>
5#endif
6
7const char* vert =
8#if defined(__EMSCRIPTEN__)
9"#version 100\n"
10"attribute vec2 a_Position;\n"
11"attribute vec4 a_Color;\n"
12"varying vec4 v_Color;\n"
13#else
14"#version 140\n"
15"in vec2 a_Position;\n"
16"in vec4 a_Color;\n"
17"out vec4 v_Color;\n"
18#endif
19"void main() {\n"
20" gl_Position = vec4(a_Position.x, a_Position.y, 0, 1.0);\n"
21" v_Color = a_Color;\n"
22"}";
23
24const char* frag =
25#if defined(__EMSCRIPTEN__)
26"#version 100\n"
27"precision mediump float;\n"
28"varying vec4 v_Color;\n"
29"#define o_FragColor gl_FragColor\n"
30#else
31"#version 140\n"
32"in vec4 v_Color;\n"
33"out vec4 o_FragColor;\n"
34#endif
35"void main() {"
36" o_FragColor = v_Color;\n"
37"}";
38
39// #include <GL/gl.h>
40be_Texture* tex;
41be_Shader* shader;
42
43void key_pressed(be_Context* ctx, be_Event* ev) {
44 printf("Pressed: %d\n", ev->key.keycode);
45 if (ev->key.keycode == BITEK_ESCAPE) bite_set_should_close(ctx, 1);
46}
47
48void quit_callback(be_Context* ctx, be_Event* ev) {
49 bite_set_should_close(ctx, 1);
50}
51
52void main_loop(void* data) {
53 // printf("Entering render function\n");
54 be_Context* ctx = (be_Context*)data;
55 bite_poll_events(ctx);
56 bite_use_shader(shader);
57 bite_simple_triangle(ctx);
58 bite_use_shader(NULL);
59 bite_swap(ctx);
60}
61
62int main(int argc, char** argv) {
63 be_Config c = bite_init_config("bitEngine", 640, 380);
64 be_Context* ctx = bite_create(&c);
65 be_u8 pixels[] = {255, 255, 255, 255};
66 tex = bite_create_texture(1, 1, 0, pixels);
67 shader = bite_create_shader(vert, frag);
68#if defined(__EMSCRIPTEN__)
69 emscripten_set_main_loop_arg(main_loop, ctx, 0, 1);
70#else
71 bite_register_callback(ctx, BITE_WINDOW_CLOSE, quit_callback);
72 bite_register_callback(ctx, BITE_KEY_PRESSED, key_pressed);
73 while (!bite_should_close(ctx)) main_loop(ctx);
74#endif
75 bite_destroy(ctx);
76 return 0;
77}