(Compiling gcc under Linux) Below, is an attempt to loop until a SDL_QUIT event occurs. However, the program immediately drops out of the while loop without an event. What have I done wrong?
// +-------------------------------------+
// | main.c |
// | poll SDL_QUIT |
// | by Jan Zumwalt ver 2020-08-01 |
// +-------------------------------------+
#include <stdio.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
_Bool QUIT=0;
SDL_Event pEvent;
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING)) // attempt to initialize graphics system
{
while (!QUIT)
{
while (SDL_PollEvent(&pEvent)) /* handle events here */
{
if (pEvent.type == SDL_QUIT)
{
QUIT = 1;
}
}
/* do some other stuff here -- draw your app, etc. */
}
}
printf("Pause for 5 seconds\n");
SDL_Delay(5000); // show messages 5sec
SDL_Quit(); // clean up sdl2 resources before exiting
return 0; // return success
}