#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, };