这些是我的漫反射,环境和特殊设置以及我的灯光的位置。我的场景看起来像是在极光的照耀下。我尝试过调整灯光的位置,但没有任何效果。
    GLfloat greenDiffuseMaterial [] = {0.0,1.0,0.0,1.0};
    GLfloat whiteSpecularMaterial [] = {1.0,1.0,1.0,1.0};
    GLfloat greenAmbientMaterial [] = {0.0,1.0,0.2,1.0};

GLfloat greenEmissiveMaterial[] = {0.0, 1.0, 0.5,1.0};
GLfloat lightPosition[] = { 0.0,1.0,0.0, 0.0};
GLfloat ambientLight[]  = { 0.0, 0.0, 0.0, 1.0 };
GLfloat diffuseLight[]  = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specularLight[] = { 1.0, 1.0, 1.0, 1.0 };


编辑1

 for (int g =0;g<6400;g++){
    glBegin(GL_QUADS);
        if(mountText %2 ==0){glTexCoord2f(islandVert[g][0] /xscale,islandVert[g][2] / zscale);}
        else{
                glEnable(GL_NORMALIZE);
        glDisable(GL_TEXTURE_2D);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_DEPTH_TEST);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
                        glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);}
        glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);

        glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
        g++;
        if(mountText %2 ==0){glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);}
        else{
            glEnable(GL_NORMALIZE);
        glDisable(GL_TEXTURE_2D);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_DEPTH_TEST);
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);}
        glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
        glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
        g++;

        if(mountText %2 ==0){glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);}
        else{
                glEnable(GL_NORMALIZE);
        glDisable(GL_TEXTURE_2D);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_DEPTH_TEST);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
                            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);}
        glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
        glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);

        g++;

        if(mountText %2 ==0){glTexCoord2f(islandVert[g][0] / xscale, islandVert[g][2] / zscale);}
        else{
                glEnable(GL_NORMALIZE);
        glDisable(GL_TEXTURE_2D);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_DEPTH_TEST);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, greenAmbientMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, greenDiffuseMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecularMaterial);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
                            glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);}
        glNormal3f(vertNorm[g][0],vertNorm[g][1],vertNorm[g][2]);
        glVertex3f(islandVert[g][0],islandVert[g][1],islandVert[g][2]);
    glEnd();
}


基本上,在每个坐标处,我都会检查纹理是否打开,如果不是,则要将其设置为原始绿色材料。我得到的结果是对象的一侧被极端照亮,另一侧是环境光。顶点法线起作用是因为存在平滑的阴影,但我认为这可能与灯光的位置有关。当我尝试更改它时,场景保持不变。

最佳答案

仅此部分

GLfloat greenEmissiveMaterial[] = {0.0, 1.0, 0.5,1.0};


将使任何对象以颜色(0,1,0.5)出现,而与您指定的任何光源无关。真实的灯光只会增加该颜色,使其更亮。

10-06 01:27