Why not vec3 for OpenGL ES 2.0 gl

I am new to OpenGL ES 2.0, and cannot understand the following simplest shader:

attribute vec4 vPosition;
void main()
{
   gl_Position = vPosition;
}

My question is, since a position would be a vector of (x, y, z) , why is gl_Position a vec4 instead of vec3?


The w in vec4(x, y, z, w) is used for clipping, and plays its part while linear algebra transformations are applied to the position.

By default, this should be set to 1.0.

See here for some more info: http://web.archive.org/web/20160408103910/http://iphonedevelopment.blogspot.com/2010/11/opengl-es-20-for-iOS-chapter-4.html


如果直接在剪辑空间中将顶点提供给着色器,则只需传递x,y,z并在该着色器中添加1作为w组件。

attribute vec3 vPosition; // vec3 instead of vec4
void main()
{
   gl_Position = vec4 (vPosition, 1.0);
}
链接地址: http://www.djcxy.com/p/33602.html

上一篇: glUniform4fv给GL

下一篇: 为什么不用vec3来处理OpenGL ES 2.0 gl