32 #include <GL/glew.h> |
32 #include <GL/glew.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_settings_init_defaults(AscWindowSettings *settings) { |
37 void asc_window_initialize(unsigned int index, AscGLContextSettings settings) { |
38 settings->dimensions.width = 800u; |
|
39 settings->dimensions.height = 600u; |
|
40 settings->fullscreen = false; |
|
41 settings->glsettings.depth_size = 24; |
|
42 settings->glsettings.vsync = 1; |
|
43 settings->glsettings.gl_major_version = 4; |
|
44 settings->glsettings.gl_minor_version = 0; |
|
45 settings->title = "Ascended Window"; |
|
46 } |
|
47 |
|
48 void asc_window_initialize(unsigned int index, const AscWindowSettings *settings) { |
|
49 if (index >= ASC_MAX_WINDOWS) { |
38 if (index >= ASC_MAX_WINDOWS) { |
50 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); |
51 return; |
40 return; |
52 } |
41 } |
53 AscWindow *window = &asc_context.windows[index]; |
42 AscWindow *window = &asc_context.windows[index]; |
55 asc_error("Cannot create window - slot %u already occupied.", index); |
44 asc_error("Cannot create window - slot %u already occupied.", index); |
56 return; |
45 return; |
57 } |
46 } |
58 |
47 |
59 SDL_WindowFlags flags = SDL_WINDOW_OPENGL; |
48 SDL_WindowFlags flags = SDL_WINDOW_OPENGL; |
60 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; |
49 flags |= settings.fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE; |
61 |
50 window->window = SDL_CreateWindow("Ascension",800, 600, flags); |
62 window->window = SDL_CreateWindow( |
|
63 settings->title, |
|
64 (int) settings->dimensions.width, |
|
65 (int) settings->dimensions.height, |
|
66 flags |
|
67 ); |
|
68 if (window->window == NULL) { |
51 if (window->window == NULL) { |
69 asc_error("Creating Window failed: %s", SDL_GetError()); |
52 asc_error("Creating Window failed: %s", SDL_GetError()); |
70 return; |
53 return; |
71 } |
54 } |
72 |
55 |
79 window->resized = true; // count initial sizing as resize |
62 window->resized = true; // count initial sizing as resize |
80 |
63 |
81 // default UI scale |
64 // default UI scale |
82 window->ui_scale = 1.0f; |
65 window->ui_scale = 1.0f; |
83 |
66 |
84 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { |
67 if (asc_gl_context_initialize(&window->glctx, window->window, &settings)) { |
85 char ui_scene_name[16]; |
68 char ui_scene_name[16]; |
86 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); |
69 snprintf(ui_scene_name, sizeof(ui_scene_name), "Window %u UI", index); |
87 asc_scene_init(&window->ui, ui_scene_name, |
70 asc_scene_init(&window->ui, ui_scene_name, |
88 .type = ASC_CAMERA_ORTHO, |
71 .type = ASC_CAMERA_ORTHO, |
89 .ortho.rect = ASC_RECT(0, 0, window->dimensions.width, window->dimensions.height), |
72 .ortho.rect = ASC_RECT(0, 0, window->dimensions.width, window->dimensions.height), |