PDA

View Full Version : skeleton glut app has low frame rate (code)



avocados
07-17-2005, 12:42 PM
I'm just swapping buffers here and getting only 76 frames per second. Can that be right? In order to maintain 60fps I would need to spend 4/5ths of the time on each frame just swapping the buffer. This is on a GeForce4 TS 2ghz AMD.


#include <gl\glut.h>
#include <stdio.h>


int ticks = 0;

void countFPS(int t)
{
printf("FPS: %d\n", ticks);
ticks = 0;
glutTimerFunc( 1000, countFPS, 0);
}

void renderScene(void) //**RENDERSCENE**//
{
ticks++;

glutSwapBuffers();
glutPostRedisplay();
}

int main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowPosition(40,175);
glutInitWindowSize(800,600);
glutCreateWindow("frame rate test");

glutDisplayFunc(renderScene);

glutTimerFunc( 1000, countFPS, 0);
glutMainLoop();

return(0);
}

07-17-2005, 12:49 PM
do you have vsync enabled?

You can disable it within your app with the WGL extension wglSwapInterval(0).

avocados
07-17-2005, 01:22 PM
I just recomplied with GL_SINGLE and now I get over 340,000 FPS. Could vsync be screwing up double buffering and not single? My desktop refresh is 60hz, so I thought vsync couldn't be an issue.

07-17-2005, 01:31 PM
With a single buffer, there is no buffer to swap.

You can also disable the vsync from your desktop settings dialog. Try that and see what happens...

avocados
07-17-2005, 01:53 PM
I forgot to say I was calling glFlush with the single buffer.

But you're right, its vsync. This app runs at 1500fps after disabling vsync in the nvidia control panel.

I'm not sure what to do now. I'm rendering a heightmap with texture blending and I get an extra 10 to 15 FPS with vsync turned off. Do all games turn vsync off then?

07-17-2005, 08:43 PM
glFlush empties the command buffers, while glFinish blocks until all commands complete. Neither of these calls have anything to do with vsync or frame buffer swapping. With vsync enabled in a double buffer configuration, SwapBuffers() waits for the next vertical retrace to swap the front and back frame buffers. In a single buffer scenario, there is only the front buffer, hence no swap is possible and vsync becomes irrelevant.

Do all games turn vsync off? Don't know. Some do. Obviously you'd like to leave it on for the visual quality, but I think some games make it an option, so gamers can turn it off for the extra fps, especially on older systems that are struggling with the newer games...

avocados
07-18-2005, 09:25 AM
Thanks Hlz, I'll get the WGL extension. That will be fine for what I'm doing for awhile.