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:
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!
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!