سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

See the doc for VertexAttribute

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top