/* Version for OpenGL (ES) >= 2.0 */
static void fghDrawGeometryWire20(GLfloat *vertices, GLfloat *normals, GLsizei numFaces, GLsizei numEdgePerFace,
- GLint attribute_v_coord, GLint attribute_v_normal)
+ GLint attribute_v_coord, GLint attribute_v_normal)
{
- GLuint vbo_coords, vbo_normals;
+ GLuint vbo_coords = 0, vbo_normals = 0;
GLuint numVertices = numFaces * numEdgePerFace;
int i;
fghGenBuffers(1, &vbo_coords);
fghBindBuffer(FGH_ARRAY_BUFFER, vbo_coords);
fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(vertices[0]),
- vertices, FGH_STATIC_DRAW);
+ vertices, FGH_STATIC_DRAW);
}
if (numVertices > 0 && attribute_v_normal != -1) {
- fghGenBuffers(1, &vbo_normals);
- fghBindBuffer(FGH_ARRAY_BUFFER, vbo_normals);
- fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(normals[0]),
- normals, FGH_STATIC_DRAW);
+ fghGenBuffers(1, &vbo_normals);
+ fghBindBuffer(FGH_ARRAY_BUFFER, vbo_normals);
+ fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(normals[0]),
+ normals, FGH_STATIC_DRAW);
}
if (vbo_coords) {
fghEnableVertexAttribArray(attribute_v_coord);
fghBindBuffer(FGH_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
+ 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 */
);
}
fghEnableVertexAttribArray(attribute_v_normal);
fghBindBuffer(FGH_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
+ 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 */
);
}
/* Draw per face (TODO: could use glMultiDrawArrays if available) */
for (i=0; i<numFaces; i++)
- glDrawArrays(GL_LINE_LOOP, i*numEdgePerFace, numEdgePerFace);
+ glDrawArrays(GL_LINE_LOOP, i*numEdgePerFace, numEdgePerFace);
if (vbo_coords != 0)
- fghDisableVertexAttribArray(attribute_v_coord);
+ fghDisableVertexAttribArray(attribute_v_coord);
if (vbo_normals != 0)
- fghDisableVertexAttribArray(attribute_v_normal);
+ fghDisableVertexAttribArray(attribute_v_normal);
if (vbo_coords != 0)
- fghDeleteBuffers(1, &vbo_coords);
+ fghDeleteBuffers(1, &vbo_coords);
if (vbo_normals != 0)
- fghDeleteBuffers(1, &vbo_normals);
+ fghDeleteBuffers(1, &vbo_normals);
}
static void fghDrawGeometryWire(GLfloat *vertices, GLfloat *normals, GLsizei numFaces, GLsizei numEdgePerFace)
if (fgState.HasOpenGL20 && (attribute_v_coord != -1 || attribute_v_normal != -1))
/* User requested a 2.0 draw */
- fghDrawGeometryWire20(vertices, normals, numFaces, numEdgePerFace,
- attribute_v_coord, attribute_v_normal);
+ fghDrawGeometryWire20(vertices, normals, numFaces, numEdgePerFace,
+ attribute_v_coord, attribute_v_normal);
#ifndef GL_ES_VERSION_2_0
else
- fghDrawGeometryWire11(vertices, normals, numFaces, numEdgePerFace);
+ fghDrawGeometryWire11(vertices, normals, numFaces, numEdgePerFace);
#endif
}
/* Version for OpenGL (ES) 1.1 */
#ifndef GL_ES_VERSION_2_0
static void fghDrawGeometrySolid11(GLfloat *vertices, GLfloat *normals, GLubyte *vertIdxs,
- GLsizei numVertices, GLsizei numVertIdxs)
+ GLsizei numVertices, GLsizei numVertIdxs)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
/* Version for OpenGL (ES) >= 2.0 */
static void fghDrawGeometrySolid20(GLfloat *vertices, GLfloat *normals, GLubyte *vertIdxs,
- GLsizei numVertices, GLsizei numVertIdxs,
- GLint attribute_v_coord, GLint attribute_v_normal)
+ GLsizei numVertices, GLsizei numVertIdxs,
+ GLint attribute_v_coord, GLint attribute_v_normal)
{
- GLuint vbo_coords, vbo_normals, ibo_elements;
+ GLuint vbo_coords = 0, vbo_normals = 0, ibo_elements = 0;
if (numVertices > 0 && attribute_v_coord != -1) {
- fghGenBuffers(1, &vbo_coords);
- fghBindBuffer(FGH_ARRAY_BUFFER, vbo_coords);
- fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(vertices[0]),
- vertices, FGH_STATIC_DRAW);
+ fghGenBuffers(1, &vbo_coords);
+ fghBindBuffer(FGH_ARRAY_BUFFER, vbo_coords);
+ fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(vertices[0]),
+ vertices, FGH_STATIC_DRAW);
}
if (numVertices > 0 && attribute_v_normal != -1) {
- fghGenBuffers(1, &vbo_normals);
- fghBindBuffer(FGH_ARRAY_BUFFER, vbo_normals);
- fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(normals[0]),
- normals, FGH_STATIC_DRAW);
+ fghGenBuffers(1, &vbo_normals);
+ fghBindBuffer(FGH_ARRAY_BUFFER, vbo_normals);
+ fghBufferData(FGH_ARRAY_BUFFER, numVertices * 3 * sizeof(normals[0]),
+ normals, FGH_STATIC_DRAW);
}
if (vertIdxs != NULL) {
- fghGenBuffers(1, &ibo_elements);
- fghBindBuffer(FGH_ELEMENT_ARRAY_BUFFER, ibo_elements);
- fghBufferData(FGH_ELEMENT_ARRAY_BUFFER, numVertIdxs * sizeof(vertIdxs[0]),
- vertIdxs, FGH_STATIC_DRAW);
+ fghGenBuffers(1, &ibo_elements);
+ fghBindBuffer(FGH_ELEMENT_ARRAY_BUFFER, ibo_elements);
+ fghBufferData(FGH_ELEMENT_ARRAY_BUFFER, numVertIdxs * sizeof(vertIdxs[0]),
+ vertIdxs, FGH_STATIC_DRAW);
}
if (vbo_coords) {
- fghEnableVertexAttribArray(attribute_v_coord);
- fghBindBuffer(FGH_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
+ fghEnableVertexAttribArray(attribute_v_coord);
+ fghBindBuffer(FGH_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(FGH_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
+ fghEnableVertexAttribArray(attribute_v_normal);
+ fghBindBuffer(FGH_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);
+ glDrawArrays(GL_TRIANGLES, 0, numVertices);
} else {
- fghBindBuffer(FGH_ELEMENT_ARRAY_BUFFER, ibo_elements);
- glDrawElements(GL_TRIANGLES, numVertIdxs, GL_UNSIGNED_BYTE, 0);
+ fghBindBuffer(FGH_ELEMENT_ARRAY_BUFFER, ibo_elements);
+ glDrawElements(GL_TRIANGLES, numVertIdxs, GL_UNSIGNED_BYTE, 0);
}
if (vbo_coords != 0)
- fghDisableVertexAttribArray(attribute_v_coord);
+ fghDisableVertexAttribArray(attribute_v_coord);
if (vbo_normals != 0)
- fghDisableVertexAttribArray(attribute_v_normal);
+ fghDisableVertexAttribArray(attribute_v_normal);
if (vbo_coords != 0)
- fghDeleteBuffers(1, &vbo_coords);
+ fghDeleteBuffers(1, &vbo_coords);
if (vbo_normals != 0)
- fghDeleteBuffers(1, &vbo_normals);
+ fghDeleteBuffers(1, &vbo_normals);
if (ibo_elements != 0)
- fghDeleteBuffers(1, &ibo_elements);
+ fghDeleteBuffers(1, &ibo_elements);
}
static void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLubyte *vertIdxs,
- GLsizei numVertices, GLsizei numVertIdxs)
+ GLsizei numVertices, GLsizei numVertIdxs)
{
GLint attribute_v_coord = fgStructure.CurrentWindow->Window.attribute_v_coord;
GLint attribute_v_normal = fgStructure.CurrentWindow->Window.attribute_v_normal;
if (fgState.HasOpenGL20 && (attribute_v_coord != -1 || attribute_v_normal != -1))
/* User requested a 2.0 draw */
- fghDrawGeometrySolid20(vertices, normals, vertIdxs,
- numVertices, numVertIdxs,
- attribute_v_coord, attribute_v_normal);
+ fghDrawGeometrySolid20(vertices, normals, vertIdxs,
+ numVertices, numVertIdxs,
+ attribute_v_coord, attribute_v_normal);
#ifndef GL_ES_VERSION_2_0
else
- fghDrawGeometrySolid11(vertices, normals, vertIdxs,
- numVertices, numVertIdxs);
+ fghDrawGeometrySolid11(vertices, normals, vertIdxs,
+ numVertices, numVertIdxs);
#endif
}
for (i=0; i<numFaces; i++)
{
int normIdx = i*3;
- int faceIdxVertIdx = i*numEdgePerFace; // index to first element of "row" in vertex indices
+ int faceIdxVertIdx = i*numEdgePerFace; /* index to first element of "row" in vertex indices */
for (j=0; j<numEdgePerFace; j++)
{
int outIdx = i*numEdgePerFace*3+j*3;
7,4,3,2,
4,7,6,5
};
-DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(cube,Cube,CUBE);
+DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(cube,Cube,CUBE)
/* -- Dodecahedron -- */
/* Magic Numbers: It is possible to create a dodecahedron by attaching two
18, 1, 0, 5, 9,
19, 14, 13, 10, 12
};
-DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(dodecahedron,Dodecahedron,DODECAHEDRON);
+DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(dodecahedron,Dodecahedron,DODECAHEDRON)
/* -- Icosahedron -- */
11, 6, 7 ,
11, 10, 6
};
-DECLARE_SHAPE_CACHE(icosahedron,Icosahedron,ICOSAHEDRON);
+DECLARE_SHAPE_CACHE(icosahedron,Icosahedron,ICOSAHEDRON)
/* -- Octahedron -- */
#define OCTAHEDRON_NUM_VERT 6
3, 4, 2,
3, 5, 4
};
-DECLARE_SHAPE_CACHE(octahedron,Octahedron,OCTAHEDRON);
+DECLARE_SHAPE_CACHE(octahedron,Octahedron,OCTAHEDRON)
/* -- RhombicDodecahedron -- */
#define RHOMBICDODECAHEDRON_NUM_VERT 14
7, 11, 13, 12,
8, 12, 13, 9
};
-DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
+DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON)
/* -- Tetrahedron -- */
/* Magic Numbers: r0 = ( 1, 0, 0 )
0, 3, 1,
0, 1, 2
};
-DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON);
+DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON)
/* -- Sierpinski Sponge -- */
static unsigned int ipow (int x, unsigned int y)
}
}
+#ifndef GL_ES_VERSION_2_0
/* -- Now the various shapes involving circles -- */
/*
* Compute lookup table of cos and sin values forming a circle
free(sint2);
free(cost2);
}
-
+#endif
/* -- INTERNAL DRAWING functions --------------------------------------- */
#define _DECLARE_INTERNAL_DRAW_DO_DECLARE(name,nameICaps,nameCaps,vertIdxs)\
vertices = cube_verts;
if (useWireMode)
- fghDrawGeometryWire (vertices, cube_norms,
- CUBE_NUM_FACES, CUBE_NUM_EDGE_PER_FACE);
+ fghDrawGeometryWire(vertices, cube_norms,
+ CUBE_NUM_FACES, CUBE_NUM_EDGE_PER_FACE);
else
fghDrawGeometrySolid(vertices, cube_norms, cube_vertIdxs,
- CUBE_VERT_PER_OBJ, CUBE_VERT_PER_OBJ_TRI);
+ CUBE_VERT_PER_OBJ, CUBE_VERT_PER_OBJ_TRI);
if (dSize!=1.f)
/* cleanup allocated memory */
free(vertices);
}
-DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(dodecahedron,Dodecahedron,DODECAHEDRON);
-DECLARE_INTERNAL_DRAW(icosahedron,Icosahedron,ICOSAHEDRON);
-DECLARE_INTERNAL_DRAW(octahedron,Octahedron,OCTAHEDRON);
-DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
-DECLARE_INTERNAL_DRAW(tetrahedron,Tetrahedron,TETRAHEDRON);
+DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(dodecahedron,Dodecahedron,DODECAHEDRON)
+DECLARE_INTERNAL_DRAW(icosahedron,Icosahedron,ICOSAHEDRON)
+DECLARE_INTERNAL_DRAW(octahedron,Octahedron,OCTAHEDRON)
+DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON)
+DECLARE_INTERNAL_DRAW(tetrahedron,Tetrahedron,TETRAHEDRON)
static void fghSierpinskiSponge ( int numLevels, double offset[3], GLfloat scale, GLboolean useWireMode )
{
GLfloat *vertices, *normals;
if (slices * stacks > 65535)
- fgWarning("fghSphere: too many slices or stacks requested, indices will wrap");
+ fgWarning("fghSphere: too many slices or stacks requested, indices will wrap");
/* Generate vertices and normals */
fghGenerateSphere((GLfloat)radius,slices,stacks,&vertices,&normals,&nVert);
fghCube( (GLfloat)dSize, FALSE );
}
-DECLARE_SHAPE_INTERFACE(Dodecahedron);
-DECLARE_SHAPE_INTERFACE(Icosahedron);
-DECLARE_SHAPE_INTERFACE(Octahedron);
-DECLARE_SHAPE_INTERFACE(RhombicDodecahedron);
+DECLARE_SHAPE_INTERFACE(Dodecahedron)
+DECLARE_SHAPE_INTERFACE(Icosahedron)
+DECLARE_SHAPE_INTERFACE(Octahedron)
+DECLARE_SHAPE_INTERFACE(RhombicDodecahedron)
void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, double offset[3], double scale )
{
fghSierpinskiSponge ( num_levels, offset, (GLfloat)scale, FALSE );
}
-DECLARE_SHAPE_INTERFACE(Tetrahedron);
+DECLARE_SHAPE_INTERFACE(Tetrahedron)
/*** END OF FILE ***/