View Full Version : FBO and Fragment Shaders on Nvidia / Linux

06-24-2005, 12:46 AM
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;

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);


// bind this texture to the current framebuffer obj. as
// color_attachement_0
GL_COLOR_ATTACHMENT0_EXT, TextureTarget, TextureId, 0);

//see if everything is OK

//'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,

// Render My Object

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

glBindTexture(TextureTarget, TextureId);


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.


Java Cool Dude
06-25-2005, 08:31 PM
If you're activating a single texture per object you don't need this line:

06-27-2005, 12:38 AM
I've tried both with and without the glActiveTexture , it doesn't work either way.

Has anyone got a very simple example of this that should work? I'm trying to work out if this is a bug in the driver or not.



06-27-2005, 07:51 AM
It seems that FBOs don't support TEXTURE_RECTANGLE as their target. Luckily GL 2.0 supports NPOT textures out of the box which means this isn't a problem, but it took ages to track this down.

Ah well.


06-27-2005, 11:35 PM
Does NPOT work on the GFFX in hardware?

I know that on ATI I can use NPOT as long as I adhere to the restrictions of rectangle textures. But on NVIDIA I'm not so sure, their release notes state that NPOT will fall back to software, they don't mention any usage pattern that is hardware...

06-28-2005, 12:18 AM
I'm trying it out with 500x500 and 512x512 textures and there seems to be no great slow down (i.e. not software). I've upgraded to a 6800 and this might be why, but it works without a problem.

06-28-2005, 01:27 AM
Of course, the 6x00 series fully supports NPOT. I'm talking of FX class hardware... I can't try myself right now because I have no access to an FX here. Perhaps I can test it next weekend...

06-28-2005, 07:24 AM
Originally posted by Overmind:
Does NPOT work on the GFFX in hardware?
GeForce FX (NV3x) does not support general non-power-of-2 textures (with mipmaps etc.), only NV_texture_rectangle.

GeForce 6 series supports fully general NPOT.

06-28-2005, 07:54 AM
Originally posted by jgreasley:
It seems that FBOs don't support TEXTURE_RECTANGLE as their target. NVIDIA's FBO implementation definately does support TEXTURE_RECTANGLE.

There's a simple example on the NVIDIA registered developer website that shows how to use FBO with fragment programs.