Time Duration

Hi,

I want to ask if anyone know if it’s possible in OpenGL to have a shape (e.g Square) show up for a certain time period (e.g. 1 sec) then disappear, and then another shape (e.g Circle) will show up for a certain time period (e.g. 2 secs) before it disappear? And if so, what steps or code that I need to include for that to happen?

Right now, all I can get to display so far is the shapes that display together at the same time (overlapping each other). And when I used glClear in a loop only the last shape appeared.

I am learning OpenGL by myself and have been struggling at this problem for quite a while now. Also, I have been searching everywhere, and I haven’t able to find what I wanted. So any help will be greatly appreciated.

Thank you in advance.

opengl only draw from the commands you send.
a simple ways to do what you want is :

-glClear
-drawSquare()
-swapbuffers
-wait 1 sec

-glClear
-drawCircle
-swapbuffers
-wait 2 sec

-glClear
-swapbuffers

A more realistic approach is have a state in your program, listing what has to be drawn, that changes over time, for example with a timer.
that way you can draw the scene in a continuous loop or every time you receive events such as window uncovered/resized/… etc, testing the state to decide what to draw.

if (state == mustdrawsquare) then drawSquare
else if (state == mustdrawcircle) then drawcircle
else then glClear

Does it helps ?

Thank you for your help. I tried to implement what you have stated, but it doesn’t seem to work very well. I think it is due to the timer function not working correctly.

My next question is if anyone know if OpenGL has a ready-made timer function to use where all I need is to specify the time duration in millisecond for each shape? What I’m referring to is something similar to the WaitSec() function in Matlab & PTB.

Thank you.

OpenGl has no timer functions. Use the timer of your OS or programming language standart library (it it has one)