我正在绘制 2 个三角形,z=0
漫射照明从上方居中。z
如果我在轴上缩放其中一个,它会改变它的光照。因为z=0
,我会认为在 z 轴上的缩放不会有任何效果。
我错过了什么?
渲染代码
// Set up the a light centered horizontally.
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
float light1Position[] = { 0.0f, 2.0f, 0.0f, 1.0f };
float light1Diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, light1Position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light1Diffuse);
// Set up the material.
float material1Diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_DIFFUSE, material1Diffuse);
// Transform such that we can draw in (-1, -1) to (1, 1) at z = 0.
glTranslated(0, 0, -1);
glScaled(2, 2, 1);
// Draw two triangles, symmetric w.r.t. to the light and camera.
glBegin(GL_TRIANGLES);
glVertex3d(-1, -1, 0);
glVertex3d( 0, 1, 0);
glVertex3d(-1, 1, 0);
glEnd();
glScaled(1, 1, 5.0); // This should be a no-op since 5 * 0 = 0.
// However, the following triangle is darker.
glBegin(GL_TRIANGLES);
glVertex3d( 1, -1, 0);
glVertex3d( 1, 1, 0);
glVertex3d( 0, 1, 0);
glEnd();
渲染结果
我已经上传了一个 Cocoa 项目,它在 github 上重现了这个。我在 Objective-C 和 C++ 中都试过这个。