--- a/src/window.c Fri Mar 29 00:03:25 2024 +0100 +++ b/src/window.c Mon Apr 01 18:54:19 2024 +0200 @@ -43,13 +43,6 @@ settings->title = "Ascended Window"; } -static void asc_window_init_scenes(AscWindow *window) { - asc_scene_init(&window->ui); - asc_camera_ortho(&window->ui.cameras[0], (asc_recti){ - 0, 0, window->dimensions - }); -} - AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { if (index >= ASC_MAX_WINDOWS) { asc_error("Maximum number of windows exceeded."); @@ -58,9 +51,13 @@ AscWindow *window = &asc_context.windows[index]; if (window->id > 0) { asc_error("Cannot create window - slot already occupied."); - asc_dprintf("Tried to create window with index %u", index); + asc_dprintf("Tried to create window with index %u twice", index); return NULL; } + if (window->ui != NULL) { + asc_dprintf("Window with index %u has a dangling UI pointer", index); + asc_scene_node_free(window->ui); + } Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; @@ -86,9 +83,9 @@ window->resized = true; // count initial sizing as resize if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { + window->ui = asc_scene_node_empty(); asc_dprintf("Window %u initialized", window->id); asc_context.active_window = window; - asc_window_init_scenes(window); return window; } else { asc_dprintf("Creating GL context failed for window %u", window->id); @@ -110,7 +107,8 @@ } // destroy all scenes - asc_scene_destroy(&window->ui); + asc_scene_node_free(window->ui); + window->ui = NULL; // release context related data asc_gl_context_destroy(&window->glctx); @@ -136,8 +134,17 @@ asc_window_activate(window); } + // Clear the color buffer for the window frame + int window_width = window->dimensions.width; + int window_height = window->dimensions.height; + glViewport(0, 0, window_width, window_height); + glClear(GL_COLOR_BUFFER_BIT); + asc_recti viewport = {0, 0, window_width, window_height}; + // Draw the UI - asc_scene_draw(&window->ui); + AscCamera ui_camera; + asc_camera_ortho(&ui_camera, viewport); + asc_scene_draw(window->ui, viewport, &ui_camera); // Swap Buffers SDL_GL_SwapWindow(window->window);