什么在VertexAttribute()在libgdx用于第三个参数? [英] Whats the 3rd argument in VertexAttribute() used for in libgdx?
问题描述
干草,我会通过libgdx的wiki上的基础教程,我经行很困惑
Hay, I'm going through the basic tutorial on libgdx's wiki, and I'm confused by the line
new VertexAttribute(Usage.Position, 3, "a_position"));
什么是用于字符串a_position?
What is the string "a_position" used for?
推荐答案
网格类的工作与OpenGL ES的1.x和2.0。在OpenGL ES的1.x中使用固定功能管线(无着色器)。这里的属性不具有任何用途。在OpenGL ES 2.0的你写的所谓的顶点和片段着色器。如果你发送一个网格(或者更确切地说,它的顶点)到你的顶点/片段着色器对,着色器必须有一种方式来确定具体的顶点属性,比如顶点位置,纹理坐标,颜色等。
the Mesh class works with OpenGL ES 1.x and 2.0. In OpenGL ES 1.x you use a fixed function pipeline (no shaders). Here the attribute does not have any use. In OpenGL ES 2.0 you write so called vertex and fragment shaders. If you send a Mesh (or rather its vertices) to your vertex/fragment shader pair, your shaders have to have a way to identify specific vertex attributes, say the vertex position, texture coordinates, colors and so on.
着色器写在一个语言GLSL叫。顶点着色器看起来是这样的:
Shaders are written in a language called GLSL. A vertex shader could look like this:
attribute vec4 a_Position;
attribute vec4 a_Normal;
attribute vec2 a_TexCoord;
uniform mat4 u_projView;
varying vec2 v_texCoords;
varying vec4 v_color;
void main() {
v_color = vec4(1, 0, 0, 1);
v_texCoords = a_TexCoord;
gl_Position = u_projView * a_Position;
}
正如你可以看到有所谓的属性,它们是完全一样libgdx VertexAttributes。第三个参数因此是一个VertexAttribute的名称作为着色器使用(在libgdx因此ShaderProgram,如果您使用的方便,而不是直GLES 2.0函数去)。
As you can see there are so called attributes which are exactly the same as VertexAttributes in libgdx. The 3rd parameter is thus the name of a VertexAttribute as used in a shader (and hence ShaderProgram in libgdx, if you use that for convenience instead of going with straight GLES 2.0 functions).
心连心,
马里奥
hth, Mario
这篇关于什么在VertexAttribute()在libgdx用于第三个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!