Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created December 10, 2014 04:44
Show Gist options
  • Select an option

  • Save zeroeth/9250892dc01de8f3d30c to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/9250892dc01de8f3d30c to your computer and use it in GitHub Desktop.
bare minimum vbo example
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