渲染到帧缓冲区时,灰色材质看起来很暗

时间:2014-10-27 08:37:30

标签: c++ opengl

当我指定任何绝对灰色的材料时:

 glAmbientColor [0] = 0.2;
 glAmbientColor [1] = 0.2;
 glAmbientColor [2] = 0.2;
 glAmbientColor [3] = 1;

 glDiffuseColor [0] = 0.8;
 glDiffuseColor [1] = 0.8;
 glDiffuseColor [2] = 0.8;
 glDiffuseColor [3] = 1;

 glSpecularColor [0] = 0.2;
 glSpecularColor [1] = 0.2;
 glSpecularColor [2] = 0.2;
 glSpecularColor [3] = 1;

 glEmissiveColor [0] = 0;
 glEmissiveColor [1] = 0;
 glEmissiveColor [2] = 0;
 glEmissiveColor [3] = 1;

并使用以下内容渲染对象:

 glEnable (GL_LIGHTING);

 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,   glAmbientColor);
 glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,   glDiffuseColor);
 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  glSpecularColor);
 glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,  glEmissiveColor);
 glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS, 0.2);

到自定义帧缓冲区,灰色材质看起来很暗,即。它具有更高的对比度。渲染到默认帧缓冲区让材质正常显示。任何其他绝对灰色的材料总是正常呈现。

我没有特殊的OpenGL选项集。我在法线上总是做一个glEnable(GL_NORMALIZE)。

我是否必须以特殊方式配置帧缓冲区?有没有人与NVidia显卡和最新的驱动程序(331.89)有相同的问题?

例如,如果我稍微更改diffuseColor,如:

glDiffuseColor [0] = 0.8 + 0.0001;

材料总是正常呈现!

我创建了帧缓冲区,如下所示:

    glGenFramebuffers (1, &id);

    // Bind frame buffer.
    glBindFramebuffer (GL_FRAMEBUFFER, id);

    // The color buffer
    glGenRenderbuffers (1, &colorBufferId);
    glBindRenderbuffer (GL_RENDERBUFFER, colorBufferId);
    glRenderbufferStorage (GL_RENDERBUFFER, GL_RGBA8, width, height);
    glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBufferId);

    // The depth buffer
    glGenRenderbuffers (1, &depthBufferId);
    glBindRenderbuffer (GL_RENDERBUFFER, depthBufferId);
    glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
    glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBufferId);

1 个答案:

答案 0 :(得分:0)

我自己发现,它与帧缓冲区无关。一切正常。问题首先发生在后期图像处理过程中,因为图像保存为单色PNG而不是RGB png。

实际上是这个问题: ImageMagick Reduces Colorspace to Gray