Refresh screen at maximum rate based on timer
This handles window resizes much more smoothly as well.
This commit is contained in:
parent
eed5ac7586
commit
deed177f55
21
src/app.d
21
src/app.d
@ -15,6 +15,7 @@ GLuint program_id;
|
||||
mat4 view_matrix;
|
||||
int window_width;
|
||||
int window_height;
|
||||
private __gshared bool draw_pending;
|
||||
|
||||
private void init()
|
||||
{
|
||||
@ -90,6 +91,7 @@ private void display(SDL_Window * window)
|
||||
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, null);
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
draw_pending = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
@ -124,12 +126,13 @@ int main()
|
||||
}
|
||||
|
||||
init();
|
||||
SDL_AddTimer(5, &tick, null);
|
||||
resize(WIDTH, HEIGHT);
|
||||
SDL_Event event;
|
||||
outer:
|
||||
for (;;)
|
||||
{
|
||||
if (SDL_PollEvent(&event))
|
||||
if (SDL_WaitEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
@ -159,8 +162,11 @@ outer:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (draw_pending)
|
||||
{
|
||||
display(window);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
|
||||
@ -170,3 +176,16 @@ outer:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private extern(C) uint tick(uint interval, void * param) nothrow
|
||||
{
|
||||
if (!draw_pending)
|
||||
{
|
||||
/* Draw a new frame every 5 ms if not still drawing the last. */
|
||||
draw_pending = true;
|
||||
SDL_Event event;
|
||||
event.type = SDL_USEREVENT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
return interval;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user