Add FPS limiter (limits at 60 FPS).
This commit is contained in:
parent
5400c4a8fc
commit
766a2d597c
@ -39,8 +39,11 @@ void run() {
|
|||||||
camera cam;
|
camera cam;
|
||||||
cube box;
|
cube box;
|
||||||
|
|
||||||
|
unsigned int last_time = SDL_GetTicks();
|
||||||
|
|
||||||
while(not in_sys.get_action("quit"))
|
while(not in_sys.get_action("quit"))
|
||||||
{
|
{
|
||||||
|
in_sys.sync_events();
|
||||||
cam.update(&in_sys);
|
cam.update(&in_sys);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@ -64,9 +67,10 @@ void run() {
|
|||||||
glUniformMatrix4fv(matrix_id, 1, GL_FALSE, &mvp[0][0]);
|
glUniformMatrix4fv(matrix_id, 1, GL_FALSE, &mvp[0][0]);
|
||||||
|
|
||||||
box.render();
|
box.render();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
|
|
||||||
in_sys.sync_events();
|
if(SDL_GetTicks() - last_time < (1000 / 60))
|
||||||
|
SDL_Delay((1000 / 60) - (SDL_GetTicks() - last_time));
|
||||||
|
last_time = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user