diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 47 |
1 files changed, 42 insertions, 5 deletions
@@ -4,8 +4,37 @@ | |||
4 | static inline bool | 4 | static inline bool |
5 | app_init(AppState *state, PlatformAPI platform) { | 5 | app_init(AppState *state, PlatformAPI platform) { |
6 | platform.log("INIT"); | 6 | platform.log("INIT"); |
7 | state->lt_memory = platform.calloc(LT_MEMORY_SIZE, sizeof(u8)); | 7 | |
8 | state->st_memory = platform.calloc(ST_MEMORY_SIZE, sizeof(u8)); | 8 | // Initialize GLFW. |
9 | if (!glfwInit()) { | ||
10 | platform.log("ERROR: failed to initialize GLFW"); | ||
11 | return false; | ||
12 | } | ||
13 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
14 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | ||
15 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | ||
16 | |||
17 | // // Initialize window. | ||
18 | GLFWwindow* window = glfwCreateWindow(400, 300, "Hello MIC", NULL, NULL); | ||
19 | if (window == NULL) { | ||
20 | platform.log("ERROR: failed to create GLFW window"); | ||
21 | glfwTerminate(); | ||
22 | return false; | ||
23 | } | ||
24 | glfwMakeContextCurrent(window); | ||
25 | |||
26 | // Initialize GLEW. | ||
27 | if(glewInit() != GLEW_OK) { | ||
28 | platform.log("ERROR: glew initialization"); | ||
29 | glfwTerminate(); | ||
30 | return false; | ||
31 | } | ||
32 | |||
33 | // Initialize viewport. | ||
34 | glViewport(0, 0, 400, 300); | ||
35 | |||
36 | // Initialize application state. | ||
37 | state->window = window; | ||
9 | return true; | 38 | return true; |
10 | } | 39 | } |
11 | 40 | ||
@@ -29,9 +58,17 @@ app_unload(AppState *state, PlatformAPI platform) { | |||
29 | 58 | ||
30 | static inline bool | 59 | static inline bool |
31 | app_step(AppState *state, PlatformAPI platform) { | 60 | app_step(AppState *state, PlatformAPI platform) { |
32 | (void)state; // Unused parameter. | 61 | (void)platform; // Unused parameter. |
33 | platform.log("STEP"); | 62 | if (glfwWindowShouldClose(state->window)) { |
34 | platform.sleep(100000); | 63 | return false; |
64 | } | ||
65 | |||
66 | glClearColor(1.0f, 0.0f, 0.4f, 1.0f); | ||
67 | glClear(GL_COLOR_BUFFER_BIT); | ||
68 | |||
69 | glfwSwapBuffers(state->window); | ||
70 | glfwPollEvents(); | ||
71 | |||
35 | return true; | 72 | return true; |
36 | } | 73 | } |
37 | 74 | ||