c++ - QT OpenGL无法完全渲染立方体吗?

标签 c++ qt opengl rendering opengl-compat

我正在尝试创建和显示3D正方形,但是由于某种原因,当我渲染它时,它的一部分丢失了:

void DrawCube::drawCubes(int amount){ 



      glBegin(GL_POLYGON);
        glVertex3f( 1.0, -1.0,  1);
        glVertex3f( 1.0, -1.0, -1);
        glVertex3f( 1.0,  1.0, -1);
        glVertex3f( 1.0,  1.0,  1);
        glEnd();


      glBegin(GL_POLYGON);
        glVertex3f(-1.0, -1.0, -1);
        glVertex3f( 1.0, -1.0, -1);
        glVertex3f( 1.0,  1.0, -1);
        glVertex3f(-1.0,  1.0, -1);
      glEnd();


      glBegin(GL_POLYGON);
        glVertex3f(-1.0, -1.0, 1);
        glVertex3f( 1.0, -1.0, 1);
        glVertex3f( 1.0,  1.0, 1);
        glVertex3f(-1.0,  1.0, 1);
      glEnd();


      glBegin(GL_POLYGON);
        glVertex3f( -1.0, -1.0,  1);
        glVertex3f( -1.0, -1.0, -1);
        glVertex3f( -1.0,  1.0, -1);
        glVertex3f( -1.0,  1.0,  1);
      glEnd();
  }

}

rendering problem

我不是在寻找只给我代码的答案,而是在解释造成这种感谢的原因。

最佳答案

立方体似乎被投影的远平面夹住了。通过 glOrtho 设置投影矩阵时,增加到远平面的距离。
请注意,投影矩阵定义了 View 体积(请参见3D projection)。裁剪了超出查看体积的所有几何图形。

关于c++ - QT OpenGL无法完全渲染立方体吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59361926/

相关文章:

c++ - 在 STL Multimap 中将自己的对象作为数据

c++ - 为什么对象在插入集合后会被删除?

c++ - 此应用程序启动失败,因为它找不到或加载 Qt 平台插件 "windows"

c++ - 在 Windows 7 下的 Qt 5.5.1 应用程序中使用 RInside

c++ - 使用 glReadPixels 时是否可以不限制数据?

c++ - 如何在 C++ 中将类类型映射到该类的实例?

c++ - 如何在字符串中找到一个字符串并替换它?

Qt 国际化 : What do you use as source text in your Qt application?

c++ - 函数类型不是模板非类型参数的有效类型?

c++ - OpenGL VBO 法线/光照问题