int i,j,idx, nVert;
GLfloat *vertices, *normals;
+ if (slices * stacks > 65535)
+ fgWarning("fghSphere: too many slices or stacks requested, indices will wrap");
+
/* Generate vertices and normals */
fghGenerateSphere((GLfloat)radius,slices,stacks,&vertices,&normals,&nVert);
if (useWireMode)
{
- GLuint *sliceIdx, *stackIdx;
+ GLushort *sliceIdx, *stackIdx;
/* First, generate vertex index arrays for drawing with glDrawElements
* We have a bunch of line_loops to draw for each stack, and a
* bunch for each slice.
*/
- sliceIdx = malloc(slices*(stacks+1)*sizeof(GLuint));
- stackIdx = malloc(slices*(stacks-1)*sizeof(GLuint));
+ sliceIdx = malloc(slices*(stacks+1)*sizeof(GLushort));
+ stackIdx = malloc(slices*(stacks-1)*sizeof(GLushort));
/* generate for each stack */
for (i=0,idx=0; i<slices; i++)
{
- GLuint offset = 1+i; /* start at 1 (0 is top vertex), and we advance one slice as we go along */
+ GLushort offset = 1+i; /* start at 1 (0 is top vertex), and we advance one slice as we go along */
sliceIdx[idx++] = 0; /* vertex on top */
for (j=0; j<stacks-1; j++, idx++)
{
/* generate for each stack */
for (i=0,idx=0; i<stacks-1; i++)
{
- GLuint offset = 1+i*slices; /* start at 1 (0 is top vertex), and we advance one stack down as we go along */
+ GLushort offset = 1+i*slices; /* start at 1 (0 is top vertex), and we advance one stack down as we go along */
for (j=0; j<slices; j++, idx++)
{
stackIdx[idx] = offset+j;
glNormalPointer(GL_FLOAT, 0, normals);
/*draw slices*/
for (i=0; i<slices; i++)
- glDrawElements(GL_LINE_STRIP,stacks+1,GL_UNSIGNED_INT,sliceIdx+i*(stacks+1));
+ glDrawElements(GL_LINE_STRIP,stacks+1,GL_UNSIGNED_SHORT,sliceIdx+i*(stacks+1));
/*draw stacks*/
for (i=0; i<stacks-1; i++)
- glDrawElements(GL_LINE_LOOP, slices,GL_UNSIGNED_INT,stackIdx+i*slices);
+ glDrawElements(GL_LINE_LOOP, slices,GL_UNSIGNED_SHORT,stackIdx+i*slices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
else
{
- GLuint *topIdx, *bottomIdx, *stripIdx;
+ 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
*/
/* Allocate buffers for indices, bail out if memory allocation fails */
- topIdx = malloc((slices+2)*sizeof(GLuint));
- bottomIdx = malloc((slices+2)*sizeof(GLuint));
- stripIdx = malloc((slices+1)*2*(stacks-2)*sizeof(GLuint));
+ 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))
{
free(topIdx);
/* Strip indices are relative to first index belonging to strip, NOT relative to first vertex/normal pair in array */
for (i=0,idx=0; i<stacks-2; i++, idx+=2)
{
- GLuint offset = 1+i*slices; /* triangle_strip indices start at 1 (0 is top vertex), and we advance one stack down as we go along */
+ GLushort offset = 1+i*slices; /* triangle_strip indices start at 1 (0 is top vertex), and we advance one stack down as we go along */
for (j=0; j<slices; j++, idx+=2)
{
stripIdx[idx ] = offset+j+slices;
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);
/*draw top*/
- glDrawElements(GL_TRIANGLE_FAN,slices+2,GL_UNSIGNED_INT,topIdx);
+ glDrawElements(GL_TRIANGLE_FAN,slices+2,GL_UNSIGNED_SHORT,topIdx);
/*draw stacks*/
for (i=0; i<stacks-2; i++)
- glDrawElements(GL_TRIANGLE_STRIP,(slices+1)*2,GL_UNSIGNED_INT,stripIdx+i*(slices+1)*2);
+ glDrawElements(GL_TRIANGLE_STRIP,(slices+1)*2,GL_UNSIGNED_SHORT,stripIdx+i*(slices+1)*2);
/*draw bottom*/
- glDrawElements(GL_TRIANGLE_FAN,slices+2,GL_UNSIGNED_INT,bottomIdx);
+ glDrawElements(GL_TRIANGLE_FAN,slices+2,GL_UNSIGNED_SHORT,bottomIdx);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
/* -- INTERFACE FUNCTIONS ---------------------------------------------- */
-#ifndef EGL_VERSION_1_0
/*
* Draws a solid sphere
*/
}
+#ifndef EGL_VERSION_1_0
/*
* Draws a solid cone
*/