[SDL] a few simple SDL questions

Pallav Nawani pallav at sasken.com
Wed Jan 29 02:41:01 PST 2003


> 2) is it better for performance if i write my own double-buffering code, or 
> initialize w/ SDL_DOUBLEBUF and then call SDL_Flip() everytime i refresh the 
> screen?

If you're an expert in directx then you might be able to write 
faster functions, but in general, you're well off using SDL. Use 
hardware surfaces with sdl_flip otherwise performance will 
suffer.

 
> 3) How could i initialize an fps counter for my game (sorry i'm really at a 
> loss w/ this one) ?

float total_time = 0;

t1 = SDL_GetTicks();
game_loop();
frame_count++;
t2 = SDL_GetTicks();

total_time += (t2-t1)/1000.0;
fps = frame_count/total_time;
if(frame_count==10) {
total_time = 0;
frame_count = 0;
}

This gives you an 'average' fps, for every 10 frames. You can 
modify this to suit your requirements.



-- 
hth,
Pallav.

_______________________________________________________________________
Ralph's Observation:
	It is a mistake to let any mechanical object realise that you
	are in a hurry.
_________________________________________________________________
|		                                      		|
|Pallav Nawani                    				|
|Sasken Communication Technologies Ltd.				|
|Domlur, Bangalore.						|
|_______________________________________________________________|





More information about the SDL mailing list