OpenGL 2.0 define custom vertex attributes
I am working with an application which uses OpenGL 2.0.
I have vertex data, I have index data and I render both via a glDrawElements.
I am also using a custom vertex and fragment shader.
The vertex data consists of only:
glVertexPointer(4, GL_FLOAT, stride, offsetV);
glTexCoordPointer(4, GL_FLOAT, stride, offsetT);
glColorPointer(4, GL_FLOAT, stride, offsetC);
My problem is, I would like to define another attribute per vertex which is not part of the fixed function pipeline.
How could I do this? I know, I could just abuse one of the other pre-defined attributes like "glSecondaryColorPointer" but if possible I would rather define my own attribute which I can add to my vertex data.
Thank you very much for the great help.
You define the attribute in the vertex shader, as a global variable with an "in" qualifier. You can optionally use a layout qualifier to specify the index, or use glGetAttribLocation() in the application. The data for the attribute is provided using glVertexAttribPointer().
Originally Posted by Cornix
Wow, thank you. This is much simpler then I originally thought.
Be warned: the aliasing of generic attribute locations to legacy built-in attribute locations is undefined. So if you use a layout qualifier (or glBindAttribLocation) it is your responsibility to carefully choose a location that will not collide (see ARB_vertex_program, circa 2002, Table X.1, "Generic and Conventional Vertex Attribute Mappings".)
Generally, it is simpler if you convert everything to generic attributes.
Yes, thank you. I was thinking about that already, just removing the build-in attributes and only using my own now that I know that I can do this.