I am trying to implement a glow effect using cG, multitexturing and render-to-texture. I have each of the parts working, so I can execute cG programs, I can multi texture, and I can render-to-texture.
In order for the effect to work, I render the glow sources to a texture, then bind that texture to all four texture units and render full screen quads to a second textyre using a cg vertex and fragment program to createa horizontal blur. I then render this second texture back into the first texture to create the vertical blur, and then I finally render the first texture over the main buffer to create the glow in the scene.
All of this works ‘fine’ if I only bind the rendered texture to texture unit 0 for the bluring (leaving the other units off). If I do this, I get a very slight glow-like effect. But if I bind the same texture to the other texture units, nothing is rendered into the texture during the blur steps, so the glow I end up adding to the scene is black.
The code I am using to do the binding looks like this:
glClientActiveTexture(GL_TEXTURE0 + texUnitID);
glActiveTexture(GL_TEXTURE0 + texUnitID);
glEnable(mTarget);
glBindTexture(mTarget, mTextureID);
if(mBindCount == 0 && !wglBindTexImageARB(mHpBuffer, WGL_FRONT_LEFT_ARB))
{
WarningError(“Could not bind p-buffer to render texture!”);
return;
}
++mBindCount;
The code for deactivating the texture is:
glClientActiveTexture(GL_TEXTURE0 + texUnitID);
glActiveTexture(GL_TEXTURE0 + texUnitID);
–mBindCount;
if(mBindCount == 0 && !wglReleaseTexImageARB(mHpBuffer, WGL_FRONT_LEFT_ARB))
{
WarningError(“Could not release p-buffer from render texture!”);
}
If I don’t have all that mucking about with mBindCount, then the second time I try to bind the texture (that is, to texture unit 1), wglBindTexImageARB fails.
So, does anyone have any ideas?