1.1 --- a/src/window.c Fri Mar 29 00:03:25 2024 +0100 1.2 +++ b/src/window.c Mon Apr 01 18:54:19 2024 +0200 1.3 @@ -43,13 +43,6 @@ 1.4 settings->title = "Ascended Window"; 1.5 } 1.6 1.7 -static void asc_window_init_scenes(AscWindow *window) { 1.8 - asc_scene_init(&window->ui); 1.9 - asc_camera_ortho(&window->ui.cameras[0], (asc_recti){ 1.10 - 0, 0, window->dimensions 1.11 - }); 1.12 -} 1.13 - 1.14 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { 1.15 if (index >= ASC_MAX_WINDOWS) { 1.16 asc_error("Maximum number of windows exceeded."); 1.17 @@ -58,9 +51,13 @@ 1.18 AscWindow *window = &asc_context.windows[index]; 1.19 if (window->id > 0) { 1.20 asc_error("Cannot create window - slot already occupied."); 1.21 - asc_dprintf("Tried to create window with index %u", index); 1.22 + asc_dprintf("Tried to create window with index %u twice", index); 1.23 return NULL; 1.24 } 1.25 + if (window->ui != NULL) { 1.26 + asc_dprintf("Window with index %u has a dangling UI pointer", index); 1.27 + asc_scene_node_free(window->ui); 1.28 + } 1.29 1.30 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; 1.31 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; 1.32 @@ -86,9 +83,9 @@ 1.33 window->resized = true; // count initial sizing as resize 1.34 1.35 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { 1.36 + window->ui = asc_scene_node_empty(); 1.37 asc_dprintf("Window %u initialized", window->id); 1.38 asc_context.active_window = window; 1.39 - asc_window_init_scenes(window); 1.40 return window; 1.41 } else { 1.42 asc_dprintf("Creating GL context failed for window %u", window->id); 1.43 @@ -110,7 +107,8 @@ 1.44 } 1.45 1.46 // destroy all scenes 1.47 - asc_scene_destroy(&window->ui); 1.48 + asc_scene_node_free(window->ui); 1.49 + window->ui = NULL; 1.50 1.51 // release context related data 1.52 asc_gl_context_destroy(&window->glctx); 1.53 @@ -136,8 +134,17 @@ 1.54 asc_window_activate(window); 1.55 } 1.56 1.57 + // Clear the color buffer for the window frame 1.58 + int window_width = window->dimensions.width; 1.59 + int window_height = window->dimensions.height; 1.60 + glViewport(0, 0, window_width, window_height); 1.61 + glClear(GL_COLOR_BUFFER_BIT); 1.62 + asc_recti viewport = {0, 0, window_width, window_height}; 1.63 + 1.64 // Draw the UI 1.65 - asc_scene_draw(&window->ui); 1.66 + AscCamera ui_camera; 1.67 + asc_camera_ortho(&ui_camera, viewport); 1.68 + asc_scene_draw(window->ui, viewport, &ui_camera); 1.69 1.70 // Swap Buffers 1.71 SDL_GL_SwapWindow(window->window);