我在maya中创建了一个LocatorNode,它使用OpenGL(Viewport 2.0)显示一个多维数据集,其代码如下:
glBegin (GL_QUADS);
// top
glNormal3f (0.0f, 0.0f, 1.0f); glVertex3f (1, 1, 1);
glNormal3f (0.0f, 0.0f, 1.0f); glVertex3f (1, -1, 1);
glNormal3f (0.0f, 0.0f, 1.0f); glVertex3f (-1, -1, 1);
glNormal3f (0.0f, 0.0f, 1.0f); glVertex3f (-1, 1, 1);
// bottom
glNormal3f (0.0f, 0.0f, -1.0f); glVertex3f (1, 1, -1);
glNormal3f (0.0f, 0.0f, -1.0f); glVertex3f (-1, 1, -1);
glNormal3f (0.0f, 0.0f, -1.0f); glVertex3f (-1, -1, -1);
glNormal3f (0.0f, 0.0f, -1.0f); glVertex3f (1, -1, -1);
// front
glNormal3f (1.0f, 0.0f, 0.0f); glVertex3f (1, 1, -1);
glNormal3f (1.0f, 0.0f, 0.0f); glVertex3f (1, -1, -1);
glNormal3f (1.0f, 0.0f, 0.0f); glVertex3f (1, -1, 1);
glNormal3f (1.0f, 0.0f, 0.0f); glVertex3f (1, 1, 1);
// back
glNormal3f (-1.0f, 0.0f, 0.0f); glVertex3f (-1, 1, -1);
glNormal3f (-1.0f, 0.0f, 0.0f); glVertex3f (-1, 1, 1);
glNormal3f (-1.0f, 0.0f, 0.0f); glVertex3f (-1, -1, 1);
glNormal3f (-1.0f, 0.0f, 0.0f); glVertex3f (-1, -1, -1);
// right
glNormal3f (0.0f, 1.0f, 0.0f); glVertex3f (-1, 1, -1);
glNormal3f (0.0f, 1.0f, 0.0f); glVertex3f (1, 1, -1);
glNormal3f (0.0f, 1.0f, 0.0f); glVertex3f (1, 1, 1);
glNormal3f (0.0f, 1.0f, 0.0f); glVertex3f (-1, 1, 1);
// left
glNormal3f (0.0f, -1.0f, 0.0f); glVertex3f (-1, -1, -1);
glNormal3f (0.0f, -1.0f, 0.0f); glVertex3f (-1, -1, 1);
glNormal3f (0.0f, -1.0f, 0.0f); glVertex3f (1, -1, 1);
glNormal3f (0.0f, -1.0f, 0.0f); glVertex3f (1, -1, -1);
glEnd ();
但是,正如您在下图中看到的那样,当我用Maya(左侧)直接创建的另一个立方体正确着色时,我的立方体(右侧)是平面阴影。 知道我需要在OpenGL代码中更改哪些内容才能获得正确的着色?
答案 0 :(得分:2)
首先,您必须通过调用glEnable(GL_LIGHTING)
来启用闪电。然后你启用一个glEnable(GL_LIGHT0)
的光源,它是第一个索引为0的光源,但你有8个插槽,选择你想要的光线,而不是真正重要的光线。然后你可以设置光源的漫反射颜色:glLightfv(GL_LIGHT0, GL_DIFFUSE, { 0.8f, 0.8f, 0.8f, 1.0f} )
,这里它是一个非常白的颜色,可能是浅灰色。如果你有一个圆柱体,我会说你可以选择平面阴影和光滑的阴影但是因为你有一个立方体它是一样的。顺便说一句,平面阴影用于左边的立方体,右边的立方体根本没有阴影,它到处都有相同的颜色,因此颜色根本不依赖于表面法线。