MCPcopy Create free account
hub / github.com/assaultcube/AC / setupscreen

Function setupscreen

source/src/main.cpp:558–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

556COMMAND(getdisplayresolutions, "");
557
558void setupscreen(int &useddepthbits, int &usedfsaa)
559{
560 if(glcontext)
561 {
562 SDL_GL_DeleteContext(glcontext);
563 glcontext = NULL;
564 }
565 if(screen)
566 {
567 SDL_DestroyWindow(screen);
568 screen = NULL;
569 }
570
571 SDL_Rect desktop;
572 if(SDL_GetDisplayBounds(0, &desktop) < 0) fatal("failed querying desktop bounds: %s", SDL_GetError());
573 desktopw = desktop.w;
574 desktoph = desktop.h;
575 if(scr_w < 0 || scr_h < 0) { scr_w = desktopw; scr_h = desktoph; } // first run: set to fullscreen res
576
577 int modes = SDL_GetNumDisplayModes(0);
578 if(modes >= 1)
579 {
580 bool hasmode = false;
581 SDL_DisplayMode mode;
582 loopi(modes)
583 {
584 if(SDL_GetDisplayMode(0, i, &mode) == 0 && scr_w <= mode.w && scr_h <= mode.h) { hasmode = true; break; }
585 }
586 if(!hasmode && SDL_GetDisplayMode(0, 0, &mode) == 0) { scr_w = mode.w; scr_h = mode.h; }
587
588 }
589 int winw = fullscreen && fullscreendesktop ? desktopw : scr_w;
590 int winh = fullscreen && fullscreendesktop ? desktoph : scr_h;
591
592 int flags = SDL_WINDOW_RESIZABLE;
593 if(fullscreen) flags |= fullscreendesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
594
595 static int configs[] =
596 {
597 0x7, /* try everything */
598 0x6, 0x5, 0x3, /* try disabling one at a time */
599 0x4, 0x2, 0x1, /* try disabling two at a time */
600 0 /* try disabling everything */
601 };
602 int config = 0;
603 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
604 if(!depthbits) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
605 if(!fsaa)
606 {
607 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
608 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
609 }
610 loopi(sizeof(configs)/sizeof(configs[0]))
611 {
612 config = configs[i];
613 if(!depthbits && config&1) continue;
614 if(!stencilbits && config&2) continue;
615 if(fsaa<=0 && config&4) continue;

Callers 2

resetglFunction · 0.85
main.cppFile · 0.85

Calls 5

updatescreensizeFunction · 0.85
inputgrabFunction · 0.85
fatalFunction · 0.70
loopiFunction · 0.70
conoutfFunction · 0.70

Tested by

no test coverage detected