[SDL] Perfomance problem with SDL+OpenGL
Jonathan Dearborn
grimfang4 at hotmail.com
Sat Dec 9 08:05:47 PST 2006
Here you go. Some code to tell fps before and after Vsync (as well as control the frame rate). This is adapted from some tutorial online (either Sol's or Marius Andra's (cone3d))
#define DESIREDFPS 27#define WAITTIME 1000 / DESIREDFPS
/// In main()
// Main loop cout.precision(4); SDL_Event event; int frameStartTime; int frameTime; float fps; bool done = 0; while(!done) { frameStartTime = SDL_GetTicks();
/// Check for input
/// Do whatever your program does
// Without vsync frameTime = SDL_GetTicks()-frameStartTime; if(frameTime != 0) fps = 1000.0f / frameTime; //this is the framerate without vsync
else fps = 1111.11f; cout << "FPS w/o vsync: " << fps << endl; /// You can use any text writer (like SFont) instead of cout
SDL_Flip(screen); // Send screen surface to the display // With vsync frameTime = SDL_GetTicks()-frameStartTime; if(frameTime != 0) fps = 1000.0f / frameTime; //this is the framerate with vsync and the framebreak
else fps = 1111.11f; cout << "FPS with vsync: " << fps << endl; /// You can use any text writer instead of cout
// Frame rate control if(frameTime < WAITTIME) Sleep(WAITTIME - frameTime); // Keep framerate constant the Windows way /** Sleep() is defined in windows.h and is not platform-independent.
You can use SDL_Delay(), but that does not give time back to the OS
like Sleep() does. **/
} // END while(!done)
/// End of main()
Date: Tue, 5 Dec 2006 01:35:57 +0100From: thephantomlord at gmail.comTo: sdl at libsdl.orgSubject: Re: [SDL] Perfomance problem with SDL+OpenGL
But can I show the fps in the caption of the window?
C ya
2006/12/4, Jonathan Dearborn <grimfang4 at hotmail.com>:
Hey, I don't know if this helps, but you can try running the program without calling SDL_Flip() (or whatever screen update function you're using, whether for SDL or OpenGL) and check the fps and compare this to the fps without the stuff you put in (drawing routine?) and without SDL_Flip(). This will avoid SDL_Flip()'s vsync at least. You won't be able to see what's happening, of course, so output the fps to a text file.
Date: Mon, 4 Dec 2006 13:46:54 +0100From: thephantomlord at gmail.comTo: cal at splitreflection.com; sdl at libsdl.orgSubject: Re: [SDL] Perfomance problem with SDL+OpenGL
Thx for all guys, I'd just though that more frame rate (more than vertical refresh) would be better! :rolleyes:
So, theres no trouble with getting that fps...
C Ya!
Sun, 3 Dec 2006 16:12:7, cal at splitreflection.com < cal at splitreflection.com>:
"Simon Roby" <simon.roby at gmail.com > wrote:> This is not a performance problem! Vertical retrace syncing (aka. > vsync) prevents your program from updating the screen more often than > it isrefreshed on your display.---I've seen claims that pushing frame rate to hundreds of frames/second makes a game more responsive. For a simplistic algorithm this can be the case. But if the input processing properly accounts for the possability for a 'button' being pressed and released during a frame, 20-30 frames/second can be suprisingly responsive. I agree that there's no point in a frame rate faster than vertical refresh. _______________________________________________SDL mailing listSDL at libsdl.orghttp://www.libsdl.org/mailman/listinfo/sdl -- Phantom LordCaelis Studios ---> From Gods Hands To Yours
Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! Try it now! _______________________________________________SDL mailing listSDL at libsdl.orghttp://www.libsdl.org/mailman/listinfo/sdl-- Phantom LordCaelis Studios ---> From Gods Hands To Yours
_________________________________________________________________
All-in-one security and maintenance for your PC. Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061209/c5acf91d/attachment.html
More information about the SDL
mailing list