Tue, 28 Oct 2025 22:03:06 +0100
fix that dependencies for tools are always checked
| 0 | 1 | /* | 
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * Copyright 2023 Mike Becker. All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions are met: | |
| 7 | * | |
| 8 | * 1. Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * | |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 | * notice, this list of conditions and the following disclaimer in the | |
| 13 | * documentation and/or other materials provided with the distribution. | |
| 14 | * | |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 25 | * POSSIBILITY OF SUCH DAMAGE. | |
| 26 | */ | |
| 27 | ||
| 106 
895f92cff6b8
bring back error.h to reduce compile dependencies
 Mike Becker <universe@uap-core.de> parents: 
105diff
changeset | 28 | #include "ascension/error.h" | 
| 6 
302971e8599b
move window related stuff to its own unit
 Mike Becker <universe@uap-core.de> parents: 
3diff
changeset | 29 | #include "ascension/window.h" | 
| 7 | 30 | #include "ascension/context.h" | 
| 0 | 31 | |
| 253 | 32 | #include <GL/glew.h> | 
| 33 | ||
| 231 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 34 | #include <assert.h> | 
| 253 | 35 | #include <stdio.h> | 
| 6 
302971e8599b
move window related stuff to its own unit
 Mike Becker <universe@uap-core.de> parents: 
3diff
changeset | 36 | |
| 257 
67d7b79997df
remove AscWindowSettings struct
 Mike Becker <universe@uap-core.de> parents: 
253diff
changeset | 37 | void asc_window_initialize(unsigned int index, AscGLContextSettings settings) { | 
| 7 | 38 | if (index >= ASC_MAX_WINDOWS) { | 
| 92 | 39 | asc_error("Maximum number of windows exceeded (%u/%u).", index, ASC_MAX_WINDOWS); | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 40 | return; | 
| 7 | 41 | } | 
| 42 | AscWindow *window = &asc_context.windows[index]; | |
| 43 | if (window->id > 0) { | |
| 92 | 44 | asc_error("Cannot create window - slot %u already occupied.", index); | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 45 | return; | 
| 7 | 46 | } | 
| 47 | ||
| 253 | 48 | SDL_WindowFlags flags = SDL_WINDOW_OPENGL; | 
| 257 
67d7b79997df
remove AscWindowSettings struct
 Mike Becker <universe@uap-core.de> parents: 
253diff
changeset | 49 | flags |= settings.fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; | 
| 
67d7b79997df
remove AscWindowSettings struct
 Mike Becker <universe@uap-core.de> parents: 
253diff
changeset | 50 | window->window = SDL_CreateWindow("Ascension",800, 600, flags); | 
| 0 | 51 | if (window->window == NULL) { | 
| 92 | 52 | asc_error("Creating Window failed: %s", SDL_GetError()); | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 53 | return; | 
| 0 | 54 | } | 
| 55 | ||
| 56 | window->id = SDL_GetWindowID(window->window); | |
| 105 | 57 | { | 
| 58 | Sint32 w, h; | |
| 59 | SDL_GetWindowSize(window->window, &w, &h); | |
| 175 
e5544920377e
improve macros in datatypes.h - fixes #692
 Mike Becker <universe@uap-core.de> parents: 
155diff
changeset | 60 | window->dimensions = ASC_VEC2U(w, h); | 
| 105 | 61 | } | 
| 37 
8a8cc6725b48
add camera and render groups
 Mike Becker <universe@uap-core.de> parents: 
34diff
changeset | 62 | window->resized = true; // count initial sizing as resize | 
| 0 | 63 | |
| 154 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 64 | // default UI scale | 
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 65 | window->ui_scale = 1.0f; | 
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 66 | |
| 257 
67d7b79997df
remove AscWindowSettings struct
 Mike Becker <universe@uap-core.de> parents: 
253diff
changeset | 67 | if (asc_gl_context_initialize(&window->glctx, window->window, &settings)) { | 
| 220 
6b266e907f89
resolve several minor TODOs
 Mike Becker <universe@uap-core.de> parents: 
213diff
changeset | 68 | char ui_scene_name[16]; | 
| 
6b266e907f89
resolve several minor TODOs
 Mike Becker <universe@uap-core.de> parents: 
213diff
changeset | 69 | snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); | 
| 
6b266e907f89
resolve several minor TODOs
 Mike Becker <universe@uap-core.de> parents: 
213diff
changeset | 70 | asc_scene_init(&window->ui, ui_scene_name, | 
| 100 
5231da78831e
change asc_scene_init() to also request parameters for camera initialization
 Mike Becker <universe@uap-core.de> parents: 
99diff
changeset | 71 | .type = ASC_CAMERA_ORTHO, | 
| 186 
e9bb4d4f88a8
rename asc_recti to just asc_rect (there won't be an asc_rectu)
 Mike Becker <universe@uap-core.de> parents: 
175diff
changeset | 72 | .ortho.rect = ASC_RECT(0, 0, window->dimensions.width, window->dimensions.height), | 
| 101 | 73 | .projection_update_func = asc_camera_ortho_update_size | 
| 121 
ede9a9e92ff9
add viewport_clear flag to camera settings
 Mike Becker <universe@uap-core.de> parents: 
112diff
changeset | 74 | ); | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 75 | asc_dprintf("Window %u initialized at index %u", window->id, index); | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 76 | asc_context.active_window = index; | 
| 0 | 77 | } else { | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 78 | asc_error("Creating GL context failed for window %u at index %u", window->id, index); | 
| 44 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 79 | // cleanup on error | 
| 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 80 | SDL_DestroyWindow(window->window); | 
| 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 81 | window->window = NULL; | 
| 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 82 | window->id = 0; | 
| 0 | 83 | } | 
| 84 | } | |
| 85 | ||
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 86 | void asc_window_destroy(unsigned int index) { | 
| 7 | 87 | // safeguard | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 88 | if (asc_context.windows[index].id == 0) return; | 
| 7 | 89 | |
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 90 | // this window cannot be active anymore | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 91 | if (asc_context.active_window == index) { | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 92 | asc_context.active_window = ASC_MAX_WINDOWS; | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 93 | } | 
| 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 94 | |
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 95 | // pointer to the window | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 96 | AscWindow *window = &asc_context.windows[index]; | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 97 | |
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 98 | // for releasing OpenGL resources, we need to make the context current | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 99 | asc_gl_context_activate(&window->glctx); | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 100 | |
| 29 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 101 | // destroy all scenes | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 102 | for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 103 | asc_scene_destroy(&window->scenes[i]); | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 104 | } | 
| 95 
622887f7e954
in preparation of more scenes, bring back AscScene struct
 Mike Becker <universe@uap-core.de> parents: 
92diff
changeset | 105 | asc_scene_destroy(&window->ui); | 
| 29 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 106 | |
| 44 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 107 | // release context related data | 
| 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 108 | asc_gl_context_destroy(&window->glctx); | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 109 | |
| 44 
b3da4096c607
create own compilation unit for GL context - fixes shader not being created per context
 Mike Becker <universe@uap-core.de> parents: 
41diff
changeset | 110 | // destroy window | 
| 0 | 111 | if (window->window != NULL) { | 
| 112 | SDL_DestroyWindow(window->window); | |
| 113 | } | |
| 114 | ||
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 115 | // if another window was active, make the other context current again | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 116 | if (asc_context.active_window < ASC_MAX_WINDOWS) { | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 117 | asc_gl_context_activate(&asc_active_window->glctx); | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 118 | } | 
| 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 119 | |
| 0 | 120 | // clean the data | 
| 121 | asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); | |
| 122 | memset(window, 0, sizeof(AscWindow)); | |
| 123 | } | |
| 124 | ||
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 125 | void asc_window_sync(unsigned int index) { | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 126 | if (index > ASC_MAX_WINDOWS) { | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 127 | asc_error("Index for syncing window out of bounds (%u/%u).", index, ASC_MAX_WINDOWS); | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 128 | return; | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 129 | } | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 130 | AscWindow *window = &asc_context.windows[index]; | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 131 | // necessary safeguard | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 132 | if (window->id == 0) return; | 
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 133 | |
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 134 | // active the window that shall be synced temporarily | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 135 | unsigned int active_index = asc_context.active_window; | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 136 | if (index != active_index) { | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 137 | asc_window_activate(index); | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 138 | } | 
| 29 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 139 | |
| 47 
44457f6cb0a2
remove unnecessary scene container
 Mike Becker <universe@uap-core.de> parents: 
44diff
changeset | 140 | // Clear the color buffer for the window frame | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 141 | int window_width = window->dimensions.width; | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 142 | int window_height = window->dimensions.height; | 
| 47 
44457f6cb0a2
remove unnecessary scene container
 Mike Becker <universe@uap-core.de> parents: 
44diff
changeset | 143 | glViewport(0, 0, window_width, window_height); | 
| 
44457f6cb0a2
remove unnecessary scene container
 Mike Becker <universe@uap-core.de> parents: 
44diff
changeset | 144 | glClear(GL_COLOR_BUFFER_BIT); | 
| 
44457f6cb0a2
remove unnecessary scene container
 Mike Becker <universe@uap-core.de> parents: 
44diff
changeset | 145 | |
| 262 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 146 | // Update the viewports when the window resized | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 147 | if (window->resized) { | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 148 | for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 149 | if (asc_scene_active(&window->scenes[i])) { | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 150 | asc_camera_update_viewport(&window->scenes[i].camera, window->dimensions); | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 151 | } | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 152 | } | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 153 | asc_camera_update_viewport(&window->ui.camera, window->dimensions); | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 154 | } | 
| 
b47de42f4598
update viewports of cameras before executing behaviors, so that the new viewport information is available in the behavior functions
 Mike Becker <universe@uap-core.de> parents: 
257diff
changeset | 155 | |
| 112 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 156 | // Execute all behaviors | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 157 | // TODO: this can eventually be parallelized | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 158 | for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 159 | asc_scene_execute_behaviors(&window->scenes[i]); | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 160 | } | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 161 | asc_scene_execute_behaviors(&window->ui); | 
| 
3e956c96dd6c
extract execution of behaviors from draw function
 Mike Becker <universe@uap-core.de> parents: 
106diff
changeset | 162 | |
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 163 | // Draw all scenes | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 164 | for (unsigned int i = 0; i < ASC_MAX_SCENES; i++) { | 
| 99 
ac143db979dc
add aspect-ration independent rendering
 Mike Becker <universe@uap-core.de> parents: 
96diff
changeset | 165 | asc_scene_draw(&window->scenes[i]); | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 166 | } | 
| 99 
ac143db979dc
add aspect-ration independent rendering
 Mike Becker <universe@uap-core.de> parents: 
96diff
changeset | 167 | asc_scene_draw(&window->ui); | 
| 29 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 168 | |
| 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 169 | // Swap Buffers | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 170 | SDL_GL_SwapWindow(window->window); | 
| 29 
1d001eb694dc
bring first scene graph to live
 Mike Becker <universe@uap-core.de> parents: 
16diff
changeset | 171 | |
| 37 
8a8cc6725b48
add camera and render groups
 Mike Becker <universe@uap-core.de> parents: 
34diff
changeset | 172 | // Clear Flags | 
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 173 | window->resized = false; | 
| 37 
8a8cc6725b48
add camera and render groups
 Mike Becker <universe@uap-core.de> parents: 
34diff
changeset | 174 | |
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 175 | if (index != active_index) { | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 176 | asc_window_activate(active_index); | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 177 | } | 
| 0 | 178 | } | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 179 | |
| 65 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 180 | void asc_window_activate(unsigned int index) { | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 181 | asc_context.active_window = index; | 
| 
9c44c55d327a
consistently refer to windows by ID - fixes #381
 Mike Becker <universe@uap-core.de> parents: 
64diff
changeset | 182 | asc_gl_context_activate(&asc_active_window->glctx); | 
| 16 
c5dde81b6fb2
add text rendering and demo FPS counter
 Mike Becker <universe@uap-core.de> parents: 
13diff
changeset | 183 | } | 
| 68 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 184 | |
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 185 | unsigned int asc_window_index(Uint32 id) { | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 186 | unsigned int i = 0; | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 187 | for (; i < ASC_MAX_WINDOWS ; i++) { | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 188 | if (asc_context.windows[i].id == id) break; | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 189 | } | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 190 | return i; | 
| 
823c03733e42
add mouse and window focus - resolves #382
 Mike Becker <universe@uap-core.de> parents: 
65diff
changeset | 191 | } | 
| 95 
622887f7e954
in preparation of more scenes, bring back AscScene struct
 Mike Becker <universe@uap-core.de> parents: 
92diff
changeset | 192 | |
| 96 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 193 | AscScene *asc_window_scene(unsigned int index) { | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 194 | return &asc_active_window->scenes[index]; | 
| 
9e25f080a33e
add scenes, but they don't draw yet
 Mike Becker <universe@uap-core.de> parents: 
95diff
changeset | 195 | } | 
| 154 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 196 | |
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 197 | asc_vec2u asc_window_display_resolution(void) { | 
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 198 | const AscWindow *window = asc_active_window; | 
| 253 | 199 | SDL_DisplayID display = SDL_GetDisplayForWindow(window->window); | 
| 200 | const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(display); | |
| 201 | if (dm == NULL) { | |
| 154 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 202 | asc_error("Failed to get display mode for window %u on display %d: %s", | 
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 203 | window->id, display, SDL_GetError()); | 
| 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 204 | } | 
| 253 | 205 | return ASC_VEC2U(dm->w, dm->h); | 
| 154 
4dff9cc488fe
add auto-scaling of UI depending on screen resolution - resolves #682
 Mike Becker <universe@uap-core.de> parents: 
149diff
changeset | 206 | } | 
| 231 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 207 | |
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 208 | float asc_window_ui_scale(unsigned int index) { | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 209 | assert(asc_context.windows[index].window != NULL); | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 210 | return asc_context.windows[index].ui_scale; | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 211 | } | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 212 | |
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 213 | void asc_window_set_title(unsigned index, const char *title) { | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 214 | assert(asc_context.windows[index].window != NULL); | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 215 | SDL_SetWindowTitle(asc_context.windows[index].window, title); | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 216 | } | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 217 | |
| 237 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 218 | void asc_window_set_position(unsigned index, asc_vec2i pos) { | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 219 | assert(asc_context.windows[index].window != NULL); | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 220 | SDL_SetWindowPosition(asc_context.windows[index].window, pos.x, pos.y); | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 221 | } | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 222 | |
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 223 | void asc_window_center(unsigned index) { | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 224 | // TODO: add support for multiple displays | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 225 | // TODO: add support for centering just one axis | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 226 | assert(asc_context.windows[index].window != NULL); | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 227 | SDL_SetWindowPosition(asc_context.windows[index].window, | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 228 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 229 | } | 
| 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 230 | |
| 231 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 231 | void asc_window_set_size(unsigned index, asc_vec2u size) { | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 232 | assert(asc_context.windows[index].window != NULL); | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 233 | asc_context.windows[index].dimensions = size; | 
| 237 
2ea35c5f4760
add functions to change the window position
 Mike Becker <universe@uap-core.de> parents: 
231diff
changeset | 234 | // TODO: check what needs to be changed when SDL_WINDOW_ALLOW_HIGHDPI is supported by the engine | 
| 231 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 235 | SDL_SetWindowSize(asc_context.windows[index].window, (int)size.width, (int)size.height); | 
| 
0da563c4e39c
make initial window size depend on UI scaling factor
 Mike Becker <universe@uap-core.de> parents: 
220diff
changeset | 236 | } |