remove timer, poll for event instead to run at maximum framerate
This commit is contained in:
parent
4425ba1c0b
commit
0e85b9ef95
@ -5,7 +5,6 @@ import derelict.opengl.glu;
|
|||||||
|
|
||||||
enum int WIDTH = 800;
|
enum int WIDTH = 800;
|
||||||
enum int HEIGHT = 600;
|
enum int HEIGHT = 600;
|
||||||
static bool drawing = false;
|
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
@ -22,7 +21,6 @@ void init()
|
|||||||
|
|
||||||
void display()
|
void display()
|
||||||
{
|
{
|
||||||
drawing = true;
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(SDL_GetTicks() * 90.0 / 1000, 0, 0, 1);
|
glRotatef(SDL_GetTicks() * 90.0 / 1000, 0, 0, 1);
|
||||||
@ -37,21 +35,9 @@ void display()
|
|||||||
glVertex3f(5.0, -5.0, 0.0);
|
glVertex3f(5.0, -5.0, 0.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
drawing = false;
|
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
int main(char[][] args)
|
||||||
{
|
{
|
||||||
DerelictSDL.load();
|
DerelictSDL.load();
|
||||||
@ -76,20 +62,19 @@ int main(char[][] args)
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_AddTimer(1000 / 60, &timer_callback, null);
|
for (;;)
|
||||||
while (SDL_WaitEvent(&event))
|
|
||||||
{
|
{
|
||||||
if (event.type == SDL_QUIT)
|
if (SDL_PollEvent(&event))
|
||||||
break;
|
|
||||||
else if (event.type == SDL_KEYDOWN)
|
|
||||||
{
|
{
|
||||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
if (event.type == SDL_QUIT)
|
||||||
break;
|
break;
|
||||||
|
else if (event.type == SDL_KEYDOWN)
|
||||||
|
{
|
||||||
|
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_USEREVENT)
|
display();
|
||||||
{
|
|
||||||
display();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user