PDA

View Full Version : Game rendering



10-01-2001, 09:54 AM
In games with every machine you play it the game goes same speed. how you do it?
Mean that like in CS on fast machines game runs about 100 FPS in lower end machines it runs 20 FPS but the game time goes sameway. It has something to do with rendering something=)
Please help me. I cannot sleep...

Fredy
10-01-2001, 09:57 AM
Solution: timer

10-01-2001, 10:20 AM
I would really like to see one code example with working timer...
In glut with windows and linux compatible...

10-01-2001, 10:53 AM
I would really like to see one code example with working timer...
In glut with windows and linux compatible...

Gelero
10-01-2001, 11:04 AM
yeah! me too!

Nutty
10-01-2001, 11:22 AM
#include <windows.h>

static LARGE_INTEGER time, last_time, diff, frequency;
float g_frame_time; //In seconds!
float g_frame_rate;

void Render(void)
{

//Render stuff here!

}

void CalcFrameTime(void)
{
GLfloat frame_time;

last_time = time;
QueryPerformanceCounter(&amp;time);

diff.QuadPart = time.QuadPart - last_time.QuadPart;
frame_time = (GLfloat)diff.QuadPart / (GLfloat)frequency.QuadPart;

g_frame_time = frame_time;
g_frame_rate = 1.0f / frame_time;
}

void Update(float d_time)
{

//Move all game objects and cameras based on d_time here.

//For example. To move 1 metre a second. Move the camera with a vector of 1,0,0 multiplied
//by d_time.

}

void main(void)
{

QueryPerformanceCounter(&amp;last_time);
QueryPerformanceCounter(&amp;time);
QueryPerformanceFrequency(&amp;frequency);
//Set iniitial frame time to 0.
g_frame_time = 0.f;

while(1)
{

CalcFrameTime();


Update(g_frame_time);

Render();





}
}


hope this helps.

Nutty

pATChes11
10-01-2001, 04:54 PM
That's Win32 code... it wouldn't work under Linux and Windows... Still useful, and is certainly something that I needed for a simple and fast OpenGL app http://www.opengl.org/discussion_boards/ubb/smile.gif