How to give time delay for animation ....

Hello guys…
it will be a great help if someone can tell me how to give a pause or delay in the display function. if possible provide a link for an example -like a simple example of a point moving in 3d space .

OpenGL doesn’t have a “display function”. Also, being able to do what you ask has nothing to do with animating a point moving in space.

actually i was talking about display function using glut.the callback function of Glutdisplayfunc . can i add a delay there?

If you want to pause an animation, simply don’t update it. With GLUT, you’d normally implement animation by registering a callback function with glutTimerFunc(). The callback updates the animation state then calls glutPostRedisplay(). To pause, you’d just have the callback return immediately without either updating the state or requesting redisplay.

Thanx for the help.
I have tried to build a very simple code in which a vertical line moves along the x axis.
here is the code:

#include<Myheader.txt>

float i=0;
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex3f(10i,1, 0.0);
glVertex3f(10
i,50,0.0);
glEnd();
glutSwapBuffers();
i=i+0.1;
if(i>10)
{i=1;}
//glutPostRedisplay();
}
void makedelay(int)
{
Draw();
glutTimerFunc(40,makedelay,1);
}

void Initialize() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
}

int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(50, 50);
glutCreateWindow(“XoaX.net”);
Initialize();
//glutDisplayFunc(Draw);
glutTimerFunc(40,makedelay,1);
glutMainLoop();
return 0;
}

note that i have not registered a callback for glutDisplayfunc is it ok?

No.

You should not use rendering functions outside of the display function. Other functions (e.g. timer and idle functions) should simply call glutPostRedisplay() if they want the display to be redrawn.

You should always register a display function which redraws the window. This will be called whenever redraw is required, either because the application requested it with glutPostRedisplay() or because the OS requested it (e.g. because the window was obscured then exposed).

[QUOTE=GClements;1251806]No.

You should not use rendering functions outside of the display function. Other functions (e.g. timer and idle functions) should simply call glutPostRedisplay() if they want the display to be redrawn.

You should always register a display function which redraws the window. This will be called whenever redraw is required, either because the application requested it with glutPostRedisplay() or because the OS requested it (e.g. because the window was obscured then exposed).[/QUOTE]

ok thanx…

But if my display function is like this
display()
{

draw1();
draw2();
draw();

};

and i only want to delay drawing the draw2 function.
how to do that. Please help. I might me asking very silly questions. please ignore.

When your display function is called, the contents of buffers are undefined, so you have to draw everything. You cannot rely upon the OS preserving the contents of the front buffer, and the contents of the back buffer are undefined after calling glutSwapBuffers() (it may copy the back buffer to the front buffer, it may swap the front and back buffers, it may do something else entirely).

[QUOTE=qawded;1251761]Hello guys…
it will be a great help if someone can tell me how to give a pause or delay in the display function. if possible provide a link for an example -like a simple example of a point moving in 3d space .[/QUOTE]

if you really want to delay just do this:

#include <time.h>
void delay(float secs)
{
	float end = clock()/CLOCKS_PER_SEC + secs;
	while((clock()/CLOCKS_PER_SEC) < end);
}

[QUOTE=sandbucket;1252271]if you really want to delay just do this:

#include <time.h>
void delay(float secs)
{
	float end = clock()/CLOCKS_PER_SEC + secs;
	while((clock()/CLOCKS_PER_SEC) < end);
}

[/QUOTE]

actually this wont work. the variables are not accurate enough. it will work for large delays but thats all, not very useful.

[QUOTE=qawded;1251878]But if my display function is like this


display()
{
    draw1();
    draw2();
    draw();
}; 

and i only want to delay drawing the draw2 function.[/QUOTE]

Try putting a Sleep function in draw2(). Like this --> Sleep (5000);
This will pause execution of draw2 for 5 seconds.
Sleep (100) would pause execution for 0.1 seconds.