PDA

View Full Version : How to link with input vertex data?



reader1
03-15-2015, 05:40 AM
This is a simple vertex shader,
in vec3 VertexPosition;
in vec3 VertexColor;
out vec3 Color;

void main()
{
Color =VertexColor;
gl_Position = vec4(VertexPosition,1.0);
}

Where is VertexPosition? from .cpp, we have positionData array, How to find the pointer VertexPositoin points to the data?

GClements
03-15-2015, 05:55 AM
Where is VertexPosition? from .cpp, we have positionData array, How to find the pointer VertexPositoin points to the data?
You can use glGetAttribLocation() after the program is linked to obtain the index for an attribute, or glBindAttribLocation() before the program is linked to set it to a specific value. Or you can use a layout(location=...) specifier in the variable's declaration to assign a specific index.

Arrays of data are associated with an attribute index using glVertexAttribPointer().

reader1
03-15-2015, 06:19 AM
You can use glGetAttribLocation() after the program is linked to obtain the index for an attribute, or glBindAttribLocation() before the program is linked to set it to a specific value. Or you can use a layout(location=...) specifier in the variable's declaration to assign a specific index.

Arrays of data are associated with an attribute index using glVertexAttribPointer().
Thank you very much for the porompt reply. I find an article about this issue, which is as same as your descriptoin