This is the way I expect it to work.
When you are using OpenGL, at some point you say to the system, “I have a vertex.” You can do this either by using the attribute location 0 or by using glVertex*. These two statements are roughly equivalent. If you want to draw a vertex, you use one or the other, not both, since that triggers the creation of two vertices. This is what you found and how it is supposed to work.
It is my understading that you want to compute the vertex position based on a bunch of other attributes, not the data that you actually pass to glVertex*. Is this correct?
Here’s my example of what I think the solution is:
I want to compute the vertex position based on three attributes, a1, a2, and a3. I’m not going to use glVertex*, so a1 will be in attribute location 0. To render the vertex, I do something like this:
glBegin(...);
glVertexAttrib1f(a2_loc, a2_data);
glVertexAttrib1f(a3_loc, a3_data);
glVertexAttrib1f(a1_loc, a1_data); // this triggers the creation of a vertex
glEnd();
The shader looks something like this:
attribute float a1;
attribute float a2;
attribute float a3;
void main() {
gl_Position = gl_ModelViewProjectionMatrix*vec4(a1, a2, a3, 1.0);
// replace this with your actual computation of the vertex position
}
When OpenGL gets to the thrid glVertexAttrib1f command, it creates a vertex with the attributes (a1,a2,a3) == (a1_data, a2_data, a3_data). Once you are in your shader, you can do whatever you want with those values.
Theoretically, you could replace the call to glVertexAttrib1f(a1_loc, a1_data) with a glVertex1f(a1_data). In the vertex shader you could use gl_Vertex.x instead of a1.
I hope this helps…