- if (numVertices > 0 && attribute_v_coord != -1) {
- fghGenBuffers(1, &vbo_coords);
- fghBindBuffer(GL_ARRAY_BUFFER, vbo_coords);
- fghBufferData(GL_ARRAY_BUFFER, numVertices * 3 * sizeof(vertices[0]),
- vertices, GL_STATIC_DRAW);
- }
-
- if (numVertices > 0 && attribute_v_normal != -1) {
- fghGenBuffers(1, &vbo_normals);
- fghBindBuffer(GL_ARRAY_BUFFER, vbo_normals);
- fghBufferData(GL_ARRAY_BUFFER, numVertices * 3 * sizeof(normals[0]),
- normals, GL_STATIC_DRAW);
- }
-
- if (vertIdxs != NULL) {
- fghGenBuffers(1, &ibo_elements);
- fghBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
- fghBufferData(GL_ELEMENT_ARRAY_BUFFER, numVertIdxs * sizeof(vertIdxs[0]),
- vertIdxs, GL_STATIC_DRAW);
- }
-
- if (vbo_coords) {
- fghEnableVertexAttribArray(attribute_v_coord);
- fghBindBuffer(GL_ARRAY_BUFFER, vbo_coords);
- fghVertexAttribPointer(
- attribute_v_coord, // attribute
- 3, // number of elements per vertex, here (x,y,z)
- GL_FLOAT, // the type of each element
- GL_FALSE, // take our values as-is
- 0, // no extra data between each position
- 0 // offset of first element
- );
- };
-
- if (vbo_normals) {
- fghEnableVertexAttribArray(attribute_v_normal);
- fghBindBuffer(GL_ARRAY_BUFFER, vbo_normals);
- fghVertexAttribPointer(
- attribute_v_normal, // attribute
- 3, // number of elements per vertex, here (x,y,z)
- GL_FLOAT, // the type of each element
- GL_FALSE, // take our values as-is
- 0, // no extra data between each position
- 0 // offset of first element
- );
- };
-
- if (vertIdxs == NULL) {
- glDrawArrays(GL_TRIANGLES, 0, numVertices);
- } else {
- fghBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
- glDrawElements(GL_TRIANGLES, numVertIdxs, GL_UNSIGNED_BYTE, 0);
- }