Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am following this tutorial for rendering a cube in OpenGL ES 2 with GLKit and custom shaders. I am having some trouble understanding some things. Take a look at this code snippet:

Code:
 glGenBuffers(1, &_verticesVBO); 
    glBindBuffer(GL_ARRAY_BUFFER, _verticesVBO); 
    glBufferData(GL_ARRAY_BUFFER, sizeof(CubeVertexData), CubeVertexData, GL_STATIC_DRAW);     
    glBindBuffer(GL_ARRAY_BUFFER, 0);     
    
    glGenBuffers(1, &_indicesVBO); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indicesVBO); 
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(CubeIndicesData), CubeIndicesData, GL_STATIC_DRAW);     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);    
    
    GLint attribute;
    GLsizei stride = sizeof(GLfloat) * 3;
    glGenVertexArraysOES(1, &_VAO); 
    glBindVertexArrayOES(_VAO); 
    
    glBindBuffer(GL_ARRAY_BUFFER, _verticesVBO); 
    attribute = glGetAttribLocation(_program, "Position"); 
    glEnableVertexAttribArray(attribute);
    glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, stride, NULL);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indicesVBO);
    glBindVertexArrayOES(0);

How does the glVertexAttribPointer know what array (there is an indices array and a vertex array) to use for the Position attribute? Most of the code that I've done involves using the last parameter to pass in the array. In this tutorial it's NULL.

Any assistance is much appreciated.

Thanks!
 
The docs tell you:
pointer
Specifies a offset of the first component of the first generic vertex attribute in the array in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target. The initial value is 0.

Whatever buffer is currently bound to GL_ARRAY_BUFFER.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.