I’m having a problem trying to do lighting with the esGenSphere code that’s provided as sample code for the OpenGL ES 2.0 Programming Guide (purple book). Downloaded the source (v1.0.2), and am trying to generate the sphere and light it with diffuse lighting. I’m doing Phong shading, so am passing a varying normal to the fragment shader. The sphere is drawn with GL_TRIANGLE_STRIP. The problem is that half the sphere is lit incorrectly . If I turn backface culling on, I would expect every other triangle to get culled, which would be normal for a triangle strip. But I only see the culling in the half of the sphere that has problems with the lighting . I’ve rotated the sphere slightly around the y axis to see that the culling issue gets rotated (so it seems to be a problem with the geometry, and not my shader). But I’m wondering why - In the image with backface culling on, the triangles that don’t get culled get lit correctly in both halves. With backface culling off, all triangles in that half don’t get lit correctly…!!! How is that happening? Is something still wrong with my shader? Thanks for your help!

static const gchar *fragment_shader =
"varying vec3 fcolor;
"
"varying vec4 N;
"
"varying vec4 transV;
"
"void main()
"
"{
"
" float shininess = 10.0;
"
" vec3 lightDiffuse = vec3(1.0, 1.0, 1.0);
"
" vec4 lightDir = vec4(0, 0, -500, 0.);
"
" vec3 L = normalize(vec3(lightDir-transV));
"
" float ndotl = max(0.0, dot(vec3(N), L));
"
" gl_FragColor = vec4(fcolor*.9, 1.0) + vec4(fcolor

*ndotl*lightDiffuse, 1.0);

"

"}

";

static const gchar *vertex_shader =

"uniform mat4 u_projMatrix;

"

"uniform mat4 u_transMatrix;

"

"

"

"attribute vec3 vtxnormal;

"

"attribute vec3 vtxpos;

"

"attribute vec3 vtxcolor;

"

"

"

"varying vec3 fcolor;

"

"varying vec4 N;

"

"varying vec4 transV;

"

"

"

"void main()

"

"{

"

" N = normalize(u_transMatrix * vec4(vtxnormal, 0.0));

"

" transV = u_transMatrix * vec4(vtxpos, 1.0);

"

" gl_Position = u_projMatrix * transV;

"

" fcolor = vtxcolor;

"

"}

";