Hi,
I am new to OpenGL. I am working on a project where I need to read data from a input file, store coordinates in an array and then draw the image by using GL_LINE_STRIP and coordinates in the array. I also need to pause after each line is drawn so you can see the image being rendered line by line with about 0.3 second pause after each line.
I have everything finished, the problem I have is with the whole animation of lines. It hangs for a while and then draws the whole image at once, without any delay after each line.
void main(int argc, char** argv)
{
PromptFileName();
CreateArray();
ReadData();
init_window(argc,argv);
other_init();
glutMainLoop();
}
void init_window(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_RGB);
glutInitWindowSize(500,400);
glutInitWindowPosition(0,0);
glutCreateWindow("2A");
}
void other_init()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3d(0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2026.0, 2026.0, -2026.0, 2026.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
for (int i=0; i<arraySize; i++){
sleep( (clock_t) (0.3 * CLOCKS_PER_SEC ));
glColor3f(i/10.0, 1.0, 0.0);
//arrayPtr has the coordinates
if (arrayPtr[i][3] == 1) // if this row is marked as jump
{
if (i != 0)
glEnd();
glBegin(GL_LINE_STRIP);
}
// draw a line strip
glVertex3f(arrayPtr[i][0], arrayPtr[i][1], 0.0);
glFlush(); // clear buffers
sleep( (clock_t) (0.3 * CLOCKS_PER_SEC ));
}
glEnd();
glFlush();
}
Thank you.
-Tom