c++ - OpenGL:绘制多边形时,如果第一个顶点位于屏幕空间之外怎么办(三角扇)

标签 c++ macos opengl

我正在关注 Sumanta Guha 第二版的Computer Graphics Through OpenGL,第二版,在第 35 页,它说

Raising the first vertex of (the original) square.cpp from glVertex3f(20.0, 20.0, 0.0) to glVertex3f(20.0, 20.0, 1.5) causes the square – actually, the new figure which is not a square any more – to be clipped. If, instead, the second vertex is raised from glVertex3f(80.0, 20.0, 0.0) to glVertex3f(80.0, 20.0, 1.5), then the figure is clipped too, but very differently from when the first vertex is raised. Why? Should not the results be similar by symmetry?

Hint: OpenGL draws polygons after triangulating them as so-called triangle fans with the first vertex of the polygon the center of the fan. For example, the fan in Figure 2.16 consists of three triangles around vertex v0.

相应的代码如下

  glVertex3f(20.0, 20.0, 0.0);
  glVertex3f(80.0, 20.0, 0.0);
  glVertex3f(80.0, 80.0, 0.0);
  glVertex3f(20.0, 80.0, 0.0);

如果我只将第一个顶点的 z 轴设置为 1.5f,我会得到这样的输出,

enter image description here

如果我仅将第二个顶点的 z 轴设置为 1.5f,则会得到以下输出

enter image description here

在后一种情况下,我可以理解为什么我会因为剪辑而得到该输出,但我不明白为什么我会在前一种情况下得到该输出。

最佳答案

您正在绘制两个三角形:A、B、C 和 A、C、D。

如果更改其中一个顶点的一个 z,两个三角形将不再位于同一平面内。

在第一种情况下,您更改 A 会影响两个三角形。在第二种情况下,您要更改 B,这只会影响第二个三角形。

请注意,您使用的代码已经严重过时,并且无法在 OpenGL 的现代核心配置文件中工作,其中“现代”的意思是:自十年 .

关于c++ - OpenGL:绘制多边形时,如果第一个顶点位于屏幕空间之外怎么办(三角扇),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46013073/

相关文章:

iPhone:在应用程序中同时使用 OpenGL 和 native 用户界面的最佳方式是什么?

c++ - C : display every x milliseconds (OpenGL)

c++ - float 不等式是否保证一致

c++ - 用户定义预声明的全局常量

macos - 如何以编程方式拦截 OSX (10.8) 打印命令?

c++ - 在 Qt Creator 中设置 OSX 的应用程序图标

c++ - 如何在 C++ 中创建和使用实例数组?

c++ - C++03 12.4/12 中关于通过指针显式调用基类析构函数的说法是什么?

safari - 如何让 XCode/GDB 融入 Safari 5.1 NPAPI 插件?

opengl - 为什么 OpenGL + GLSL 着色器不输出任何内容?