Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of glVertexPointer?

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

  1. What's the difference between those two ways of passing data to the shader?
  2. Should I prefer one over the other?
like image 808
BRabbit27 Avatar asked Oct 21 '25 11:10

BRabbit27


1 Answers

The first way is the modern, generic way of sending attributes. The second one is older, where vertices, normals, colors etc. had their own hard-coded attributes. It should not be used in modern code.

like image 113
SurvivalMachine Avatar answered Oct 23 '25 06:10

SurvivalMachine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!