diff options
| author | Aaditya Dhruv <[email protected]> | 2026-01-25 15:10:37 -0600 |
|---|---|---|
| committer | Aaditya Dhruv <[email protected]> | 2026-01-25 15:10:37 -0600 |
| commit | 118980e02e59ff31871df59dce257075394f3533 (patch) | |
| tree | 26fba4492bb4b561d21bf49b35d892a821d54fab /src/window.c | |
| parent | 0e6e1245b70df4dfcba135d50e1b53d1a8ef7eb8 (diff) | |
wip
Diffstat (limited to 'src/window.c')
| -rw-r--r-- | src/window.c | 41 |
1 files changed, 41 insertions, 0 deletions
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 <stdio.h> + +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(); +} |
