Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Yet another Framerate question

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    18

    Yet another Framerate question

    I was working on a 2D game Engine using SDL and openGL.For calculating frame rate I use the following code.

    Code :
    startTime = SDL_GetTicks();
    	frames=0;
    	while(!doneWithGame) {
    		currState->update(apg);
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    		 glLoadIdentity();
    		currState->render(apg);
    		frames++;
    		currentTime = SDL_GetTicks();
    		if(currentTime - startTime > 1000) { 
    		FPS = frames; 
    		frames = 0;
    		startTime = currentTime;
    		}
    		SDL_GL_SwapBuffers();
    		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!!!

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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 , or through SDL via SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); or something like that.
    Last edited by Nowhere-01; 04-28-2013 at 10:34 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    18
    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??
    Last edited by ragzzy-R; 04-28-2013 at 07:45 PM.

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    18
    many thanks!! that helped

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •