27 |
27 |
28 #include "ascension/error.h" |
28 #include "ascension/error.h" |
29 #include "ascension/window.h" |
29 #include "ascension/window.h" |
30 #include "ascension/context.h" |
30 #include "ascension/context.h" |
31 |
31 |
|
32 #include <GL/glew.h> |
|
33 |
32 #include <assert.h> |
34 #include <assert.h> |
33 #include <GL/glew.h> |
35 #include <stdio.h> |
34 |
36 |
35 void asc_window_settings_init_defaults(AscWindowSettings *settings) { |
37 void asc_window_settings_init_defaults(AscWindowSettings *settings) { |
36 settings->dimensions.width = 800u; |
38 settings->dimensions.width = 800u; |
37 settings->dimensions.height = 600u; |
39 settings->dimensions.height = 600u; |
38 settings->fullscreen = false; |
40 settings->fullscreen = false; |
52 if (window->id > 0) { |
54 if (window->id > 0) { |
53 asc_error("Cannot create window - slot %u already occupied.", index); |
55 asc_error("Cannot create window - slot %u already occupied.", index); |
54 return; |
56 return; |
55 } |
57 } |
56 |
58 |
57 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; |
59 SDL_WindowFlags flags = SDL_WINDOW_OPENGL; |
58 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; |
60 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; |
59 |
61 |
60 window->window = SDL_CreateWindow( |
62 window->window = SDL_CreateWindow( |
61 settings->title, |
63 settings->title, |
62 SDL_WINDOWPOS_CENTERED, |
64 (int) settings->dimensions.width, |
63 SDL_WINDOWPOS_CENTERED, |
65 (int) settings->dimensions.height, |
64 settings->dimensions.width, |
|
65 settings->dimensions.height, |
|
66 flags |
66 flags |
67 ); |
67 ); |
68 if (window->window == NULL) { |
68 if (window->window == NULL) { |
69 asc_error("Creating Window failed: %s", SDL_GetError()); |
69 asc_error("Creating Window failed: %s", SDL_GetError()); |
70 return; |
70 return; |
201 return &asc_active_window->scenes[index]; |
201 return &asc_active_window->scenes[index]; |
202 } |
202 } |
203 |
203 |
204 asc_vec2u asc_window_display_resolution(void) { |
204 asc_vec2u asc_window_display_resolution(void) { |
205 const AscWindow *window = asc_active_window; |
205 const AscWindow *window = asc_active_window; |
206 SDL_DisplayMode dm; |
206 SDL_DisplayID display = SDL_GetDisplayForWindow(window->window); |
207 const int display = SDL_GetWindowDisplayIndex(window->window); |
207 const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(display); |
208 if (SDL_GetDesktopDisplayMode(display, &dm)) { |
208 if (dm == NULL) { |
209 asc_error("Failed to get display mode for window %u on display %d: %s", |
209 asc_error("Failed to get display mode for window %u on display %d: %s", |
210 window->id, display, SDL_GetError()); |
210 window->id, display, SDL_GetError()); |
211 } |
211 } |
212 return ASC_VEC2U(dm.w, dm.h); |
212 return ASC_VEC2U(dm->w, dm->h); |
213 } |
213 } |
214 |
214 |
215 float asc_window_ui_scale(unsigned int index) { |
215 float asc_window_ui_scale(unsigned int index) { |
216 assert(asc_context.windows[index].window != NULL); |
216 assert(asc_context.windows[index].window != NULL); |
217 return asc_context.windows[index].ui_scale; |
217 return asc_context.windows[index].ui_scale; |