-
-
Save Ilgrim/9ab2ac2a678b80bfc4a0cfde0ee0b5b7 to your computer and use it in GitHub Desktop.
C++ SDL Fullscreen Toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A function for toggling windowed mode in a C++ SDL app. Fullscreen windows will appear on whichever screen the window was on. | |
* | |
* Could be used in conjunction with SDL_GetDisplayName(int displayIndex) | |
* and SDL_GetNumVideoDisplays(void) to programmatically force fullscreen onto a particular display | |
*/ | |
void toggleWindowed() | |
{ | |
//Grab the mouse so that we don't end up with unexpected movement when the dimensions/position of the window changes. | |
SDL_SetRelativeMouseMode(SDL_TRUE); | |
windowed = !windowed; | |
if (windowed) | |
{ | |
int i = SDL_GetWindowDisplayIndex(win); | |
screenWidth = windowedWidth; | |
screenHeight = windowedHeight; | |
SDL_SetWindowFullscreen(win, 0); | |
} | |
else | |
{ | |
int i = SDL_GetWindowDisplayIndex(win); | |
SDL_Rect j; | |
SDL_GetDisplayBounds(i, &j); | |
screenWidth = j.w; | |
screenHeight = j.h; | |
SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP); | |
} | |
recalculateResolution(); //This function sets appropriate font sizes/UI positions | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment