add timer to push display event

This commit is contained in:
Josh Holtrop 2013-02-02 21:43:48 -05:00
parent f05afa10b3
commit 3fbc5aa16d

View File

@ -5,6 +5,7 @@ import derelict.opengl.glu;
enum int WIDTH = 800;
enum int HEIGHT = 600;
static bool drawing = false;
void init()
{
@ -21,6 +22,7 @@ void init()
void display()
{
drawing = true;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1, 1, 1);
@ -33,6 +35,18 @@ void display()
glVertex3f(5.0, -5.0, 0.0);
glEnd();
SDL_GL_SwapBuffers();
drawing = false;
}
extern (C) Uint32 timer_callback(Uint32 interval, void *param)
{
if (!drawing)
{
SDL_Event event;
event.type = SDL_USEREVENT;
SDL_PushEvent(&event);
}
return interval;
}
int main(char[][] args)
@ -58,8 +72,8 @@ int main(char[][] args)
}
init();
display();
SDL_Event event;
SDL_AddTimer(1000 / 50, &timer_callback, null);
while (SDL_WaitEvent(&event))
{
if (event.type == SDL_QUIT)
@ -69,6 +83,10 @@ int main(char[][] args)
if (event.key.keysym.sym == SDLK_ESCAPE)
break;
}
else if (event.type == SDL_USEREVENT)
{
display();
}
}
SDL_Quit();