I am new to the open GL.i am facing problem in implementing delay.I am using open GL ES 1.0. What i am trying to do is to scale up an image and wait for few seconds and bring it to back to original one.But it is waiting for some time and doing both scale up and down simultaneously.Please help me in solving this .I used two for loops for implementing delay.Is there any function for delay or sleep in open GL ES 1.0.
I guess it is not related operating system.Anyways i am using linux OS ,eclipse IDE and android SDK.code is like
scale up i.e glscalef()
sleep or wait
scaledown
so it has to display output with scaled image and then wait and then scaled down output…but actually what happening is it is waiting for some time and displays scaled up and scaled down outputs simulatenously with out any delay
Usually, you draw in the back buffer. It will not be shown untill you swap the back buffer with the front buffer. Otherwise, the user would have seen when the sreen is cleared, and when various drawing operations are completed.
So if you draw in the back buffer, then delay, then draw some more, and then eventually swap the back buffer with the front buffer, then the user will not see any changes until the end.
I would recommend that use an algorithm as follows:
while(1) {
switch(CurrentState()) {
case NormalScale: DrawNormalScale(); break;
case Enlarged: DrawLargeScale(); break;
}
SwapBackBuffer();
}
You need to set the value of state from a time depending function. Of course, if you want to be fancy, you can have a gradual change of scale instead of two distinct modes.
Thanks 4 ur suggestion.It looks fine.But can u illustrate on implementing swap buffer function.or is it a predefined function which is available in open gl library…
Swapping buffers is not part of the OpenGL API. It depends on the environment you are in. For the glut library, there is glutSwapBuffers(). For the glfw library, there is glfwSwapBuffers(). For your environment, I don’t know.
It may depend on how your main loop is handled. If you use glut, for example, you don’t really have control of the main loop (unless glfw, which I prefer).
No - swap buffers is not an OpenGL command, it is an operating system command. You need to read some documentation and work out what the command for swapping buffers on your operating system is.