显示 3d 点

Display 3d point

我正在尝试使用 opengl 显示 3d 点 (50,30,20),但屏幕上没有任何显示。我该如何解决?

初始化:

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();
 

}

显示:

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();
}

您的点被正投影的近平面裁剪:

glOrtho(20.0, 70.0, 10.0, 40.0, 10.0, 30.0);
glVertex3f(50.0, 30.0, 20.0);

OpenGL 坐标系是右手系(参见 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 的 x 轴和 y 轴,它指向视图外。
因此,您必须在近平面和远平面之间沿负 z 轴移动点:

glVertex3f(50.0, 30.0, 20.0);

glVertex3f(50.0, 30.0, -20.0);