Any clue why lines are not displayed?

47 Views Asked by At

Is there any clue why this code does not draw the two lines?

void renderScene(void) {
    glMatrixMode(GL_PROJECTION);    
    glOrtho(0.0, 1000, 0.0, 1000, 0, 0);   
    glClearColor(0,0,0.5,0);
    glClear(GL_COLOR_BUFFER_BIT); 
    glColor3f(1,1,1); 
    glBegin(GL_LINES);   
    glVertex2i(10, 70); 
    glVertex2i(900, 70);
    glVertex2i(500, 700);
    glVertex2i(500, 10);
    glEnd();    
    glutSwapBuffers();
    glFlush();
}
1

There are 1 best solutions below

0
Rabbid76 On

glOrtho does not simply set a matrix, but multiplies the current matrix by the new orthographic projection matrix. Since OpenGL is a state engine, the matrix is kept across frames, so the matrix is changed gradually. You must load the identity matrix before you can define the projection matrix with glLoadIdentity:

glMatrixMode(GL_PROJECTION);  
glLoadIdentity();   
glOrtho(0.0, 1000, 0.0, 1000, 0, 0);