# HG changeset patch # User Mike Becker # Date 1754599241 -7200 # Node ID 67d7b79997df6730c7a14791e2ee6ab9d09c666c # Parent 60014484121c98de2529deca1445e405cf449db9 remove AscWindowSettings struct diff -r 60014484121c -r 67d7b79997df src/ascension/glcontext.h --- a/src/ascension/glcontext.h Wed Aug 06 00:37:01 2025 +0200 +++ b/src/ascension/glcontext.h Thu Aug 07 22:40:41 2025 +0200 @@ -35,8 +35,9 @@ typedef struct asc_gl_context_settings_s { int gl_major_version; int gl_minor_version; - int vsync; int depth_size; + bool vsync; + bool fullscreen; } AscGLContextSettings; typedef struct asc_gl_context_s { @@ -56,6 +57,8 @@ #define asc_active_glctx (&asc_active_window->glctx) +AscGLContextSettings asc_gl_context_settings_default(int gl_major_version, int gl_minor_version); + bool asc_gl_context_initialize( AscGLContext *ctx, SDL_Window *window, diff -r 60014484121c -r 67d7b79997df src/ascension/window.h --- a/src/ascension/window.h Wed Aug 06 00:37:01 2025 +0200 +++ b/src/ascension/window.h Thu Aug 07 22:40:41 2025 +0200 @@ -44,14 +44,6 @@ #define ASC_MAX_SCENES 8u #endif // ASC_MAX_SCENES -// TODO: remove AscWindowSettings (we can set most of the stuff after creation) -typedef struct asc_window_settings_s { - AscGLContextSettings glsettings; - asc_vec2u dimensions; - const char *title; - bool fullscreen; -} AscWindowSettings; - typedef struct asc_window_s { Uint32 id; bool resized; @@ -65,24 +57,17 @@ } AscWindow; /** - * Initializes the settings structure with default values. - * - * @param settings an uninitialized settings object - */ -void asc_window_settings_init_defaults(AscWindowSettings *settings); - -/** * Creates and initializes a new window and a corresponding OpenGL context. * * The new window will also be automatically activated (see asc_window_activate()). * - * The index specified must not be in use by another window already. + * The index specified must not be in use by another window yet. * The maximum number of windows is defined by #ASC_MAX_WINDOWS. * * @param index the index of the new window - * @param settings the settings to be used for initialization + * @param settings the OpenGL context settings to be used for initialization */ -void asc_window_initialize(unsigned int index, const AscWindowSettings *settings); +void asc_window_initialize(unsigned int index, AscGLContextSettings settings); /** * Destroys the window and its OpenGL context. @@ -198,5 +183,8 @@ */ void asc_window_set_size(unsigned int index, asc_vec2u size); + +// TODO: add functions to enable/disable fullscreen and vsync during runtime + #endif /* ASCENSION_WINDOW_H */ diff -r 60014484121c -r 67d7b79997df src/glcontext.c --- a/src/glcontext.c Wed Aug 06 00:37:01 2025 +0200 +++ b/src/glcontext.c Thu Aug 07 22:40:41 2025 +0200 @@ -74,6 +74,16 @@ } } +AscGLContextSettings asc_gl_context_settings_default(int gl_major_version, int gl_minor_version) { + return (AscGLContextSettings) { + .gl_major_version = gl_major_version, + .gl_minor_version = gl_minor_version, + .depth_size = 24, + .vsync = true, + .fullscreen = false, + }; +} + bool asc_gl_context_initialize( AscGLContext *ctx, SDL_Window *window, @@ -91,7 +101,7 @@ glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err == GLEW_OK) { - SDL_GL_SetSwapInterval(settings->vsync); + SDL_GL_SetSwapInterval(settings->vsync ? 1 : 0); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEBUG_OUTPUT); diff -r 60014484121c -r 67d7b79997df src/window.c --- a/src/window.c Wed Aug 06 00:37:01 2025 +0200 +++ b/src/window.c Thu Aug 07 22:40:41 2025 +0200 @@ -34,18 +34,7 @@ #include #include -void asc_window_settings_init_defaults(AscWindowSettings *settings) { - settings->dimensions.width = 800u; - settings->dimensions.height = 600u; - settings->fullscreen = false; - settings->glsettings.depth_size = 24; - settings->glsettings.vsync = 1; - settings->glsettings.gl_major_version = 4; - settings->glsettings.gl_minor_version = 0; - settings->title = "Ascended Window"; -} - -void asc_window_initialize(unsigned int index, const AscWindowSettings *settings) { +void asc_window_initialize(unsigned int index, AscGLContextSettings settings) { if (index >= ASC_MAX_WINDOWS) { asc_error("Maximum number of windows exceeded (%u/%u).", index, ASC_MAX_WINDOWS); return; @@ -57,14 +46,8 @@ } SDL_WindowFlags flags = SDL_WINDOW_OPENGL; - flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; - - window->window = SDL_CreateWindow( - settings->title, - (int) settings->dimensions.width, - (int) settings->dimensions.height, - flags - ); + flags |= settings.fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; + window->window = SDL_CreateWindow("Ascension",800, 600, flags); if (window->window == NULL) { asc_error("Creating Window failed: %s", SDL_GetError()); return; @@ -81,7 +64,7 @@ // default UI scale window->ui_scale = 1.0f; - if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { + if (asc_gl_context_initialize(&window->glctx, window->window, &settings)) { char ui_scene_name[16]; snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); asc_scene_init(&window->ui, ui_scene_name, diff -r 60014484121c -r 67d7b79997df test/snake/snake.c --- a/test/snake/snake.c Wed Aug 06 00:37:01 2025 +0200 +++ b/test/snake/snake.c Thu Aug 07 22:40:41 2025 +0200 @@ -427,9 +427,7 @@ globals_init(); // create the window - AscWindowSettings settings; - asc_window_settings_init_defaults(&settings); - asc_window_initialize(0, &settings); + asc_window_initialize(0, asc_gl_context_settings_default(4, 0)); asc_window_set_title(0, "Snake"); asc_window_set_size(0, asc_vec2_ftou( asc_vec2f_scale(ASC_VEC2F(1024+HUD_WIDTH, 1024), asc_ui_scale_auto())));