// Copyright (c) 2021 Dominic Msters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "glwfwplatform.h" GLFWwindow *window; game_t *runningGame; int32_t main() { // Create out platform context platform_t platform = { .name = "glfw", .screenWidth = WINDOW_WIDTH_DEFAULT, .screenHeight = WINDOW_HEIGHT_DEFAULT }; // Attempt to init GLFW if(!glfwInit()) return NULL; window = glfwCreateWindow(platform.screenWidth, platform.screenHeight, "", NULL, NULL ); if(!window) { glfwTerminate(); return 1; } // Load GLAD glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); // Setup window listeners glfwSetWindowSizeCallback(window, &glfwOnResize); glfwSetKeyCallback(window, &glfwOnKey); // Create the game instance runningGame = gameInit(&platform); if(runningGame == NULL) return 1; // Main Render Loop while(!glfwWindowShouldClose(window)) { gameUpdate(runningGame); glfwSwapBuffers(window); glfwPollEvents(); } // Game has finished running, cleanup. gameDispose(runningGame); // Terminate the GLFW context. glfwSetWindowSizeCallback(window, NULL); glfwTerminate(); return 0; } void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height) { engine_t *engine = gameGetEngine(runningGame); engine->platform->screenWidth = width; engine->platform->screenWidth = height; renderSetResolution(engine->render, width, height); } void glfwOnKey(GLFWwindow *window, int32_t key, int32_t scancode, int32_t action, int32_t mods ) { char *title = glfwGetKeyName(key, scancode); if(title == NULL) { printf("Unknown Key %d", scancode); } else { printf(title); } printf("\n"); }