Created
January 23, 2015 20:29
-
-
Save nilspin/8fdd61a282b700bfc78d to your computer and use it in GitHub Desktop.
How VAOs work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gluint VAO,VBO,indexBuffer; | |
glGenVertexArrays(1,&VAO); | |
glBindVertexArrays(VAO); | |
glGenBuffers(1,&VBO); | |
glBindBuffer(GL_ARRAY_BUFFER, VBO);//Use this vbo first | |
glBufferData(GL_ARRAY_BUFFER,.....); //move this data to GPU in this call | |
glVertexAttribPointer(/*point to data within VBO appropriately*/); | |
glEnableVertexAttribArray(/*handle of attrib in question from previous line*/); | |
//Do above for as many VBOs as you like | |
glGenBuffers(1,&indexBuffer); //now time for index data. | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);//now use this vbo | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER,.....); | |
//Note that here we haven't used glVertexAttribPointer or glEnableVertexAttribArray because its not required. | |
//GPU does that by itself; | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);//unbind | |
//At this point we have successfully created VBOs, moved data to them, and specified vertex attrib pointers | |
//so our work is done here | |
glBindVertexArrays(0); //Unbind VAO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment