Hi…have searched google and the forums but have not found anyone with the same problem.
I suspect I am misunderstanding how SDL_PollEvent works.
In the following code when I replace SDL_MOUSEMOTION with SDL_QUIT, SDL_MOUSEBUTTONDOWN, or even SDL_MOUSEBUTTONUP
the code behaves as I would expect for each case.
However when I use SDL_MOUSEMOTION my program window only stays up for the 2 seconds delay I have put in and then the window closes and the program exits,
even if I didn’t move my mouse at all, or even touch it.
I start the program using the keyboard in a Windows console window, so don’t touch the mouse at all before the program starts.
I was thinking that perhaps the program was taking existing events from a window buffer or something like that when it starts and that maybe I should clear before using SDL_PollEvent.
But from reading different articles on SDL_PollEvent it’s my understanding that this isn’t necessary, so I guess I am just missing something.
Any help or comments is appreciated, thank you.
Code:
SDL_Surface *screen = NULL;
SDL_Event event;
int main( int argc, char* args[] )
{
SDL_Init( SDL_INIT_EVERYTHING );
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
SDL_Delay( 2000 );
bool quit = false;
while( quit == false )
{
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_MOUSEMOTION )
{
quit = true;
}
}
}
SDL_FreeSurface( screen );
SDL_Quit();
return 0;
}