I am making an Sdl game, it\'s 2d shooter. I am using SDL to import surfaces and OpenGL to draw them on the screen (doing so because it works way faster than just SDL). I\'v
Have you tried using something like usleep(50000)
instead of delay(1)
?
This would make your thread sleep for 50 msecs between polling the queue, or equivalently, you would check the queue 20 times per second.
Also, what platform is this on: Linux, Windows?
On Windows you may not have usleep()
, but you can try select()
as follows:
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 50000;
select(0, NULL, NULL, NULL, &tv);
Another suggestion is to try polling in a tight loop until it stops returning events. Once no events are pending, proceed with sleeping for 50 msecs between polls until it starts returning events again.