MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / createGLWindow

Method createGLWindow

engine/src/program.cpp:176–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool
177GLWindow::createGLWindow (const char *title)
178{
179 int width = isFullscreen ? videoModes[fullscreenMode].width
180 : videoModes[windowedMode].width;
181 int height = isFullscreen ? videoModes[fullscreenMode].height
182 : videoModes[windowedMode].height;
183 int bits = isFullscreen ? videoModes[fullscreenMode].bpp
184 : videoModes[windowedMode].bpp;
185
186 SDL_DisplayMode currentMode;
187 SDL_GetCurrentDisplayMode (0, &currentMode);
188 windowPosition =
189 Point (currentMode.w / 2 - width / 2, currentMode.h / 2 - height / 2);
190
191 int x = isFullscreen ? 0 : windowPosition.x;
192 int y = isFullscreen ? 0 : windowPosition.y;
193
194 Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
195 if (isFullscreen)
196 {
197 flags |= SDL_WINDOW_FULLSCREEN;
198 SDL_ShowCursor (SDL_DISABLE);
199 }
200
201 window = SDL_CreateWindow (title, x, y, width, height, flags);
202 if (!window)
203 {
204 std::cerr << "Failed to create window: " << SDL_GetError () << std::endl;
205 return false;
206 }
207
208 if (!initGL (bits))
209 {
210 SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_ERROR, "Error",
211 "OpenGL initialization failed.", window);
212 SDL_DestroyWindow (window);
213 window = nullptr;
214 return false;
215 }
216
217 SDL_RaiseWindow (window);
218 return true;
219}
220
221void
222GLWindow::createGLWindow (bool togglefullscreen)

Callers 2

mainFunction · 0.80
P_runFunction · 0.80

Calls 1

PointClass · 0.85

Tested by

no test coverage detected