57 settings->dimensions.height = 600; |
57 settings->dimensions.height = 600; |
58 settings->fullscreen = 0; |
58 settings->fullscreen = 0; |
59 settings->gl_major_version = 4; |
59 settings->gl_major_version = 4; |
60 settings->gl_minor_version = 0; |
60 settings->gl_minor_version = 0; |
61 settings->title = "Ascended Window"; |
61 settings->title = "Ascended Window"; |
|
62 } |
|
63 |
|
64 static void asc_window_init_scenes(AscWindow *window) { |
|
65 asc_scene_init(&window->ui); |
62 } |
66 } |
63 |
67 |
64 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { |
68 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { |
65 if (index >= ASC_MAX_WINDOWS) { |
69 if (index >= ASC_MAX_WINDOWS) { |
66 asc_error("Maximum number of windows exceeded."); |
70 asc_error("Maximum number of windows exceeded."); |
121 glEnable(GL_DEBUG_OUTPUT); |
125 glEnable(GL_DEBUG_OUTPUT); |
122 glDebugMessageCallback(asc_gl_debug_callback, NULL); |
126 glDebugMessageCallback(asc_gl_debug_callback, NULL); |
123 |
127 |
124 asc_dprintf("Window %u initialized", window->id); |
128 asc_dprintf("Window %u initialized", window->id); |
125 if (asc_primitives_init(&window->primitives)) { |
129 if (asc_primitives_init(&window->primitives)) { |
|
130 asc_window_init_scenes(window); |
126 asc_context.active_window = window; |
131 asc_context.active_window = window; |
127 return window; |
132 return window; |
128 } else { |
133 } else { |
129 asc_dprintf("!!! Creating primitives for window %u failed !!!", window->id); |
134 asc_dprintf("!!! Creating primitives for window %u failed !!!", window->id); |
130 } |
135 } |
150 // this window cannot be active anymore |
155 // this window cannot be active anymore |
151 if (asc_context.active_window == window) { |
156 if (asc_context.active_window == window) { |
152 asc_context.active_window = NULL; |
157 asc_context.active_window = NULL; |
153 } |
158 } |
154 |
159 |
|
160 // destroy all scenes |
|
161 asc_scene_destroy(&window->ui); |
|
162 |
155 // release context related data (we have to make the GL context current for this) |
163 // release context related data (we have to make the GL context current for this) |
156 SDL_GL_MakeCurrent(window->window, window->glctx); |
164 SDL_GL_MakeCurrent(window->window, window->glctx); |
157 asc_primitives_destroy(&window->primitives); |
165 asc_primitives_destroy(&window->primitives); |
158 |
166 |
159 // destroy the GL context and the window |
167 // destroy the GL context and the window |
178 void asc_window_sync(AscWindow const* window) { |
186 void asc_window_sync(AscWindow const* window) { |
179 AscWindow const *active_window = asc_context.active_window; |
187 AscWindow const *active_window = asc_context.active_window; |
180 if (window != active_window) { |
188 if (window != active_window) { |
181 asc_window_activate(window); |
189 asc_window_activate(window); |
182 } |
190 } |
183 SDL_GL_SwapWindow(window->window); |
191 |
|
192 // Clear viewport for new frame |
184 glViewport(0, 0, window->dimensions.width, window->dimensions.height); |
193 glViewport(0, 0, window->dimensions.width, window->dimensions.height); |
185 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
194 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
186 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
195 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
196 |
|
197 // Draw the UI |
|
198 asc_scene_draw(&window->ui); |
|
199 |
|
200 // Swap Buffers |
|
201 SDL_GL_SwapWindow(window->window); |
|
202 |
187 if (window != active_window) { |
203 if (window != active_window) { |
188 asc_window_activate(active_window); |
204 asc_window_activate(active_window); |
189 } |
205 } |
190 } |
206 } |
191 |
207 |