Advertisement

fps question...

Started by December 29, 2001 01:55 PM
12 comments, last by ironhell3 23 years, 1 month ago
I'm not dfawcett, but here you go:

quote:
1) what is the difference between int x; and static int x; ?


Putting 'static' in front of a local variable means that that variable won't lose its value after the function call. So it's almost like a global variable, it just doesn't have global scope.

quote:
2) what is a DWORD ?


A Double-Word. This is a 32-bit unsigned integer (it's a typedef for unsigned long).

quote:
3) the fps we return (return fps), how can i use it in a printf?


I thought this was going to be in OpenGL? You can't use printf here.


For the most accurate results, you can use a performance timer (look up QueryPerformanceFrequency and QueryPerformanceTimer on MSDN). QueryPerformanceFrequency will return zero if no high-res performance timer exists, so you can set it up to use timeGetTime (or some other timing function) on machines that don't have a higher resolution timer.

One last thing, are you sure you're ready to be making games right now? You don't seem to fully understand the language, maybe you should brush up on things first before starting into game development.

Edited by - Midnight Coder on December 31, 2001 1:42:12 PM
why don''t you go through NeHe''s tutorials step-by-step. you''ll learn OpenGL and everything realted to fps. you won''t see too many neat language tricks, however, as these are JUST tutes and need to be clear to everyone, but you wouldn''t be asking how to display text or how to init a timer. this is just a bit of friendly advice. of course, you could take up Programming in C by Kernighan & Ritchie to get yourself up to speed with C/C++ basics if you''re not entirely comfortable with the language itself. then again - you can probably write ogl games without any profound knowledge of C/C++. it''d be ALOT more difficult, though...

keep cool
Advertisement
Just for fun, check this out:

{
static unsigned int ticks, last_ticks, i;
static int fps_calc_array[33];
static int fps_avg_pos = 0;
static float fps;

last_ticks = ticks;
ticks = SDL_GetTicks();

/* Draw */

...
fps_avg_pos++;
fps_avg_pos &= ~0x20;

fps_calc_array[fps_avg_pos] = ticks - last_ticks;

fps_calc_array[32] = 0;
for(i=0; i<32; i++) fps_calc_array[32] += fps_calc_array;

fps = 1000.0f / ((float)fps_calc_array[32] / 32.0f);
}

Rolling average of fps over last 32 frames. SDL_GetTicks() is equivalent to GetTickCount()
as for useing this in printf() just use fps() as the integer %d.

if you want to use this with some type of printing in opengl just use sprintf() to append the fps() value to your string.

http://www.lectersoft.com
http://www.lectersoft.com

This topic is closed to new replies.

Advertisement