From f0ab423e367c0cd640c4cc036c2eb2d07e64b49a Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 14 Apr 2025 18:48:27 +0200 Subject: [PATCH] add OpenGL bootstrapping code --- src/io/window.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/io/window.c b/src/io/window.c index 011cd5b..830c669 100644 --- a/src/io/window.c +++ b/src/io/window.c @@ -2,9 +2,15 @@ // Licensed under the MIT Licence. See LICENSE for details #include "window.h" +// include before GLFW +#define GLAD_GL_IMPLEMENTATION +#include + +// include system libraries #include #include #include + #include "input.h" // macros for ease of access @@ -19,18 +25,19 @@ int window_init(void) { glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // TODO: read about opengl profiles + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL); if (!win) return 1; - // make the current window the current context - glfwMakeContextCurrent(win); - // configure callbacks glfwSetKeyCallback(win, key_callback); glfwSwapInterval(1); // wait 1 screen update for a redraw a.k.a. "vsync". (not really applicable in this case but eh) + // setup OpenGL + glfwMakeContextCurrent(win); + if (!gladLoadGL(glfwGetProcAddress)) return 1; + return 0; } @@ -39,6 +46,9 @@ void window_loop(void) { while (!glfwWindowShouldClose(win)) { glfwWaitEvents(); // wait till an update has been given + glClearColor(0.1F, 0.1F, 0.1F, 1.0F); + glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(win); } glfwDestroyWindow(win);