mirror of
https://github.com/ScrelliCopter/Lesson10-SDL3.git
synced 2025-02-21 07:19:26 +11:00
break out update
This commit is contained in:
90
Lesson10.c
90
Lesson10.c
@@ -17,7 +17,6 @@
|
|||||||
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 active = true; // Window Active Flag Set To TRUE By Default
|
|
||||||
bool fullscreen = true; // Fullscreen Flag Set To Fullscreen Mode By Default
|
bool fullscreen = true; // Fullscreen Flag Set To Fullscreen Mode By Default
|
||||||
bool blend = false; // Blending ON/OFF
|
bool blend = false; // Blending ON/OFF
|
||||||
|
|
||||||
@@ -480,53 +479,17 @@ void WndProc(SDL_Event *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int Update(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
|
|
||||||
// Ask The User Which Screen Mode They Prefer
|
|
||||||
const SDL_MessageBoxData msgbox =
|
|
||||||
{
|
|
||||||
/* flags */ SDL_MESSAGEBOX_INFORMATION,
|
|
||||||
/* window */ win,
|
|
||||||
/* title */ "Start FullScreen?",
|
|
||||||
/* message */ "Would You Like To Run In Fullscreen Mode?",
|
|
||||||
/* numbuttons */ 2,
|
|
||||||
/* buttons */ yesnobttns,
|
|
||||||
/* colorScheme */ NULL
|
|
||||||
};
|
|
||||||
int bttnid = 1;
|
|
||||||
SDL_ShowMessageBox(&msgbox, &bttnid);
|
|
||||||
if (bttnid == 1)
|
|
||||||
{
|
|
||||||
fullscreen = false; // Windowed Mode
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Our OpenGL Window
|
|
||||||
if (!CreateGLWindow("Lionel Brits & NeHe's 3D World Tutorial", 640, 480, 16, fullscreen))
|
|
||||||
{
|
|
||||||
return 0; // Quit If Window Was Not Created
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!done) // Loop That Runs While done=FALSE
|
|
||||||
{
|
|
||||||
SDL_Event event; // SDL Event Structure
|
|
||||||
while (SDL_PollEvent(&event) > 0) // Is There A Message Waiting?
|
|
||||||
{
|
|
||||||
WndProc(&event); // Deal with events
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw The Scene. Watch Quit Messages From DrawGLScene()
|
// Draw The Scene. Watch Quit Messages From DrawGLScene()
|
||||||
if (active && !DrawGLScene()) // Active?
|
if (!DrawGLScene())
|
||||||
{
|
{
|
||||||
done = true; // ESC or DrawGLScene Signalled A Quit
|
done = true; // DrawGLScene Signalled A Quit
|
||||||
break;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SwapWindow(win); // Swap Buffers (Double Buffering)
|
SDL_GL_SwapWindow(win); // Swap Buffers (Double Buffering)
|
||||||
|
|
||||||
|
|
||||||
// Handle keyboard input
|
// Handle keyboard input
|
||||||
const Uint8* keys = SDL_GetKeyboardState(NULL);
|
const Uint8* keys = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
@@ -592,8 +555,53 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
lookupdown += 1.0f;
|
lookupdown += 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
|
// Ask The User Which Screen Mode They Prefer
|
||||||
|
const SDL_MessageBoxData msgbox =
|
||||||
|
{
|
||||||
|
/* flags */ SDL_MESSAGEBOX_INFORMATION,
|
||||||
|
/* window */ win,
|
||||||
|
/* title */ "Start FullScreen?",
|
||||||
|
/* message */ "Would You Like To Run In Fullscreen Mode?",
|
||||||
|
/* numbuttons */ 2,
|
||||||
|
/* buttons */ yesnobttns,
|
||||||
|
/* colorScheme */ NULL
|
||||||
|
};
|
||||||
|
int bttnid = 1;
|
||||||
|
SDL_ShowMessageBox(&msgbox, &bttnid);
|
||||||
|
if (bttnid == 1)
|
||||||
|
{
|
||||||
|
fullscreen = false; // Windowed Mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Our OpenGL Window
|
||||||
|
if (!CreateGLWindow("Lionel Brits & NeHe's 3D World Tutorial", 640, 480, 16, fullscreen))
|
||||||
|
{
|
||||||
|
return 0; // Quit If Window Was Not Created
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
SDL_Event event; // SDL Event Structure
|
||||||
|
while (SDL_PollEvent(&event) > 0) // Is There A Message Waiting?
|
||||||
|
{
|
||||||
|
WndProc(&event); // Deal with events
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Update())
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
} while (!done);
|
||||||
|
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
FreeResources();
|
FreeResources();
|
||||||
KillGLWindow(); // Kill The Window
|
KillGLWindow(); // Kill The Window
|
||||||
|
|||||||
Reference in New Issue
Block a user