Whats the 3rd argument in VertexAttribute() used for in libgdx?

佐手、 提交于 2020-01-15 09:14:49

问题


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"));

What is the string "a_position" used for?


回答1:


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.

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;
}

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




回答2:


See the doc for VertexAttribute



来源:https://stackoverflow.com/questions/5814927/whats-the-3rd-argument-in-vertexattribute-used-for-in-libgdx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!