PDA

View Full Version : Surprise, The Frame Speed is varied all the time!



honeyhuang
05-30-2006, 11:46 PM
Hi all, when I run my project, the frame speed varied up and down. I can not understand it !
let me introduce my project here.
My project is programed with SDL & OpenGL, in the main.cpp file, i use the following codes,

while ( !done )
{
SDL_Event event;
int lasttype = 0, lastbut = 0;
while(SDL_PollEvent(&event))
{
deal with message......
};

SuperPG.Draw();
glFinish();

SDL_GL_SwapBuffers();
}

every 3D object is rendered in SuperPG.Draw() function, the function code is as followed:

Draw()
{
millis =GetTickCount(); //(ms)

if (lastmillis) //Global variant initialized as 0
{
curtime = millis - lastmillis; //

m_NewDesktop.Draw();

DrawStatus(); //print the fps
}

lastmillis = millis;

}

in the DrawStatus() function, i compute the fps:

{
if (curtime!=0)
{
fps = 1000.0/curtime;
oldfps = fps;
}
else
{
fps = oldfps;
}

*fpschar='\0';
sprintf(fpschar,"%ld", (int) fps);
printf("%s\n", fpschar);
}

Who can tell me why the result fps is varied strongly? sometimes 12 frame per second
sometimes 15fps
sometimes 16fps
sometimes 21fps.
Does the message pool effect the frame speed? But I never touch the mouse and keyboard since the project start running. Why I can not see a steady fps?
Anybody tell me the reason? Thank you very much.

Jan
05-31-2006, 09:07 AM
Don't crosspoast. Beginners Forum was the right choice for this question.