From: Diederick Niehorster Date: Fri, 20 Apr 2012 11:25:42 +0000 (+0000) Subject: solid sphere now done with only triangle strips. X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;ds=sidebyside;h=bdd49e471b6885768dfe49a8d68d60d88db491c1;p=freeglut solid sphere now done with only triangle strips. All shapes should be doable with only triangle strips, so this allows code reuse later ... git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1249 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 71cda34..98bc6db 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -1074,54 +1074,55 @@ static void fghSphere( double radius, GLint slices, GLint stacks, GLboolean useW } else { - GLushort *topIdx, *bottomIdx, *stripIdx; /* First, generate vertex index arrays for drawing with glDrawElements - * Top and bottom are covered with a triangle fan - * Each other stack with triangle strip. Only need to generate on - * of those as we'll have to draw each stack separately, and can - * just use different offsets in glDrawElements. + * All stacks, including top and bottom are covered with a triangle + * strip. */ + GLushort *stripIdx; + /* Create index vector */ + GLushort offset; /* Allocate buffers for indices, bail out if memory allocation fails */ - topIdx = malloc((slices+2)*sizeof(GLushort)); - bottomIdx = malloc((slices+2)*sizeof(GLushort)); - stripIdx = malloc((slices+1)*2*(stacks-2)*sizeof(GLushort)); - if (!(topIdx) || !(bottomIdx) || !(stripIdx)) + stripIdx = malloc((slices+1)*2*(stacks)*sizeof(GLushort)); + if (!(stripIdx)) { - free(topIdx); - free(bottomIdx); free(stripIdx); fgError("Failed to allocate memory in fghGenerateSphere"); } - /* TODO: Can do top and bottom as Triangle strip as well - (just need to repeat top/btoom vertex a lot). Then we can draw - the whole thing with just one index array and one for-looped call - to glDrawElements.. That'll make it easier to reuse code with other - Circular objects too - */ - topIdx[0]=0; - topIdx[1] = 1; /* repeat first slice's idx for closing off shape */ - for (j=slices, idx=2; j>0; j--, idx++) - topIdx[idx] = j; - - bottomIdx[0]=nVert-1; /* zero based index, last element in array... */ - for (j=0, idx=1; j