If I have a buffer with my vertices, normals and texture coordinates, and I use glDrawArrays to draw the VBO to the screen, how can I send attributes per vertex that I placed in an array to the shader program? I'm making a voxel terrain, and every chunk is 1 VBO, this works all great, but I want to send the light value of each block (Just an array filled with int's) to the shader as well, how would I do that?

Edit: After reading some comments, here some clarification: I'm trying to avoid the deprecated glVertexPointer etc, so I'm using Vertex Arrays. Here is the layout of my vertex array:

X, Y, Z, NX, NY, NZ, X, Y, Z, NX, NY, NZ,X, Y, Z, NX, NY, NZ

I'm using this to draw it: (ofcourse with the array buffer bound)

glVertexAttribPointer(0, 3, GL_FLOAT, false, 12, 0);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 12, 12);

glDrawArrays(GL_TRIANGLES, 0, arraySize / 6);


However I get some weird shapes on my screen. Apart from the light problem, that is essentially the same thing, I don't get why this doesn't just work. When I remove the normals, and use just 1 vertexattribpointer it works fine. Yes, the attributes are bound to in_position and in_normal, and the vertex shader is nothing more than gl_Position = gl_ModelViewProjectionMatrix * vec4(in_position, 1.0);

Thanks!

This is what I get:

(This are 6X6 chunks, so this code is called 6*6 times.)

• possible duplicate of Access vertex data stored in VBO in the shader – MichaelHouse Mar 14 '13 at 18:09
• @Byte56: It's not quite the same thing. He's talking about getting more arbitrary data, not really per-vertex data. – Nicol Bolas Mar 15 '13 at 7:44
• @NicolBolas "...how can I send attributes per vertex..." Sounds like it's per-vertex no? – MichaelHouse Mar 15 '13 at 13:18
• @Byte56: "I want to send the light value of each block" Note the singular "value". A block is not a vertex. – Nicol Bolas Mar 15 '13 at 13:22
• @NicolBolas I suppose we're both correct then. OP may be implementing smooth lighting to have lighting information per vertex, or "blocky lighting" and having lighting per block. We'll just have to wait for more details. – MichaelHouse Mar 15 '13 at 13:27

glVertexAttribPointer(0, 3, GL_FLOAT, false, 12, 0);