PDA

View Full Version : How to get the current time?

cikz04
07-07-2010, 02:39 AM
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 &amp;&amp; timer.GetTime()/1000 < 10 )
{
}
if (timer.GetTime()/1000 > 10 ||timer.GetTime()/1000 >= 20||timer.GetTime()/1000 >= 30 )
{
}
}

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 );

glMatrixMode( GL_MODELVIEW );

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] != '\n' ) {
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?

Rosario Leonardi
07-07-2010, 05:02 AM

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.

lobbel
07-07-2010, 05:39 AM
Windows user can use GetLocalTime. This Function expects a pointer to a structure from type SYSTEMTIME.

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

But if you make something like this here

SYSTEMTIME time;
GetLocalTime(&amp;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(&amp;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