使用opengl显示3D点 [英] Display 3D point using opengl

查看:156
本文介绍了使用opengl显示3D点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,我只是想显示一个 3d 点,但是什么都没显示!

Simply, I am just trying to show a 3d point but nothing show on!

如何显示?下面的代码有什么问题,任何人都可以帮忙吗?

How to show it? what is wrong in the code below, anybody can help?

init:

void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glOrtho(-200, 0.0, -50, 100, 70, 300);
}

显示:

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPointSize(2);
    glBegin(GL_POINTS);
    glVertex3f(-120.0, 25.0, 0.0);
    glEnd();

    glutSwapBuffers();
}

重塑:

  void reshape(int w, int h)
    {
        glViewport(0, 0, (GLsizei)w, (GLsizei)h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(-120, 25, 0.0, -120, 25, 150, 0, 1, 0);
    }

推荐答案

reshape 函数中,您将近平面和远平面分别设置为1.0和20.0:

In the reshape function you set a near and far plane of 1.0, respectively 20.0:

gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);

所有不在近平面和远平面之间的几何都将被裁剪.

All the geometry which is not in between the near and the far plane is clipped.

这意味着从点到视点的z距离(眼睛坐标)必须在1.0到20.0的范围内.

This means that z distance from the point to the point of view (eye coordinate) has to be in the range from 1.0 to 20.0.

该点的z坐标为0.0:

The z-coordinate of the point is 0.0:

glVertex3f(-120.0, 25.0, 0.0);

视点(相机)的z坐标也为0.0(

The z coordinate of the point of view (camera) is 0.0 too (3rd parameter of gluLookAt):

gluLookAt(-120, 25, 0.0, -120, 25, 150, 0, 1, 0);

这将导致视点(眼睛)与该点之间的距离为 0-0 = 0 ,并且该点被裁剪.

This causes that the distance between the point of view (eye) and the point is 0-0 = 0 and the point is clipped.

要解决此问题,您必须更改该点的z坐标:

To solve the issue, either you have to change the z coordinate of the point:

glVertex3f(-120.0, 25.0, 5.0);

或观点:

gluLookAt(-120, 25, -5.0, -120, 25, 150, 0, 1, 0); 

这篇关于使用opengl显示3D点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆