[LWJGL] glVertexAttribPointer() 1st parameter: Attribute List is AttribLocation?

In this tutorial series (link), it said we put the position coordinates in attribute list 0, color components in attribute list 1, and texture coordinates in attribute list 2.

I don’t understand the meaning of attribute list inputting 0, 1, and 2. Comparing it with Android OpenGL ES’s glVertexAttribPointer(), it looks like the “attribute list” refers to the attribute locations in the shader program.

Should the code be like this below in LWJGL?


int aPositionLocation = glGetAttribLocation(program, "a_position");
//...
glVertexAttribPointer(aPositionLocation, 0, ...);
//...

Or the meaning of “attribute list” refers to something else that the tutorial in the link isn’t really telling me? I may have missed the definition, or I still didn’t understand the definition…

I’ve never heard the term attribute list before, however it must just be another term for an attribute index. The attribute indices that it is referring to are in the vertex shader.


in vec4 in_Position;
in vec4 in_Color;
in vec2 in_TextureCoord;

Most hardware allows for up to 16 attribute indices per program object (also called a shader program). There are three ways to get or set the attribute locations. One way is to define the location in the shader. This is done like so:


layout(location = 0) in vec4 in_Position;
layout(location = 1) in vec4 in_Color;
layout(location = 2) in vec2 in_TextureCoord;

Then you would use 0, 1 and 2 respectively for the attribute locations.
Another way is the way that you showed. That’s getting the location which is automatically assigned to the attribute.
The third and final way is to set the attribute location in code, using [icode]glBindAttribLocation()[/icode].

Also, in case you didn’t know, you must enable the attribute index before calling glDrawArrays() or glDrawElements(), using [icode]glEnableVertexAttribArray()[/icode]. If you’re using >OpenGL3.0, then you should create and bind your own vertex array object, which stores the rendering states.

Attributes were used before we had [icode]layout(location = 0)[/icode] etc.

This would is how you use the OpenGL function in your shader program


public void init()
{
	glUseProgram(program);

        // Shader compile and uniform stuff
		
	GL20.glBindAttribLocation(program, 0, "position");
	GL20.glBindAttribLocation(program, 1, "texCoord");
	GL20.glBindAttribLocation(program, 2, "normal");
}

This would refer to position being in location 0, texCoord being in location 1, etc.

Your vertex shader would then be something like this:


#version 120

attribute vec3 position;
attribute vec2 texCoord;
attribute vec3 normal;

void main()
{
    // Do whatever here
}

Thank you for the info.

Then I would guess the term, “attribute list,” should be changed to something else?