From 118980e02e59ff31871df59dce257075394f3533 Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Sun, 25 Jan 2026 15:10:37 -0600 Subject: wip --- src/window.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/window.c (limited to 'src/window.c') diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..e3faff7 --- /dev/null +++ b/src/window.c @@ -0,0 +1,41 @@ +#include "window.h" +#include "glad/glad.h" +#include + +int window_init(struct window* window) { + SDL_Init(SDL_INIT_VIDEO); + // This will call SDL_GL_LoadLibrary so you don't need glad to do anything + window->window = SDL_CreateWindow("Junkcraft", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL); + + SDL_GLContext* ctx = SDL_GL_CreateContext(window->window); + // Let GLAD use the SDL GetProcAddress loader instead of using its own + int version = gladLoadGLLoader(SDL_GL_GetProcAddress); + if (version == 0) { + printf("Failed to initialize OpenGL context\n"); + return -1; + } + printf("Loaded OpenGL %s\n", glGetString(GL_VERSION)); + printf("System: %s\n", glGetString(GL_RENDERER)); + + + if (window == NULL) { + perror("Failed to create window!"); + SDL_DestroyWindow(window->window); + SDL_Quit(); + return -1; + } + + window->renderer = SDL_CreateRenderer(window->window, -1, SDL_RENDERER_ACCELERATED); + if (window->renderer == NULL) { + perror("Failed to create renderer!"); + SDL_DestroyWindow(window->window); + SDL_Quit(); + return -1; + } + SDL_ShowWindow(window->window); + return 0; +} +void window_cleanup(struct window* window) { + SDL_DestroyWindow(window->window); + SDL_Quit(); +} -- cgit