Created
December 10, 2014 04:44
-
-
Save zeroeth/9250892dc01de8f3d30c to your computer and use it in GitHub Desktop.
bare minimum vbo example
This file contains hidden or 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 triangleVBO; | |
| //Vertices of a triangle (counter-clockwise winding) | |
| //float data[] = {1.0, 0.0, 1.0, 0.0, 0.0, -1.0, -1.0, 0.0, 1.0}; | |
| float data[] = {0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, -1.0, 0.0};// if the above doesn't work. | |
| //Create a new VBO and use the variable id to store the VBO id | |
| glGenBuffers(1, &triangleVBO); | |
| //Make the new VBO active | |
| glBindBuffer(GL_ARRAY_BUFFER, triangleVBO); | |
| //Upload vertex data to the video device | |
| glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); | |
| //Make the new VBO active. Repeat here incase changed since initialisation | |
| glBindBuffer(GL_ARRAY_BUFFER, triangleVBO); | |
| //Draw Triangle from VBO - do each time window, view point or data changes | |
| //Establish its 3 coordinates per vertex with zero stride in this array; necessary here | |
| glVertexPointer(3, GL_FLOAT, 0, NULL); | |
| //Establish array contains vertices (not normals, colours, texture coords etc) | |
| glEnableClientState(GL_VERTEX_ARRAY); | |
| //Actually draw the triangle, giving the number of vertices provided | |
| glDrawArrays(GL_TRIANGLES, 0, sizeof(data) / sizeof(float) / 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment