-
Notifications
You must be signed in to change notification settings - Fork 7
Tutorial on Index Buffers
Nicolas Guillemot edited this page Jun 27, 2016
·
1 revision
When using DrawElements with GL_TRIANGLE_STRIP or GL_LINE_STRIP you have to specify (1) a buffer of positions and (2) a buffer of indices:
std::vector<vec3> vpoints;
std::vector<unsigned int> indices;
Assume you have a 3x3 meshed grid, as follows:
0 1 2
3 4 5
6 7 8
In vpoints you (programmatically: for-loop) insert the vertex positions of your grid:
vpoints[0] = vec3(-1, -1);
vpoints[1] = vec3( 0, -1);
vpoints[2] = vec3(+1, -1);
...
vpoints[8] = vec3(+1, +1);
Similarly, you will programmatically fill-in the indices of your grid. Indices for the first row (and a bit of the second) will look as follows:
indices = [0, 3, 1, 4, 2, 5, RESTART_ID, 3, 6, 4, 7, 5, 8]
©Department of Computer Science, University of Victoria, 2015.