MCPcopy Create free account
hub / github.com/aardappel/treesheets / SDLInit

Function SDLInit

lobster/src/sdlsystem.cpp:247–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245};
246
247string SDLInit(string_view title, const int2 &desired_screensize, bool isfullscreen, int vsync,
248 int samples) {
249 MakeDPIAware();
250 //SDL_SetMainReady();
251 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER /* | SDL_INIT_AUDIO*/) < 0) {
252 return SDLError("Unable to initialize SDL");
253 }
254
255 SDL_SetEventFilter(SDLHandleAppEvents, nullptr);
256
257 LOG_INFO("SDL initialized...");
258
259 SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
260
261 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl_major);
262 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl_minor);
263 #ifdef PLATFORM_ES3
264 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
265 #else
266 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
267 #if defined(__APPLE__) || defined(_WIN32)
268 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, samples > 1);
269 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
270 #endif
271 #endif
272
273 //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // set this if we're in 2D mode for speed on mobile?
274 SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); // because we redraw the screen each frame
275
276 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
277
278 LOG_INFO("SDL about to figure out display mode...");
279
280 #ifdef PLATFORM_ES3
281 landscape = desired_screensize.x >= desired_screensize.y;
282 int modes = SDL_GetNumDisplayModes(0);
283 screensize = int2(1920, 1080);
284 for (int i = 0; i < modes; i++) {
285 SDL_DisplayMode mode;
286 SDL_GetDisplayMode(0, i, &mode);
287 LOG_INFO("mode: ", mode.w, " ", mode.h);
288 if (landscape ? mode.w > screensize.x : mode.h > screensize.y) {
289 screensize = int2(mode.w, mode.h);
290 }
291 }
292
293 LOG_INFO("chosen resolution: ", screensize.x, " ", screensize.y);
294 LOG_INFO("SDL about to create window...");
295
296 _sdl_window = SDL_CreateWindow(null_terminated(title),
297 0, 0,
298 screensize.x, screensize.y,
299 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS);
300
301 LOG_INFO(_sdl_window ? "SDL window passed..." : "SDL window FAILED...");
302
303 if (landscape) SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
304 #else

Callers 1

AddGraphicsFunction · 0.85

Calls 6

MakeDPIAwareFunction · 0.85
SDLErrorFunction · 0.85
null_terminatedFunction · 0.85
catFunction · 0.85
ScreenSizeChangedFunction · 0.85
OpenGLInitFunction · 0.85

Tested by

no test coverage detected