LIne not displaying with glFrustum()?

167 Views Asked by At

I was trying to draw a line on the window but it is not displaying with glFrustum(). I have used the same code with glOrtho() it does display the line. Is there anything else I need to set up for my line to show up on set window?

void init() {
  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum( -2.0,2.0,-2.0,2.0, 1.0, 20.0 );
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

 void display() {
  glBegin(GL_LINES);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(0.0f, 0.0f, 2.0f);
    glVertex3f(1.0f, 1.0f, 5.0f);
  glEnd();
 }
1

There are 1 best solutions below

2
Yakov Galka On

In OpenGL the camera looks along the negative Z axis. Therefore, your line is behind the camera, and thus it's getting clipped.

Instead draw it at the front:

glVertex3f(0.0f, 0.0f, -2.0f);
glVertex3f(1.0f, 1.0f, -5.0f);