| 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> |
32 #include "glad.h" |
| 33 |
33 |
| 34 #include <assert.h> |
34 #include <assert.h> |
| 35 #include <stdio.h> |
35 #include <stdio.h> |
| 36 |
36 |
| 37 void asc_window_initialize(unsigned int index, AscGLContextSettings settings) { |
37 void asc_window_initialize(unsigned int index, bool fullscreen) { |
| 38 if (index >= ASC_MAX_WINDOWS) { |
38 if (index >= ASC_MAX_WINDOWS) { |
| 39 asc_error("Maximum number of windows exceeded (%u/%u).", index, ASC_MAX_WINDOWS); |
39 asc_error("Maximum number of windows exceeded (%u/%u).", index, ASC_MAX_WINDOWS); |
| 40 return; |
40 return; |
| 41 } |
41 } |
| 42 AscWindow *window = &asc_context.windows[index]; |
42 AscWindow *window = &asc_context.windows[index]; |
| 44 asc_error("Cannot create window - slot %u already occupied.", index); |
44 asc_error("Cannot create window - slot %u already occupied.", index); |
| 45 return; |
45 return; |
| 46 } |
46 } |
| 47 |
47 |
| 48 SDL_WindowFlags flags = SDL_WINDOW_OPENGL; |
48 SDL_WindowFlags flags = SDL_WINDOW_OPENGL; |
| 49 flags |= settings.fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; |
49 flags |= fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; |
| 50 window->sdl = SDL_CreateWindow("Ascension",800, 600, flags); |
50 window->sdl = SDL_CreateWindow("Ascension",800, 600, flags); |
| 51 if (window->sdl == NULL) { |
51 if (window->sdl == NULL) { |
| 52 asc_error("Creating Window failed: %s", SDL_GetError()); |
52 asc_error("Creating Window failed: %s", SDL_GetError()); |
| 53 return; |
53 return; |
| 54 } |
54 } |
| 63 window->resized = true; // count initial sizing as resize |
63 window->resized = true; // count initial sizing as resize |
| 64 |
64 |
| 65 // default UI scale |
65 // default UI scale |
| 66 window->ui_scale = 1.0f; |
66 window->ui_scale = 1.0f; |
| 67 |
67 |
| 68 if (asc_gl_context_initialize(&window->glctx, window->sdl, &settings)) { |
68 if (asc_gl_context_initialize(&window->glctx, window->sdl)) { |
| 69 char ui_scene_name[16]; |
69 char ui_scene_name[16]; |
| 70 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); |
70 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); |
| 71 asc_camera_init(&window->ui_camera, .type = ASC_CAMERA_ORTHO, |
71 asc_camera_init(&window->ui_camera, .type = ASC_CAMERA_ORTHO, |
| 72 .ortho.rect = ASC_RECTV(ASC_VEC2I_0, window->rect.size), |
72 .ortho.rect = ASC_RECTV(ASC_VEC2I_0, window->rect.size), |
| 73 .viewport_update_func = asc_camera_ortho_update_size); |
73 .viewport_update_func = asc_camera_ortho_update_size); |