diff options
| author | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
|---|---|---|
| committer | Thomas Guillermo Albers Raviola <thomas@thomaslabs.org> | 2026-01-16 23:02:32 +0100 |
| commit | 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch) | |
| tree | 428986b49c32e21d3f7a3c2dfa41858ae0153209 /09-september/tomcat/renderer/window.c | |
Initial commit
Diffstat (limited to '09-september/tomcat/renderer/window.c')
| -rw-r--r-- | 09-september/tomcat/renderer/window.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/09-september/tomcat/renderer/window.c b/09-september/tomcat/renderer/window.c new file mode 100644 index 0000000..d5db1eb --- /dev/null +++ b/09-september/tomcat/renderer/window.c @@ -0,0 +1,49 @@ +#include "window.h" +#include "../util/util.h" +#include <stdlib.h> + +Window* window_new(const char* title, Uint32 width, Uint32 height) +{ + Window* window = malloc(sizeof(Window)); + window->title = title; + window->Width = width; + window->Height = height; + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + + window->window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width, height, SDL_WINDOW_OPENGL); + if(window->window == NULL) + Util_FatalError( "The window could not be created:\n%s", SDL_GetError() ); + + window->context = SDL_GL_CreateContext(window->window); + + if(window->context == NULL) + Util_FatalError( "Context could not be created:\n%s", SDL_GetError() ); + + glViewport(0, 0, width, height); + + return window; +} + +void window_resize(Window* window, Uint32 width, Uint32 height) +{ + window->Width = width; + window->Height = height; + SDL_SetWindowSize(window->window, width, height); + glViewport(0, 0, width, height); +} + +void window_update(Window* window) +{ + SDL_GL_SwapWindow(window->window); +} + +void window_destroy(Window* window) +{ + SDL_GL_DeleteContext(window->context); + SDL_DestroyWindow(window->window); + free(window); +} |
