PDA

View Full Version : Game timer !!



Ikhan
11-30-2011, 08:43 AM
Hello Folks !! :)

Is there any way to get the inbuilt timer of OpenGL !!

I want to implement stop timer in game, any idea how to implement..

And one silly question, where will be the glutBitmapCharacter() displayed !!

Out Of Time, pl reply soon !!!

carsten neumann
11-30-2011, 09:39 AM
Is there any way to get the inbuilt timer of OpenGL !!


No, there is no built in timer in OpenGL. There are timer queries, in case that is what you were thinking of, but those are used to get information about how long it takes OpenGL to process (parts of) the command stream.

glutBitmapCharacter draws at the current OpenGL raster position, see glRasterPos().

PS: if you are in such a hurry, you can get the answer to your second question much faster by looking up the man page for glutBitmapCharacter() ;)

BionicBytes
11-30-2011, 10:14 AM
I want to implement stop timer in game, any idea how to implement..

Windows is event driven. Use a system timer.
Failing that, you could use GLUT timers if you are using Glut.
Failing all of the above, in the game loop read the real time clock and at X milliseconds from time Y, process an event.

Ikhan
12-01-2011, 03:10 AM
Sorry for wrong interpretation, "stop timer" i actually mean a timer which keeps on ticking until the player reaches the destination..

Can you give some pointers on how to use it and i want to be shown at the top right corner, should i use another viewport for that or how ??

BionicBytes
12-01-2011, 03:51 AM
i want to be shown at the top right corner, should i use another viewport for that or how ??

Setup an orthographic projection with a viewport.
Disable depth testing and enable blend.



actually mean a timer which keeps on ticking until the player reaches the destination
Like I said, track the system time.

Ikhan
12-01-2011, 05:11 AM
void showTime(){
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13,'T');
glPopMatrix();
glPopAttrib();
}

will this do ??

BionicBytes
12-01-2011, 06:43 AM
You need to add:
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);

Looks OK otherwise.

Ikhan
12-02-2011, 05:09 AM
Any idea on this post BionicBytes ??

http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=307000#Post3070 00