I'm new to OpenGL ES, but quite experienced with Objective-C and iOS development. I've so far had no problem drawing and coloring shapes using vertex buffer objects, by defining an array of vertices and a corresponding array of indicies, with the following code
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Verticies), Verticies, GL_STATIC_DRAW);
GLuint indexBuffer;
glGenBuffers(1, &indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
Then drawing to the screen with the following code:
glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
[_context presentRenderbuffer:GL_RENDERBUFFER];
This is all fine for basic shapes that I can define myself in code. Now I've had someone generate .h files that have been exported from a 3D graphics program, that contain the info needed to define a shape, but they don't contain an index array. Instead the index information has somehow been embedded in the vertex array. The vertex array has repeated coordinates that define the order in which they should be drawn. See the sample code below. I also now have an array of normals and an array of texture coordinates. Can anyone tell me (or point me to to a tutorial/guide) how I would go about using (read: drawing with) this data as opposed to the separate vertex/index arrays as before? Thanks in advance!
#define poleNumVerts 276
static const float poleVerts [] = {
// f 1/1/1 2/2/2 3/3/3
-0.0170377877807436, -0.00478429549256308, 0.5,
-0.0170377877807436, 0.00409214741631937, 0.5,
-0.0176220932500109, -0.00034605799118996, 0.5,
// f 2/2/2 1/1/1 4/4/4
-0.0170377877807436, 0.00409214741631937, 0.5,
-0.0170377877807436, -0.00478429549256308, 0.5,
-0.015324690688248, -0.00892006666692703, 0.5,
// f 2/2/2 4/4/4 5/5/5
-0.0170377877807436, 0.00409214741631937, 0.5,
-0.015324690688248, -0.00892006666692703, 0.5,
-0.015324690688248, 0.00822795297696595, 0.5,
// f 5/5/5 4/4/4 6/6/6
-0.015324690688248, 0.00822795297696595, 0.5,
-0.015324690688248, -0.00892006666692703, 0.5,
-0.012599557156627, 0.0117794232669002, 0.5,
// f 6/6/6 4/4/4 7/7/7
-0.012599557156627, 0.0117794232669002, 0.5,
-0.015324690688248, -0.00892006666692703, 0.5,
-0.012599557156627, -0.0124715369568613, 0.5,
// f 6/6/6 7/7/7 8/8/8
-0.012599557156627, 0.0117794232669002, 0.5,
-0.012599557156627, -0.0124715369568613, 0.5,
-0.0090480845742739, -0.015196688827833, 0.5,
...... <code truncated>... };
static const float poleNormals [] = {
// f 1/1/1 2/2/2 3/3/3
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 2/2/2 1/1/1 4/4/4
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 2/2/2 4/4/4 5/5/5
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 5/5/5 4/4/4 6/6/6
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 6/6/6 4/4/4 7/7/7
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 6/6/6 7/7/7 8/8/8
0, 0, 1,
0, 0, 1,
0, 0, 1,
// f 6/6/6 8/8/8 9/9/9
...... <code truncated>...};
static const float poleTexCoords [] = {
// f 1/1/1 2/2/2 3/3/3
0.939514, 0.37333,
0.928115, 0.619208,
0.950000, 0.49702,
// f 2/2/2 1/1/1 4/4/4
0.928115, 0.619208,
0.939514, 0.37333,
0.897372, 0.25657,
// f 2/2/2 4/4/4 5/5/5
0.928115, 0.619208,
0.897372, 0.25657,
0.875352, 0.73157,
// f 5/5/5 4/4/4 6/6/6
0.875352, 0.73157,
0.897372, 0.25657,
0.795305, 0.826446,
// f 6/6/6 4/4/4 7/7/7
0.795305, 0.826446,
0.897372, 0.25657,
0.826446, 0.154695,
// f 6/6/6 7/7/7 8/8/8
0.795305, 0.826446,
0.826446, 0.154695,
0.731570, 0.074647,
// f 6/6/6 8/8/8 9/9/9
0.795305, 0.826446,
0.731570, 0.074647,
0.693430, 0.897371,
..... <code truncated>.... };