OpenGL lighting working on iPhone 4/iPad, not on iPhone 3G
I am having trouble with OpenGL 1.1 lighting. My code works on the iPhone 4 but not the iPhone 3G. Everything appears unlit (flat colours). I don't have a 3GS so I can't find out if it works on that one or not.
Here is my lighting setup:
- (void)setupLighting
{
const GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0};
const GLfloat matAmbient[] = {0.6, 0.6, 0.6, 1.0};
const GLfloat matDiffuse[] = {1.0, 1.0, 1.0, 1.0};
const GLfloat matSpecular[] = {0.6, 0.6, 0.6, 0.1};
const GLfloat lightPosition[] = {0.0, 0.0, 0.0, 0.0};
const GLfloat lightShininess = 100.0;
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lightShininess);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glShadeModel(GL_SMOOTH);
NSLog(@"Lighting sorted");
}
I supply normal vectors and so on after that, wh开发者_StackOverflowich successfully renders on the newer iPhone... however, I would really like to support all three iPhones. (It also works on the iPad).
Heh, to answer my own question (and provide info for anyone else with the same problem) there was a problem with the light position being (0, 0, 0, 0). Setting it to (0, 0, -1.0, 0) fixed the problem and didn't disturb the lighting conditions on the other devices. I still don't quite understand what I've done here, but I'm just glad I can provide compatibility to iPhone 3Gs...
精彩评论