过多的镜面光opengl

时间:2014-04-06 11:37:38

标签: c opengl lighting

这些是我对漫反射,环境光和specualar以及光线位置的设置。我的场景看起来非常明亮,有点光。我试过调整光线的位置但是没有任何东西。     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();
}

基本上每个坐标我检查纹理是否打开,如果不是,我想将它设置为原始绿色材质。我得到的结果是我的物体的一侧极亮,而另一侧是环境。顶点法线是有效的,因为有平滑的阴影,但我认为它可能与我的光的位置有关。当我尝试更改它时,场景保持不变。

1 个答案:

答案 0 :(得分:0)

仅此部分

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

将使任何对象以彩色(0,1,0.5)显示,与您指定的任何光源无关。真正的灯光只会添加到那种颜色,使它更亮。