View Full Version : Yet another Framerate question

04-28-2013, 08:46 AM
I was working on a 2D game Engine using SDL and openGL.For calculating frame rate I use the following code.

startTime = SDL_GetTicks();
while(!doneWithGame) {
currentTime = SDL_GetTicks();
if(currentTime - startTime > 1000) {
FPS = frames;
frames = 0;
startTime = currentTime;
std::cout<<"The FPS is :"<<FPS<<std::endl;

I hope this is correct in the first place.So my question is

I use an NVidia Geforce 9500GT with a quad core processor clocking @ 2.66Ghz.and 3Gb RAM. I get an average of 60FPS when rendering a blank screen.couple of years ago I was using Slick2D a game engine using LWJGL for making small games.while using that i used to get 1500 2000 FPS as average for a blank screen.(even my games used to render with average 200 frames :P).So my question is.why is this difference??

am I calculating FPS wrongly??
or is Slick2D uses a wrong FPS calculation??
or my coding is soooooo poor??
or whatever...... just please explain this difference.

thanks in advance!!! :)

04-28-2013, 09:57 AM
and the same old answer on the question regarding framerate limit: disable v-sync, you can do it either directly, using OpenGL calls like this (http://www.opengl.org/wiki/Swap_Interval#In_Windows) , or through SDL via SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); or something like that.

04-28-2013, 07:06 PM
thanks bro!! I used SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); and now im getting 500FPS.any other tips on increasing frame rate?? especially on slow systems?

P.S: I hope your answer means that my FPS calculation is correct.:)

Also I have one doubt.If I use the OpenGL method u told then I lose portablity as the method varies between windows and Linux.but if I use the SDL_GL_SWAP_CONTROL i guess it works on both linux and windows.(havent tried yet though).So I need to know whether both produce the same results.If yes then Im happy with SDL method.If not then please tell me what to do??

04-29-2013, 01:11 AM
i do not use SDL. but i think should work the same. test it yourself. although if you are using SDL 1.3+, you probably should be able to just call "SDL_CreateRenderer" without "SDL_RENDERER_PRESENTVSYNC" flag on your application initialization. and it won't enable it by default.

your algorithm may work, but it's not very precise. you can use fraps. it will show fps overlay over your application's window.
also, calling to std::cout or any ostream function in your rendering cycle is not really a good idea. especially, every frame.

and do you really need to update your logics more than 60 times per second? i'd move it to a separate thread, limited to 30-60 FPS. but it might bring your application to a new complexity level because of synchronization.

04-29-2013, 06:29 AM
many thanks!! that helped