How to get the current time?

Hi,

I want to render the object continuously.
For example, after every 10 sec, the new object will be appear. But how i can get the every 10 sec?..
Here the logic idea of my code.

for (int p=2; p<7; p++)
{
if (timer.GetTime()/1000 > 0 && timer.GetTime()/1000 < 10 )
{
draw( object[i].model_id, object[i].trans, shadowsNo );
}
if (timer.GetTime()/1000 > 10 ||timer.GetTime()/1000 >= 20||timer.GetTime()/1000 >= 30 )
{
shadowsNo=pow(2.0,p);
draw( object[i].model_id, object[i].trans,shadowsNo );
}
}

so, how i want to know the current time is already 10 sec, more than 10 second. Any idea how i can retrive the value.

i also print the current time …

//Print time
static char timeString[32];
float t= timer.GetTime()/1000;
sprintf_s(timeString," Time %.2f",t);
glColor3f( 0.0, 0.0, 0.0 );
x = -0.5;
y = -0.98;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

glTranslatef( x, y, 0.0 );

/* draw red text on the polygon */
glColor3f(0.75, 0.0, 0.0);
glRasterPos2i(0.0, 0.0);
for (int i=0; i<(int)strlen(timeString); i++) {
if(timeString[i] != ’
’ ) {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, timeString[i]);
}
else {
glTranslatef(0.0, -0.07, 0.0);
glRasterPos2i(0.0, 0.0);
}
}

Anybody can help me?

OpenGL don’t care about time or timer, it’s only about drawing.

If you need the timer you must ask to the framework you are using.
In glut glutGet(GLUT_ELAPSED_TIME) return the number of millisecond since glutInit
In SDL the function is SDL_GetTicks()

If you are not using a framework you must ask to your O.S.

Windows user can use GetLocalTime. This Function expects a pointer to a structure from type SYSTEMTIME.


SYSTEMTIME time;
GetLocalTime(&time);
...

But if you make something like this here


SYSTEMTIME time;
GetLocalTime(&time);
if(time % 500)
{
   clear buffer
   opengl drawing 
   swap buffer
}

Then you will see only every 500 millisecond whats going on.
Better you render your progress into a final texture that you display everytime but the results a written every nth millisecond into the texture.


SYSTEMTIME time;
GetLocalTime(&time);
if(time % 500)
{
    enable rendertarget1
    draw stuff1
    disable rendertarget1
}
else if(time % 250)
{
    enable rendertarget2
    draw stuff2
    disable rendertarget2
}

draw final texture

regards,
lobbel