Jump to content

  • Log In with Google      Sign In   
  • Create Account


c++ SDL FPS Capping and displaying No proper tutorial


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 1161

Like
0Likes
Like

Posted 25 August 2012 - 10:45 AM

Hello.
This easy and simple concept, Done it thousand times before and now am getting problems...

Tutorial should have:
How to cap FPS,
Needs to be able to count fps so its printable to screen;
Should have delta time.

Cant find proper tutorial any suggestions.

Edited by BaneTrapper, 25 August 2012 - 10:47 AM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9541

Like
1Likes
Like

Posted 25 August 2012 - 10:47 AM

What have you tried? What problems are you having now that you didn't have before?

#3 BaneTrapper   Members   -  Reputation: 1161

Like
0Likes
Like

Posted 25 August 2012 - 11:21 AM

What have you tried? What problems are you having now that you didn't have before?


I remember i did SDL application that capped frames per second, Counted loops, Make approximation on how much is a FPS and all that good stuff
and i printed everything to screen,
i got bout 20folders each with about 20+ projects its hard to find one i need. If i knew name at least.

My current problem is that,
Uint32 a = SDL_GetTicks();
//10 milisec passed;
Uint32 b = SDL_GetTicks() - a;
b is not 10 nor its 100 nor its 1 i get illogical number
Its 100% Uint32 = Uint32 - Uint32 and i dont get it;

Edit:: i know SDL_GetTicks() is inacurate to 10 milisec but i get such random numbers like 1031 one loop next one i get 323

I tried searching on google a good tutorial but difficult to find a proper one.
So could you suggest one

Edited by BaneTrapper, 25 August 2012 - 11:23 AM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#4 Servant of the Lord   Crossbones+   -  Reputation: 18487

Like
1Likes
Like

Posted 25 August 2012 - 01:28 PM

FPS capping is not something that is API-specific, though certain APIs may have features to assist in it.
You don't need a tutorial on "FPS capping in SDL", but just one on FPS capping, which you personally happen to use in SDL.

But really, you don't normally want to cap your FPS (the drawing of the game). Typically, you either cap or interpolate your logic (the moving of objects in the game).
If you successfully can handle the speed that your game updates, then the program can draw as fast or slow as the computer wants without harm (unless it gets too slow).

You can either fix your timestep (cap your logic updates) or have frame independent movement (move your logic based on how much time has passed).
But if you decide to cap your FPS anyway, here's how.

The only time you really want to cap your framerate is if you are syncronizing your game's framerate with the monitor refresh rate.
It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 BaneTrapper   Members   -  Reputation: 1161

Like
0Likes
Like

Posted 26 August 2012 - 04:39 AM

Since i am making a windowed game,
I want to cap the Rendering loop to a 80 - 60FPS.
Thanks on those all tutorials.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#6 Goran Milovanovic   Members   -  Reputation: 1104

Like
1Likes
Like

Posted 26 August 2012 - 01:08 PM

Typically, I use something like this:

[source lang="cpp"]while (1){ Uint32 time_before = SDL_GetTicks(); render(); Uint32 time_after = SDL_GetTicks(); int delta = time_after - time_before; int time_wait = (1000 / 60) - delta; // cap at 60 fps if (time_wait > 0){ SDL_Delay(time_wait) }}[/source]

It might not be 100% accurate, but it does what I want.

Edited by Goran Milovanovic, 26 August 2012 - 02:08 PM.

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS