Smooth Shading For Quadradic Formula?

Okay, I’m using a quadradic formula to create several basic geometric primitives (sphere, cone, cylinder). So, let’s say I have the following function:

QuadradicCylinder(float radius, float height, float u, float v, float *out);

I have some code that loops through u and v (which lie in the range of 0.0 - 1.0, and get the quads representing those points, and output them on the screen. Works great.

But, here is the problem. I went to add shading to the primitives and I can’t get smooth shading to work. I got flat shading to work, by taking the first, three vertexes of a quad and finding the cross product, and using that normal (normalizing it via OpenGL’s built-in commands). But how do I get smooth shading to work?

I thought, if I took three points arount each u,v point, and then gave OpenGL a slightly different normal vector for each point, it would smooth them out, and it does…sortof. What I’m getting is a weird cross-hatching that is bright at the edges of each quad, but then gets dark in the center. Any ideas? I know my OpenGL code is working fine, because if I call glutSolidSphere, it renders perfect!

tbc++

Two things: First, you probably should be using GLU Quadrics (see the red book page 486).

Second, for smooth shading you need the normals at each vertex to be something like the average of the normals of the sorrounding surfaces. But GLU Quadrics should do this all for you nicely.