smooth shading problems

Can anyone provide a sample code which demonstrates smooth shading on polygonal 3d objects.
I have my 3d object class which contains lists of polygon groups. each polygongroup have color and material properties, and list of Polygon objects. Polygon object contains list of vertices (represented by my Point3d class). It also has normal vector. So now this is how I draw object:

init method:


           gl.glShadeModel(GL.GL_SMOOTH);
            gl.glClearColor(0, 0, 0, 0);
            gl.glClearDepth(1);
            gl.glEnable(GL.GL_DEPTH_TEST);
            gl.glDepthFunc(GL.GL_LEQUAL);
            gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
            gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient);
            gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse);
            gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPosition);
            gl.glEnable(GL.GL_LIGHT1);
            gl.glColorMaterial(GL.GL_FRONT, GL.GL_DIFFUSE);
            gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

display method:


        gl.glEnable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_COLOR_MATERIAL);
      
        for (PolygonGroup polygonGroup : polygonGroups)
        {
            gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, polygonGroup.getDiffuseColor());
            gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, polygonGroup.getSpecularColor());
            gl.glMaterialf(GL.GL_FRONT, GL.GL_SHININESS, polygonGroup.getShinines());
            for (Iterator<Polygon> iter = polygonGroup.getPolygons().iterator(); iter.hasNext();)
            {
                float[] color = polygonGroup.getDiffuseColor();
                Polygon polygon = iter.next();
                gl.glBegin(GL.GL_POLYGON);
                Vector3D n = Math3D.getNormal(polygon);
                gl.glNormal3d(n.x, n.y, n.z);
                gl.glColor4f(color[0], color[1], color[2], 1);
                Point3D[] p = polygon.getPoints();
                for (int i = 0; i < p.length; i++)
                {
                    gl.glVertex3d(p[i].x, p[i].y, p[i].z);
                }
                gl.glEnd();
            }
        }
       

and after that my object looks like this:

http://dogbert.renderspace.si/~buzz/snapshot8.png

what’s wrong with this code ???

should I use vertex normals instead of surface normals?

Yes, you should. Using a surface normal effectively means that all the vertices drawn for the surface will have the same normal - thus making the surface seem flat. You can generate vertex normal simply by averaging your current surface normals for each vertex if they are not provided to you by a modeling package.

So, basically a vertex normal VN for vertex V shared by surfaces A, B and C with normals AN, BN, CN (unit vectors) =

VN = normalize(AN + BN + CN)

Yes, I just tried it and it works. Thanx for your answer.