1
$\begingroup$
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_LINES);
    glVertex3d(0.75, 0.25, 0.0);
    glVertex3d(0.75, 0.25, -0.75);
    glEnd();
    glFlush();
}

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

I should be able to see line from (0.75, 0.25, 0.0) to (0.75, 0.25, -0.75), but I can't see anything on the screen.

However, I'm able to see the line using snippet below

glVertex3d(0.35, 0.25, 0.0);
glVertex3d(0.75, 0.25, -0.75);

Can anyone explain this behavior?

$\endgroup$
2
  • 1
    $\begingroup$ This projection is a 2d projection, with the Z axis pointing into your screen. When both vertices with the same X&Y are projected to screen space they will occupy the same screen coordinate so your line will either be 1 pixel or invisible. $\endgroup$
    – PaulHK
    Jul 5 '17 at 3:20
  • $\begingroup$ @PaulHK You should write that as an answer. Please avoid writing answers as comments, because they might get lost. Comments are for temporary messages only. $\endgroup$
    – Dan Hulme
    Jul 5 '17 at 7:52
4
$\begingroup$

This projection is a 2d projection, with the Z axis pointing into your screen. When both vertices with the same X&Y are projected to screen space they will occupy the same screen coordinate so your line will either be 1 pixel or invisible.

If you are expecting a difference in screen position from those 2 coordinates then you need a perspective projection.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy