src/window.c

changeset 37
8a8cc6725b48
parent 34
45d29d7221cc
child 39
7cf310cc47cb
equal deleted inserted replaced
36:e26b4ac1661c 37:8a8cc6725b48
61 settings->title = "Ascended Window"; 61 settings->title = "Ascended Window";
62 } 62 }
63 63
64 static void asc_window_init_scenes(AscWindow *window) { 64 static void asc_window_init_scenes(AscWindow *window) {
65 asc_scene_init(&window->ui); 65 asc_scene_init(&window->ui);
66 asc_camera_ortho(&window->ui.cameras[0], (asc_recti){
67 0, 0, window->dimensions
68 });
66 } 69 }
67 70
68 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { 71 AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const *settings) {
69 if (index >= ASC_MAX_WINDOWS) { 72 if (index >= ASC_MAX_WINDOWS) {
70 asc_error("Maximum number of windows exceeded."); 73 asc_error("Maximum number of windows exceeded.");
96 window->id = SDL_GetWindowID(window->window); 99 window->id = SDL_GetWindowID(window->window);
97 SDL_GetWindowSize(window->window, 100 SDL_GetWindowSize(window->window,
98 &window->dimensions.width, 101 &window->dimensions.width,
99 &window->dimensions.height 102 &window->dimensions.height
100 ); 103 );
101 asc_mat4f_ortho( 104 window->resized = true; // count initial sizing as resize
102 window->projection,
103 0,
104 (float) window->dimensions.width,
105 (float) window->dimensions.height,
106 0
107 );
108 105
109 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 106 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
110 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version); 107 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, settings->gl_major_version);
111 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, settings->gl_minor_version); 108 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, settings->gl_minor_version);
112 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings->depth_size); 109 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, settings->depth_size);
125 glEnable(GL_DEBUG_OUTPUT); 122 glEnable(GL_DEBUG_OUTPUT);
126 glDebugMessageCallback(asc_gl_debug_callback, NULL); 123 glDebugMessageCallback(asc_gl_debug_callback, NULL);
127 124
128 asc_dprintf("Window %u initialized", window->id); 125 asc_dprintf("Window %u initialized", window->id);
129 if (asc_primitives_init(&window->primitives)) { 126 if (asc_primitives_init(&window->primitives)) {
127 asc_context.active_window = window;
130 asc_window_init_scenes(window); 128 asc_window_init_scenes(window);
131 asc_context.active_window = window;
132 return window; 129 return window;
133 } else { 130 } else {
134 asc_dprintf("!!! Creating primitives for window %u failed !!!", window->id); 131 asc_dprintf("!!! Creating primitives for window %u failed !!!", window->id);
135 } 132 }
136 } else { 133 } else {
181 // clean the data 178 // clean the data
182 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id); 179 asc_dprintf("Window %u and its OpenGL context destroyed.", window->id);
183 memset(window, 0, sizeof(AscWindow)); 180 memset(window, 0, sizeof(AscWindow));
184 } 181 }
185 182
186 void asc_window_sync(AscWindow const* window) { 183 void asc_window_sync(AscWindow* window) {
187 AscWindow const *active_window = asc_context.active_window; 184 AscWindow const *active_window = asc_context.active_window;
188 if (window != active_window) { 185 if (window != active_window) {
189 asc_window_activate(window); 186 asc_window_activate(window);
190 } 187 }
191 188
192 // Clear viewport for new frame 189 // Clear for new frame
193 glViewport(0, 0, window->dimensions.width, window->dimensions.height);
194 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 190 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
195 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 191 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
196 192
197 // Draw the UI 193 // Draw the UI
198 asc_scene_draw(&window->ui); 194 asc_scene_draw(&window->ui);
199 195
200 // Swap Buffers 196 // Swap Buffers
201 SDL_GL_SwapWindow(window->window); 197 SDL_GL_SwapWindow(window->window);
198
199 // Clear Flags
200 window->resized = false;
202 201
203 if (window != active_window) { 202 if (window != active_window) {
204 asc_window_activate(active_window); 203 asc_window_activate(active_window);
205 } 204 }
206 } 205 }

mercurial