PDA

View Full Version : Framebuffer Object, can't write to multiple Textures



Abaddon
10-11-2007, 09:33 AM
Hello,
i am trying to write to 2 textures attached to a framebuffer object, but i can't seem to get it to work.
First, in my shader i have the line

#extension GL_ARB_draw_buffers : enableand i get the following "warning C7508: extension GL_ARB_draw_buffers not supported" even though the extension string says my card is capable of GL_ARB_draw_buffers (NV GeForce 7800GS with driver version 6.14.10.9371)

I set the FBO up as follows

//create textures
glGenTextures(2, m_shadowmaps);
for (int l = 0; l < 2; l++)
{
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,m_shadowmap s[l]);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGB,320 ,240,0,GL_RGB,GL_UNSIGNED_BYTE, NULL);
}

//init FBO
glGenFramebuffersEXT(1, &amp;fbo_shadow);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo_shadow );
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_shadowmaps[0], 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, m_shadowmaps[1], 0);
glDrawBuffers (2,{GL_COLOR_ATTACHMENT0_EXT,GL_COLOR_ATTACHMENT1_ EXT});Now, even if i use something like

gl_FragData[0] = vec4(0.5, 0.0, 0.0, 1.0);
gl_FragData[1] = vec4(0.0, 0.0, 0.5, 1.0);in my fragment shader, the resulting textures are always yellowish green or some other ugly color, no matter what values i use for gl_FragData.
Any help would be greatly appreciated.

kon
10-11-2007, 11:51 AM
Your setup is ok.
Just to be sure:
No glErrors?
You are using texture coordinates in the range [320, 240] and not [0.0, 1.0]?
Try glGetTexImage to check the data in the texture.

Lindley
10-11-2007, 12:57 PM
Simple sanity check: You can use glClear with a specific glClearColor to test whether you're able to write to those textures at all. That will give you a better idea where the problem is.

Abaddon
10-11-2007, 02:25 PM
First, thanks for the fast replies and its good to know that at least my setup is correct ;)
I want to use the resulting textures as depth maps to check for occlusion in another shader using projective texturing.
I am setting the viewport to the same size as the textures before rendering to the framebuffer, that should result in the correct coordinates or am i completly wrong here?
I was getting a couple gl_invalid_operation errors when i was using display lists, but not using them got rid of that.
But i will check that again tomorrow and try out your suggestions.

Lindley
10-11-2007, 08:03 PM
Setting the viewport to the size of the texture should be fine if you're rendering to them by drawing a screen quad. The origin being 0,0 is the important part; then the width and height will just behave like a scissor test.

Make sure you've got your orthographic projection set up right if you're doing that, of course.

oc2k1
10-12-2007, 04:51 AM
You should update your drivers the 93xx series is very old