OpenGL 光照适用于 iPhone 4/iPad,不适用于 iPhone 3G

发布于 2024-09-13 23:11:57 字数 1216 浏览 9 评论 0原文

我在使用 OpenGL 1.1 光照时遇到问题。我的代码适用于 iPhone 4,但不适用于 iPhone 3G。一切看起来都没有被照亮(单色)。我没有 3GS,所以我不知道它是否适用于该机。

这是我的照明设置:

- (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");
}

之后我提供法线向量等,这在较新的 iPhone 上成功渲染......但是,我真的很想支持所有三款 iPhone。 (它也适用于 iPad)。

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, which successfully renders on the newer iPhone... however, I would really like to support all three iPhones. (It also works on the iPad).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-09-20 23:11:57

呵呵,为了回答我自己的问题(并为其他有同样问题的人提供信息),灯光位置 (0, 0, 0, 0) 存在问题。将其设置为 (0, 0, -1.0, 0) 解决了该问题,并且不会干扰其他设备上的照明条件。我仍然不太明白我在这里做了什么,但我很高兴我可以提供对 iPhone 3G 的兼容性......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文