johnbakers
johnbakers

Reputation: 24771

Attempting to render 2D points in 3D space

What does OpenGL do when it encounters this:

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. Now if I setup my projection matrix using Ortho, I can get these vertices to draw. 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?

Upvotes: 1

Views: 165

Answers (2)

damphat
damphat

Reputation: 18966

Look at your shader program that you have bound to opengl before glVertexAttribPointer. You will see that your 2D points [x, y] are treat as vec4[x, y, z, w].

  • if you do not supply w it will be 1 by default.
  • if you do not supply z it will be 0 by default.

If you do not see the point on screen, that mean it is outside frustum.

Upvotes: 1

Thomas
Thomas

Reputation: 182083

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.

To solve this, you could modify your vertex shader to set the z-coordinate explicitly to a constant value (or supplied by a uniform).

Or, depending on how many points you have and your memory requirements, you could just supply an explicit z value from the beginning:

glVertexAttribPointer(m_shader_position, 3, ....

Upvotes: 1

Related Questions