From da66462c2b7ce3185bc714cbabade787291c5c6f Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Sat, 17 Mar 2012 16:11:06 +0000 Subject: [PATCH] got rid of edgeflags as I now draw all wire frames face-by-face using line loops. Split wire and solid drawing in two separate functions Now doing polygon to triangle decomposition using vertex indices that are passed to glDrawElements, saves on memory, executes more efficient, and makes wireframe drawing a piece of cake. This should be GLES1 compatible too, hope so! git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1184 7f0cb862-5218-0410-a997-914c9d46530a --- src/fg_geometry.c | 265 +++++++++++++++++++++-------------------------------- 1 file changed, 103 insertions(+), 162 deletions(-) diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 77b09a7..2c6f344 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -33,169 +33,88 @@ */ -/* General function for drawing geometry. As for all geometry we have no - * redundancy (or hardly any in the case of cones and cylinders) in terms - * of the vertex/normal combinations, we just use glDrawArrays. - * useWireMode controls the drawing of solids (false) or wire frame - * versions (TRUE) of the geometry you pass +/* General functions for drawing geometry + * Solids are drawn by glDrawArrays if composed of triangles, or by + * glDrawElements if consisting of squares or pentagons that were + * decomposed into triangles (some vertices are repeated in that case). + * WireFrame drawing will have to be done per face, using GL_LINE_LOOP and + * issuing one draw call per face. Always use glDrawArrays as no triangle + * decomposition needed. We use the "first" parameter in glDrawArrays to go + * from face to face. */ -static void fghDrawGeometry(GLdouble *vertices, GLdouble *normals, GLboolean *edgeFlags, GLsizei numVertices, GLsizei numFaces, GLsizei numEdgePerFace, GLboolean useWireMode) +static void fghDrawGeometryWire(GLdouble *vertices, GLdouble *normals, GLsizei numFaces, GLsizei numEdgePerFace) { -# ifdef FREEGLUT_GLES1 - /* Solid drawing is the same for OpenGL 1.x and OpenGL ES 1.x, just - * no edge flags for ES. - * WireFrame drawing will have to be done per face though, using - * GL_LINE_LOOP and issuing one draw call per face. For triangles, - * we use glDrawArrays directly on the vertex data for each face, - * while for shapes that are composed of quads or pentagons, we use - * glDrawElements with index vector {0,1,2,5} or {0,1,2,8,5}, - * respectively. - * We use the first parameter in glDrawArrays or glDrawElements to - * go from face to face. - */ - if (useWireMode) - { - /* setup reading the right elements from vertex array */ - GLubyte vertIdx4[4] = {0,1,2,5}; - GLubyte vertIdx5[5] = {0,1,2,8,5}; - GLubyte *indices = NULL; - int vertStride, i, j; - - switch (numEdgePerFace) - { - case 3: - vertStride = 3; /* there are 3 vertices for each face in the array */ - break; - case 4: - indices = vertIdx4; - vertStride = 6; /* there are 6 vertices for each face in the array */ - break; - case 5: - indices = vertIdx5; - vertStride = 9; /* there are 9 vertices for each face in the array */ - break; - } - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - glVertexPointer(3, GL_DOUBLE, 0, vertices); - glNormalPointer(GL_DOUBLE, 0, normals); - - if (numEdgePerFace==3) - for (i=0; i