OpenGL renderer string: GeForce FX 5900XT/AGP/SSE2
OpenGL version string: 2.0.0 NVIDIA 76.64
Hello there,
I’ve got a strange problem with FBOs that is really annoying me.
My FBO is being created no problem, I can render to it, and use it as a texture in the fixed function pipeline, all is good.
If I try to use the FBO as Texture0 in a fragment shader, the texture is entirely black. Even with a colored clear without any rendering.
I can run exactly the same code using PBuffers instead and the Fragment shader works without a problem.
Fragment Shader
sampler2D BaseImage;
varying
void main(void)
{
vec4 color = texture2D(BaseImage, gl_TexCoord[0].st);
gl_FragColor = color;
}
Vertex Shader
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
FBO Setup Code
// generate a framebuffer objectId
glGenFramebuffersEXT(1, &FrameBufferId);
glGenTextures(1, &TextureId);
//bind the framebuffer so operations will now occur on it
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferId);
// initialize texture that will store the framebuffer image
glBindTexture(TextureTarget, TextureId);
glTexImage2D(TextureTarget, 0, InternalFormat, Width,Height, 0,
Format, ExternalFormat,NULL);
PRINT_OGL_ERROR
// bind this texture to the current framebuffer obj. as
// color_attachement_0
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT, TextureTarget, TextureId, 0);
//see if everything is OK
CHECK_FRAMEBUFFER_STATUS()
//'unbind' the frambuffer object, so subsequent drawing ops are not
// drawn into the FBO.
// '0' means "windowing system provided framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
FBO Rendering Code
// Bind the FBO and Texture
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FrameBufferId);
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
TextureTarget,
TextureId,
0);
// Render My Object
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glEnable(TextureTarget);
glBindTexture(TextureTarget, TextureId);
glActiveTextureARB(GL_TEXTURE0_ARB);
ActivateShaderProgram();
RenderAnotherObject();
Does anyone out there have an small working example of FBOs being used with Fragment shaders that I can try?
I’ve ensured the Fragment shader is being run correctly by setting the output to a known color. This works correctly. It is doing the texture lookup and the result is black.
I don’t get an GL errors and I’ve littered the code with checks.
Jack