Skip to main content
GameDev.net gamedev.net
🔒 Locked

frame sync

Started by sprinter_trueno Apr 25, 2003 at 5:56 AM 0 replies 550+ views
Original Post
sprinter_trueno
sprinter_trueno
Hi ppl, I got a question that is bothering me for some time now. Here it goes: How is it done that if I wanna use a fixed frame rate while the refresh rate of the video card is not. For example, my app shows 50 frames a second but my refresh rate is set to 60Hz. As far as I know it is a good method to wait for the vertical blank but then my app would of course always run at a different speed. The only idea I can think of is that I skip some blanks for redraw to maintain the speed, so that in the end I draw 50 frames while I have 60 redraws which means that every 6th redraw just shows the 5th. Is this correct or is there another method ? Thanks for any comment. Lorenz
RhoneRanger
RhoneRanger
YOu could set your timer to render at 50 fps. Just an idea of how you could accomplish this. Maybe someone has something better?

int fps=50; //change this to whatever you want your fps to be
//if you want your game to run at 40 fps etc.

float RenderTimer=1/fps;

float TimeToRender=0.00f;
Just use your Elapsed time in this manner in the game loop



TimeToRender+=Elapsed;

Do non graphic stuff;

if(TimeToRender>=RenderTimer)
{
renderScene;
TimeToRender=0.00f;
}



TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.