aboutsummaryrefslogtreecommitdiffstats
path: root/src/app.c
blob: 99f5cff908da05a3affeb1f9e0d782f2a106e6b5 (plain)
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
#include "app.h"
#include "platform.h"

static inline bool
app_init(AppState *state, PlatformAPI platform) {
    platform.log("INIT");

    // Initialize GLFW.
    if (!glfwInit()) {
        platform.log("ERROR: failed to initialize GLFW");
        return false;
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // // Initialize window.
    GLFWwindow* window = glfwCreateWindow(400, 300, "Hello MIC", NULL, NULL);
    if (window == NULL) {
        platform.log("ERROR: failed to create GLFW window");
        glfwTerminate();
        return false;
    }
    glfwMakeContextCurrent(window);

    // Initialize GLEW.
    if(glewInit() != GLEW_OK) {
        platform.log("ERROR: glew initialization");
        glfwTerminate();
        return false;
    }

    // Initialize viewport.
    glViewport(0, 0, 400, 300);

    // Initialize application state.
    state->window = window;
    return true;
}

static inline void
app_destroy(AppState *state, PlatformAPI platform) {
    (void)state; // Unused parameter.
    platform.log("DESTROY");
}

static inline void
app_reload(AppState *state, PlatformAPI platform) {
    (void)state; // Unused parameter.
    platform.log("RELOAD");
}

static inline void
app_unload(AppState *state, PlatformAPI platform) {
    (void)state; // Unused parameter.
    platform.log("UNLOAD");
}

static inline bool
app_step(AppState *state, PlatformAPI platform) {
    (void)platform; // Unused parameter.
    if (glfwWindowShouldClose(state->window)) {
        return false;
    }

    glClearColor(1.0f, 0.0f, 0.4f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glfwSwapBuffers(state->window);
    glfwPollEvents();

    return true;
}

const AppAPI APP_API = {
    .init = app_init,
    .destroy = app_destroy,
    .reload = app_reload,
    .step = app_step,
    .unload = app_unload,
};