Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
2年前关闭。
我无法让照明仅在地面的下降部分工作。以下是我针对地面和地面下降的代码(使其成为一条沟):
因此,没有照明正常工作的代码是“ glBegin(GL_QUADS)”的中间两个代码段
不。那不是有效的法线向量,将完全破坏任何照明计算。
下一个
至少是一些非null的向量,但是对于您所描述的脸部来说并不正常,因此照明将是错误的。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
2年前关闭。
我无法让照明仅在地面的下降部分工作。以下是我针对地面和地面下降的代码(使其成为一条沟):
static void ground(double x, double y, double z, double dx, double dy,
double dz){
float white[] = {1,1,1,1};
float Emission[] = {0.0,0.0,0.01*emission,1.0};
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,shiny);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Emission);
// Save transformation
glPushMatrix();
// Offset, scale and rotate
glTranslated(x,y,z);
glScaled(dx, dy, dz);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, textures[2]);
glBegin(GL_QUADS);
glColor3f(0.5, 1.0, 0.5);
glNormal3f(0,0,0);
glTexCoord2f(0.0, 0.0); glVertex3f(-100, 0, -300);
glTexCoord2f(300.0,0.0); glVertex3f(-100,0,300);
glTexCoord2f(300.0,300.0); glVertex3f(-3,0,300);
glTexCoord2f(0.0,300.0); glVertex3f(-3,0,-300);
glEnd();
glBindTexture(GL_TEXTURE_2D, textures[2]);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.5);
glNormal3f(0,0,-1);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.99,0,-300);
glTexCoord2f(300.0,0.0); glVertex3f(-2.99,0,300);
glTexCoord2f(300.0,300.0); glVertex3f(-1,-1,300);
glTexCoord2f(0.0,300.0); glVertex3f(-1,-1,-300);
glEnd();
glBindTexture(GL_TEXTURE_2D, textures[2]);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.5);
glNormal3f(0,0,1);
glTexCoord2f(0.0, 0.0); glVertex3f(0.99,-1,-300);
glTexCoord2f(300.0,0.0); glVertex3f(0.99,-1,300);
glTexCoord2f(300.0,300.0); glVertex3f(2.99,0,300);
glTexCoord2f(0.0,300.0); glVertex3f(2.99,0,-300);
glEnd();
glBindTexture(GL_TEXTURE_2D, textures[2]);
glBegin(GL_QUADS);
glColor3f(0.5, 1.0, 0.5);
glNormal3f(0,0,0);
glTexCoord2f(0.0, 0.0); glVertex3f(2.99, 0, -300);
glTexCoord2f(300.0,0.0); glVertex3f(2.99,0,300);
glTexCoord2f(300.0,300.0); glVertex3f(100,0,300);
glTexCoord2f(0.0,300.0); glVertex3f(100,0,-300);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
因此,没有照明正常工作的代码是“ glBegin(GL_QUADS)”的中间两个代码段
最佳答案
这只是GIGO的一个实例(垃圾进,垃圾出):
glNormal3f(0,0,0);
不。那不是有效的法线向量,将完全破坏任何照明计算。
下一个
glNormal3f(0,0,-1);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.99,0,-300);
glTexCoord2f(300.0,0.0); glVertex3f(-2.99,0,300);
glTexCoord2f(300.0,300.0); glVertex3f(-1,-1,300);
glTexCoord2f(0.0,300.0); glVertex3f(-1,-1,-300);
至少是一些非null的向量,但是对于您所描述的脸部来说并不正常,因此照明将是错误的。
关于c - 照明在opengl中不工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44765517/
10-13 04:37