【问题标题】:Whats the 3rd argument in VertexAttribute() used for in libgdx?在 libgdx 中使用的 VertexAttribute() 中的第三个参数是什么?
【发布时间】:2011-04-28 07:06:47
【问题描述】:

嘿,我正在浏览 libgdx 的 wiki 上的基本教程,我被这行弄糊涂了

new VertexAttribute(Usage.Position, 3, "a_position"));

字符串“a_position”是干什么用的?

【问题讨论】:

    标签: java android libgdx


    【解决方案1】:

    Mesh 类适用于 OpenGL ES 1.x 和 2.0。在 OpenGL ES 1.x 中,您使用固定功能管道(无着色器)。这里的属性没有任何用处。在 OpenGL ES 2.0 中,您编写所谓的顶点和片段着色器。如果您将 Mesh(或更确切地说是其顶点)发送到您的顶点/片段着色器对,您的着色器必须有一种方法来识别特定的顶点属性,例如顶点位置、纹理坐标、颜色等。

    着色器是用一种称为 GLSL 的语言编写的。顶点着色器可能如下所示:

    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 函数)。

    hth, 马里奥

    【讨论】:

    • 因此,第三个参数可以是任何单词。我们将哪个传递到 ShaderProgram?我可以称它为“funbags”,这样行吗?
    【解决方案2】:

    查看VertexAttribute的文档

    【讨论】:

    • 它说“ShaderProgram中使用的属性的别名”,什么意思?
    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多