aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-01-26 08:45:23 +0100
committerBad Diode <bd@badd10de.dev>2021-01-26 10:33:56 +0100
commit71ab55ad22abd7ba8d6c41fa4c9ff5aa69db8284 (patch)
tree7da231ec95dfccbbb4ca1f895a308550339e9e1a
parente24186fc1917c5e8b91924af0c3c7c55816ff5d6 (diff)
downloadmic-opengl-example-71ab55ad22abd7ba8d6c41fa4c9ff5aa69db8284.tar.gz
mic-opengl-example-71ab55ad22abd7ba8d6c41fa4c9ff5aa69db8284.zip
Initialize OpenGL window
-rw-r--r--Makefile2
-rw-r--r--src/app.c47
-rw-r--r--src/app.h11
3 files changed, 48 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index b31e5c8..e7770ac 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ LIB_DIR := $(BUILD_DIR)
19# Compiler and linker configuration. 19# Compiler and linker configuration.
20CC := gcc 20CC := gcc
21CFLAGS := -Wall -Wextra -pedantic -std=c99 21CFLAGS := -Wall -Wextra -pedantic -std=c99
22LDFLAGS := 22LDFLAGS := -lGL -lGLEW -lglfw
23LDLIBS := 23LDLIBS :=
24RELEASE_CFLAGS := -DNDEBUG -O2 24RELEASE_CFLAGS := -DNDEBUG -O2
25DEBUG_CFLAGS := -DDEBUG -g 25DEBUG_CFLAGS := -DDEBUG -g
diff --git a/src/app.c b/src/app.c
index a39bff0..99f5cff 100644
--- a/src/app.c
+++ b/src/app.c
@@ -4,8 +4,37 @@
4static inline bool 4static inline bool
5app_init(AppState *state, PlatformAPI platform) { 5app_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
30static inline bool 59static inline bool
31app_step(AppState *state, PlatformAPI platform) { 60app_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
diff --git a/src/app.h b/src/app.h
index 8edbe58..613360f 100644
--- a/src/app.h
+++ b/src/app.h
@@ -1,16 +1,15 @@
1#ifndef MIC_APP_H 1#ifndef MIC_APP_H
2#define MIC_APP_H 2#define MIC_APP_H
3 3
4#include <GL/glew.h>
5#include <GLFW/glfw3.h>
6
4#include "shorthand.h" 7#include "shorthand.h"
5#include "platform.h" 8#include "platform.h"
6 9
7#define LT_MEMORY_SIZE GB(2)
8#define ST_MEMORY_SIZE MB(100)
9
10typedef struct AppState { 10typedef struct AppState {
11 // Long and short term memory. 11 // OpenGL
12 char *lt_memory; 12 GLFWwindow *window;
13 char *st_memory;
14} AppState; 13} AppState;
15 14
16// Function pointers for the AppAPI. 15// Function pointers for the AppAPI.