Mac OS X 10.6 中的 OpenGL 对象有光泽/闪亮,但 10.5 则不然。为什么?
我为 Mac OS X 10.5 及更高版本编写了一个 OpenGL 屏幕保护程序,其中显示了使用行进立方体构建的旋转心脏。它在我运行 Snow Leopard (10.6) 的黑色 13.3" 开发 Macbook 上运行良好,美观且有光泽。
但是当我在较新的 Macbook 上尝试时Pro,但是运行豹子(10.5),心脏没有光泽,看起来好像只用环境光/漫射光照亮,但没有镜面光。 较新的 Macbook 配备 Nvidia 显卡,运行 10.6 的较旧 Macbook 配备 Intel XMA3100。
已将光的镜面反射分量设置为0。 >
这是我的 OpenGL 初始化代码。心脏是使用行进立方体创建的,我也在计算法线向量。
- (void)setUpOpenGL { [[glView openGLContext] makeCurrentContext]; // Synchronize buffer swaps with vertical refresh rate GLint swapInterval = 1; [[glView openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; glShadeModel(GL_SMOOTH); glClearDepth(1.0); glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); // Light GLfloat ambient_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat diffuse_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat specular_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat position_light[] = { 0.0f, 0.0f, -1.0f, 0.0f }; glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); glLightfv(GL_LIGHT0, GL_POSITION, position_light); // Material glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); GLfloat mat_ambient[] = {0.7, 0.0, 0.0, 1.0}; GLfloat mat_diffuse[] = { 0.7, 0.0, 0.0, 1.0 }; GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 0.0 }; GLfloat mat_shininess[] = { 100.0 }; glColor3f(1.0, 0.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // Copy isosurface vertices to graphics array glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, [marchingCubes vertices]); glNormalPointer(GL_FLOAT, 0, [marchingCubes normals]); }
实际的绘图代码如下所示:
- (void)drawRect:(NSRect)rect { [super drawRect:rect]; [[glView openGLContext] makeCurrentContext]; glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Adjust viewpoint to give heart beat effect glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, radius, 2*radius/3, 0, 0, 0, 0, 0, 1); // Adjust rotation to make heart spin glRotatef(rotation, 0.0f, 0.0f, 1.0f); // Draw heart glDrawArrays(GL_TRIANGLES, 0, [marchingCubes vertexCount]/3); glFlush(); [[glView openGLContext] flushBuffer]; // Rotate and scale a bit rotation += 1.0f; radius = 4.0 + 0.25*sin(rotation/4); }
有什么想法为什么镜面照明不同吗?某些显卡不支持任何指针,非常感谢。
I've written an OpenGL screensaver for Mac OS X 10.5 and higher which shows a spinning heart constructed using marching cubes. It works fine on my black 13.3" development Macbook running Snow Leopard (10.6), nice and glossy.
But when I try it on a newer Macbook Pro but running leopard (10.5), the heart isn't glossy. It appears as though it's only lit with ambient/diffuse light, but no specular light. It's as if I had set the specular component of the light to 0. The newer Macbook has an Nvidia graphics card. The one older one running 10.6 has an Intel XMA3100.
Here is my OpenGL initialization code. The heart is created using marching cubes and I am computing the normal vectors as well.
- (void)setUpOpenGL { [[glView openGLContext] makeCurrentContext]; // Synchronize buffer swaps with vertical refresh rate GLint swapInterval = 1; [[glView openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; glShadeModel(GL_SMOOTH); glClearDepth(1.0); glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); // Light GLfloat ambient_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat diffuse_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat specular_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat position_light[] = { 0.0f, 0.0f, -1.0f, 0.0f }; glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); glLightfv(GL_LIGHT0, GL_POSITION, position_light); // Material glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); GLfloat mat_ambient[] = {0.7, 0.0, 0.0, 1.0}; GLfloat mat_diffuse[] = { 0.7, 0.0, 0.0, 1.0 }; GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 0.0 }; GLfloat mat_shininess[] = { 100.0 }; glColor3f(1.0, 0.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // Copy isosurface vertices to graphics array glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, [marchingCubes vertices]); glNormalPointer(GL_FLOAT, 0, [marchingCubes normals]); }
The actual drawing code looks like this:
- (void)drawRect:(NSRect)rect { [super drawRect:rect]; [[glView openGLContext] makeCurrentContext]; glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Adjust viewpoint to give heart beat effect glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, radius, 2*radius/3, 0, 0, 0, 0, 0, 1); // Adjust rotation to make heart spin glRotatef(rotation, 0.0f, 0.0f, 1.0f); // Draw heart glDrawArrays(GL_TRIANGLES, 0, [marchingCubes vertexCount]/3); glFlush(); [[glView openGLContext] flushBuffer]; // Rotate and scale a bit rotation += 1.0f; radius = 4.0 + 0.25*sin(rotation/4); }
Any ideas why the specular lighting difference? Is specular lighting simply not supported on some graphics cards? Any pointers are much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GL_SPECULAR(和其他颜色)的默认值是
{ 0.0,0.0,0.0,1.0 }
您也可以在设置函数结束时执行此操作,以 1. 优化绘图并 2. 仔细检查是否当您设置它时,照明实际上会应用到正面。
The default for GL_SPECULAR (and other colors) is
{ 0.0,0.0,0.0,1.0 }
You may also do this at the end of your setup func to 1. optimize drawing and 2. to double check if lighting is actually applied to the front face as you set it up.