PDA

View Full Version : OpenGL 2.0 define custom vertex attributes



Cornix
10-28-2013, 04:05 PM
Hi there.

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);
and
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.

GClements
10-28-2013, 06:05 PM
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?
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().

Cornix
10-29-2013, 03:11 AM
Wow, thank you. This is much simpler then I originally thought.

arekkusu
10-29-2013, 10:14 AM
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.

Cornix
10-29-2013, 10:20 AM
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.