defer to sdl for fullscreen state (better behaved on macos)

This commit is contained in:
2024-03-13 06:50:16 +11:00
parent 313534e58a
commit 56a21bfa68

View File

@@ -18,7 +18,7 @@
SDL_Window* win = NULL; // Holds Our Window Handle SDL_Window* win = NULL; // Holds Our Window Handle
SDL_GLContext ctx = NULL; // Permanent Rendering Context SDL_GLContext ctx = NULL; // Permanent Rendering Context
bool fullscreen = true; // Fullscreen Flag Set To Fullscreen Mode By Default bool fullscreen = false;
bool blend = false; // Blending ON/OFF bool blend = false; // Blending ON/OFF
static const SDL_MessageBoxButtonData yesnobttns[2] = static const SDL_MessageBoxButtonData yesnobttns[2] =
@@ -346,16 +346,13 @@ bool CreateGLWindow(char *title, int width, int height, int bits, bool fullscree
}; };
int bttnid = 0; int bttnid = 0;
SDL_ShowMessageBox(&msgbox, &bttnid); SDL_ShowMessageBox(&msgbox, &bttnid);
if (bttnid == 0) if (bttnid == 1)
{
fullscreen = false; // Windowed Mode Selected. Fullscreen = FALSE
}
else
{ {
// Pop Up A Message Box Letting User Know The Program Is Closing. // Pop Up A Message Box Letting User Know The Program Is Closing.
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "ERROR", "Program Will Now Close.", NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "ERROR", "Program Will Now Close.", NULL);
return false; // Return FALSE return false; // Return FALSE
} }
fullscreen = false;
} }
} }
@@ -439,8 +436,7 @@ int SDL_AppEvent(const SDL_Event *event)
return 0; return 0;
case SDLK_F1: // F1 = Toggle Fullscreen / Windowed Mode case SDLK_F1: // F1 = Toggle Fullscreen / Windowed Mode
fullscreen = !fullscreen; SDL_SetWindowFullscreen(win, !fullscreen);
SDL_SetWindowFullscreen(win, fullscreen);
return 0; return 0;
default: return 0; default: return 0;
@@ -452,6 +448,14 @@ int SDL_AppEvent(const SDL_Event *event)
ReSizeGLScene(event->window.data1, event->window.data2); // data1=Backbuffer Width, data2=Backbuffer Height ReSizeGLScene(event->window.data1, event->window.data2); // data1=Backbuffer Width, data2=Backbuffer Height
return 0; return 0;
case SDL_EVENT_WINDOW_ENTER_FULLSCREEN:
fullscreen = true;
return 0;
case SDL_EVENT_WINDOW_LEAVE_FULLSCREEN:
fullscreen = false;
return 0;
default: return 0; default: return 0;
} }
} }
@@ -548,13 +552,10 @@ int SDL_AppInit(int argc, char *argv[])
}; };
int bttnid = 1; int bttnid = 1;
SDL_ShowMessageBox(&msgbox, &bttnid); SDL_ShowMessageBox(&msgbox, &bttnid);
if (bttnid == 1)
{
fullscreen = false; // Windowed Mode
}
// Create Our OpenGL Window // Create Our OpenGL Window
if (!CreateGLWindow("Lionel Brits & NeHe's 3D World Tutorial", 640, 480, 16, fullscreen)) const bool wantfullscreen = (bttnid == 0);
if (!CreateGLWindow("Lionel Brits & NeHe's 3D World Tutorial", 640, 480, 16, wantfullscreen))
{ {
return -1; // Quit If Window Was Not Created return -1; // Quit If Window Was Not Created
} }