src/window.c

changeset 29
1d001eb694dc
parent 16
c5dde81b6fb2
child 34
45d29d7221cc
--- a/src/window.c	Sun Jan 21 14:01:27 2024 +0100
+++ b/src/window.c	Tue Jan 23 21:34:12 2024 +0100
@@ -61,6 +61,10 @@
     settings->title = "Ascended Window";
 }
 
+static void asc_window_init_scenes(AscWindow *window) {
+    asc_scene_init(&window->ui);
+}
+
 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) {
     if (index >= ASC_MAX_WINDOWS) {
         asc_error("Maximum number of windows exceeded.");
@@ -123,6 +127,7 @@
 
             asc_dprintf("Window %u initialized", window->id);
             if (asc_primitives_init(&window->primitives)) {
+                asc_window_init_scenes(window);
                 asc_context.active_window = window;
                 return window;
             } else {
@@ -152,6 +157,9 @@
         asc_context.active_window = NULL;
     }
 
+    // destroy all scenes
+    asc_scene_destroy(&window->ui);
+
     // release context related data (we have to make the GL context current for this)
     SDL_GL_MakeCurrent(window->window, window->glctx);
     asc_primitives_destroy(&window->primitives);
@@ -180,10 +188,18 @@
     if (window != active_window) {
         asc_window_activate(window);
     }
-    SDL_GL_SwapWindow(window->window);
+
+    // Clear viewport for new frame
     glViewport(0, 0, window->dimensions.width, window->dimensions.height);
     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+    // Draw the UI
+    asc_scene_draw(&window->ui);
+
+    // Swap Buffers
+    SDL_GL_SwapWindow(window->window);
+
     if (window != active_window) {
         asc_window_activate(active_window);
     }

mercurial