Shading a sphere in opengl Help please!

Hey I have a sphere that I created manually and am now trying to calculate the normals so that it shades correctly. I am shining a spotlight on the sphere from the camera’s position. The light shines but instead of the sphere looking like a sphere it looks like it has a grid on it. If anyone knows what I might be doing wrong it would be a life saver!

Here is a link to a picture of the light on the sphere:
And a pic of the light up close on the sphere:

Below is the code for creating the sphere, calculating the normals, and drawing the sphere.

// Calculates the sphere points.
void make_sphere( OBJECT po, double ray, int rs, int vs ) {
double r,u,t,t_inc,u_inc;
int i,j, level_count;
r = ray;
u_inc = 2
u = -M_PI/2;
for(i=0; i <=rs; i++)
t_inc = M_PI/vs;
for(j=0; j <=vs; j++)
po->vertices[i][j][0] = (r*cos(t)cos(u));
po->vertices[i][j][1] = (r
po->vertices[i][j][2] = (-(r * cos(t)*sin(u)));
po->vertices[i][j][3] = 1;
t= t+t_inc;

Normalize(po, ray); // Calculates Normal vectors

// Calculates the normal vectors
void Normalize(OBJECT *po, GLfloat radius)
int i,j;
for(i=0; i <= crt_rs; i++)
for(j=0; j <= bcrt_vs; j++)
po->normals[i][j][0] = po->vertices[i][j][0] / radius;
po->normals[i][j][1] = po->vertices[i][j][1] / radius;
po->normals[i][j][2] = po->vertices[i][j][2] / radius;
po->normals[i][j][3] = po->vertices[i][j][3] / radius;
// Draws the sphere and normals.
void draw_sphere(OBJECT *po, int rs, int vs)
int i, j;

for(i=0; i &lt; rs; i++)

	for(j=0;j &lt; vs;j++)
	glVertex4f(po-&gt;vertices[i][j][0],po-&gt;vertices[i][j][1],po-&gt;vertices[i][j][2], po-&gt;vertices[i][j][3]);
	glVertex4f(po-&gt;vertices[i+1][j][0],po-&gt;vertices[i+1][j][1],po-&gt;vertices[i+1][j][2], po-&gt;vertices[i+1][j][3]);
	glVertex4f(po-&gt;vertices[i+1][j+1][0],po-&gt;vertices[i+1][j+1][1],po-&gt;vertices[i+1][j+1][2], po-&gt;vertices[i+1][j+1][3]);
	glVertex4f(po-&gt;vertices[i][j+1][0],po-&gt;vertices[i][j+1][1],po-&gt;vertices[i][j+1][2], po-&gt;vertices[i][j+1][3]);



Just from your figures, I’m guessing that your quads are messed up. Looks like 1 vertex for every quad is at the center of the sphere. Try generating a simpler sphere made up of a dozen or so quads. And don’t generate all of the quads, just generate the first one. I’m betting it will be messed up.

You could also try generating a simpler sphere with your algorithm but rendering it wireframe with no lighting. I think you’re going see a lot of lines (quad edges) going from the surface of the sphere into the center. Good luck.

I generated a wireframe with no lighting and the only abnormality I saw was a single line down the center of the sphere from north pole to south pole. No other criss-crosses or anything like that. Which vertex is at the center? For some reason I haven’t been able to find it.

I also did an output of all the points in the array and none are 0,0,0 (which would be the center of the sphere. I’m not sure how it’s getting to the center…?

Sounds like your vertices are correct but the poly definitions are messed up. What happens if you try to draw one quad only?

Drawing only one quad I get an extremely slender pie shaped quad going from the center of where the sphere would be to where the radius would be.

Which is exactly what was brought up in an earlier post. All of your polygons are messed up in the same way. I leave it up to you to debug your code. Looks like you are computing the vertex coordinates correctly, but that something is off in the indexing you are using in the glVertex commands between glBegin and glEnd.