OpenGL: are texture combiner functions supported when rendering to FBO?

I have an OpenGL texture rendered to a first FBO and I need to edit its brightness, render to a second FBO and then draw it on screen.

If I render the texture to the second FBO (without modifying its brightness) and then draw it on screen, it shows up correctly.

If I try to edit brightness of rendered texture (using texture combiner functions like glTexEnv ) I get wrong output like all black or all white texture, altered contrast, ecc..

If I apply brightness regulation while drawing on screen instead of the FBO, it works great..brightness is modified as expected.

So my question is: can I use texture combiner functions like glTexEnv when I render to FBO?

This is the code which I use to modify brightness while drawing to the FBO (it doesn't work):

// "secondFBO" is the FBO I'm intended to render to after brightness regulation.
// "textureId" is the OpenGL texture attached to the first FBO that contains
// the unmodified texture.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, secondFBO);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureId);

// apply alpha filter
double t = brightnessValue;     
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
if (t > 1.0f)
{
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,      GL_ADD);
    glColor4f(t-1, t-1, t-1, t-1);
}
else
{
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,      GL_SUBTRACT);
    glColor4f(1-t, 1-t, 1-t, 1-t);
}
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB,         GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB,         GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,    GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA,       GL_TEXTURE);

// ... draw texture ...

glDisable(GL_TEXTURE_RECTANGLE_ARB);

// restore previous state
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

// draw on screen
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
// "textureId2" is the texture attached to the second FBO
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureId2);

// ... draw texture ...

glDisable(GL_TEXTURE_RECTANGLE_ARB);

Why you are not using shaders? I think it would be much easier to write the code

You are using FBO and that means that Shaders - at least GLSL 1.2 are supported by your hardware

链接地址: http://www.djcxy.com/p/33920.html

上一篇: OpenGL片段着色器不写入fbo颜色缓冲区

下一篇: OpenGL:渲染到FBO时是否支持纹理合并器功能?