From 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Fri, 16 Jan 2026 23:02:32 +0100 Subject: Initial commit --- 08-august/src/graphics/window.c | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 08-august/src/graphics/window.c (limited to '08-august/src/graphics/window.c') diff --git a/08-august/src/graphics/window.c b/08-august/src/graphics/window.c new file mode 100644 index 0000000..1a942ca --- /dev/null +++ b/08-august/src/graphics/window.c @@ -0,0 +1,44 @@ +#include "window.h" +#include "../util/util.h" +#include + +window_t* Window_Create(const char* title, Uint32 width, Uint32 height) +{ + window_t* window = (window_t*) malloc(sizeof(window_t)); + window->title = title; + window->Width = width; + window->Height = height; + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + 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_t* 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_t* window) +{ + SDL_GL_SwapWindow(window->window); +} + +void Window_Destroy(window_t* window) +{ + SDL_GL_DeleteContext(window->context); + SDL_DestroyWindow(window->window); + free(window); +} -- cgit v1.2.3