PDA

View Full Version : What's the purpose of glVertexPointer?



kaufenpreis
11-19-2014, 06:06 AM
I was looking at the Particles examples of CUDA and I couldn't find where to they make the link between the array of vertices and the variables in the shader. From what I've read and actually the way I've been doing it is

...
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData( ... )
glEnableVertexAttribArray(0);
glVertexAttribPointer( ... );
...

however what I found in Nvidia's example looks like
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vbo);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);

if (m_colorVBO)
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_colorVBO);
glColorPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_COLOR_ARRAY);
}

glDrawArrays(GL_POINTS, 0, m_numParticles);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

which I believe is something similar to what I do. So my questions are
What's the difference between those two ways of passing data to the shader?
Should I prefer one over the other?

carsten neumann
11-19-2014, 09:19 AM
Before OpenGL supported generic vertex attributes there was a fixed set of them that you could specify (position, normal, color, secondary color, N sets of texture coordinates) and each had a corresponding gl{name}Pointer function. When shaders where introduced these specific vertex attributes where/are available through built-in variables (gl_Vertex, gl_Normal, gl_Color, ...) in the vertex shader.
Now, with generic vertex attributes it is not possible to have the attribute name as part of the function, so essentially all these functions where superseded with glVertexAttribPointer(i, ...) where the argument i is used to identify which attribute is meant.