43 settings->title = "Ascended Window"; |
43 settings->title = "Ascended Window"; |
44 } |
44 } |
45 |
45 |
46 void asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { |
46 void asc_window_initialize(unsigned int index, AscWindowSettings const *settings) { |
47 if (index >= ASC_MAX_WINDOWS) { |
47 if (index >= ASC_MAX_WINDOWS) { |
48 asc_error("Maximum number of windows exceeded."); |
48 asc_error("Maximum number of windows exceeded (%u/%u).", index, ASC_MAX_WINDOWS); |
49 return; |
49 return; |
50 } |
50 } |
51 AscWindow *window = &asc_context.windows[index]; |
51 AscWindow *window = &asc_context.windows[index]; |
52 if (window->id > 0) { |
52 if (window->id > 0) { |
53 asc_error("Cannot create window - slot already occupied."); |
53 asc_error("Cannot create window - slot %u already occupied.", index); |
54 asc_dprintf("Tried to create window with index %u twice", index); |
|
55 return; |
54 return; |
56 } |
55 } |
57 if (window->ui != NULL) { |
56 if (window->ui != NULL) { |
58 asc_dprintf("Window with index %u has a dangling UI pointer", index); |
57 asc_wprintf("Window with index %u has a dangling UI pointer", index); |
59 asc_scene_node_free(window->ui); |
58 asc_scene_node_free(window->ui); |
60 } |
59 } |
61 |
60 |
62 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; |
61 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; |
63 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; |
62 flags |= settings->fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; |
69 settings->dimensions.width, |
68 settings->dimensions.width, |
70 settings->dimensions.height, |
69 settings->dimensions.height, |
71 flags |
70 flags |
72 ); |
71 ); |
73 if (window->window == NULL) { |
72 if (window->window == NULL) { |
74 asc_error(SDL_GetError()); |
73 asc_error("Creating Window failed: %s", SDL_GetError()); |
75 return; |
74 return; |
76 } |
75 } |
77 |
76 |
78 window->id = SDL_GetWindowID(window->window); |
77 window->id = SDL_GetWindowID(window->window); |
79 SDL_GetWindowSize(window->window, |
78 SDL_GetWindowSize(window->window, |
85 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { |
84 if (asc_gl_context_initialize(&window->glctx, window->window, &settings->glsettings)) { |
86 window->ui = asc_scene_node_empty(); |
85 window->ui = asc_scene_node_empty(); |
87 asc_dprintf("Window %u initialized", window->id); |
86 asc_dprintf("Window %u initialized", window->id); |
88 asc_context.active_window = index; |
87 asc_context.active_window = index; |
89 } else { |
88 } else { |
90 asc_dprintf("Creating GL context failed for window %u", window->id); |
89 asc_error("Creating GL context failed for window %u", window->id); |
91 // cleanup on error |
90 // cleanup on error |
92 SDL_DestroyWindow(window->window); |
91 SDL_DestroyWindow(window->window); |
93 window->window = NULL; |
92 window->window = NULL; |
94 window->id = 0; |
93 window->id = 0; |
95 } |
94 } |