I am trying to display 3d point (50,30,20) using opengl but noting is displayed on the screen. How can I solve it?
init:
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(20.0, 70.0, 10.0, 40.0, 10.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Display:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPointSize();
glBegin(GL_POINTS);
glVertex3f(50.0, 30.0, 20.0);
glEnd();
glFlush();
glutSwapBuffers();
}
Your point is clipped by the near plane of the orthographic projection:
glOrtho(20.0, 70.0, 10.0, 40.0, 10.0, 30.0);
glVertex3f(50.0, 30.0, 20.0);
The OpenGL coordinate system is a right handed system (see Right-hand rule ). In view space the y axis points upwards and the x axis points to the right. Since the z axis is the Cross product of the x and y axis, it points out of the view.
Hence you've to shift the point along the negative z axis in between the near and far plane:
glVertex3f(50.0, 30.0, 20.0);
glVertex3f(50.0, 30.0, -20.0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.