简体   繁体   English

尝试在3D空间中渲染2D点

[英]Attempting to render 2D points in 3D space

What does OpenGL do when it encounters this: OpenGL遇到这种情况时会做什么:

glVertexAttribPointer(m_shader_position, 2, ....

But the projection matrix is a Frustum, not orthogonal? 但是投影矩阵是平截头体,不是正交的吗?

The 2 in this function indicates this is a 2D vector. 此函数中的2表示这是2D向量。 Now if I setup my projection matrix using Ortho, I can get these vertices to draw. 现在,如果使用Ortho设置投影矩阵,则可以绘制这些顶点。 But if I merely change the projection to a Frustum, they no longer appear, but what is the technical cause of this? 但是,如果我仅将投影更改为平截头体,它们将不再出现,但这是什么技术原因?

A frustum indicates a 3D view, but what part of the pipeline prevents a 2D vertex from appearing? 截锥体表示3D视图,但是管线的哪一部分阻止2D顶点出现?

If you leave off the z-coordinate like this, it defaults to 0. If your vertices (after transformation) are outside the frustum, they won't be drawn. 如果不这样设置z坐标,则默认为0。如果顶点(在变换之后)在视锥之外,则不会绘制它们。

To solve this, you could modify your vertex shader to set the z-coordinate explicitly to a constant value (or supplied by a uniform). 为了解决这个问题,您可以修改顶点着色器,以将z坐标显式设置为恒定值(或由统一提供)。

Or, depending on how many points you have and your memory requirements, you could just supply an explicit z value from the beginning: 或者,根据您拥有的点数和内存要求,您可以从一开始就提供一个明确的z值:

glVertexAttribPointer(m_shader_position, 3, ....

Look at your shader program that you have bound to opengl before glVertexAttribPointer. 在glVertexAttribPointer之前,请先查看已绑定到opengl的着色器程序。 You will see that your 2D points [x, y] are treat as vec4[x, y, z, w]. 您将看到您的2D点[x,y]被视为vec4 [x,y,z,w]。

  • if you do not supply w it will be 1 by default. 如果不提供w,则默认为1。
  • if you do not supply z it will be 0 by default. 如果不提供z,则默认为0。

If you do not see the point on screen, that mean it is outside frustum. 如果您在屏幕上看不到该点,则表示该点在视锥之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM