• Welcome to Dark Bit Factory & Gravity.
 

[C++][OpenGL] Need help with FBO!

Started by Blacksheep8Bit, June 21, 2012

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Blacksheep8Bit

So, heres the situation, my fbo works very well when i only render the color texture, but when i try to also render a depth texture the color texture goes all white, so what should i do? Heres the code:

// Color Texture
glGenTextures(1,texture);
glBindTexture(GL_TEXTURE_2D,*texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, def.Width, def.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D,0);


// Depth Texture
glGenTextures(1,depth);
glBindTexture(GL_TEXTURE_2D, *depth);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, def.Width, def.Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glBindTexture(GL_TEXTURE_2D,0);


// Framebuffer
glGenFramebuffersEXT(1,fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,*fbo);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, *texture, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, *depth, 0); // <- With this the color texture becomes all white, without it everything works perfectly!

glBindFramebufferEXT(GL_FRAMEBUFFER,0);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
MessageBox(0,"Looks like we are having problems with Post Processing...","Did it work?!",MB_OK);


What should i do? Remembering everything works well without the function i pointed above in the code!
Challenge Trophies Won:

Jim

Can you post how 'texture', 'depth' and 'fbo' were defined?
Jim
Challenge Trophies Won:

Blacksheep8Bit

Quote from: Jim on June 22, 2012
Can you post how 'texture', 'depth' and 'fbo' were defined?
Jim
Is in the code i posted above, the are "GLuint"'s
Challenge Trophies Won:

Jim

#3
What are they pointing at?  Normally it'd look like

gluint a;
glGenTexture(1, &a)

But you seem to have
gluint *a;
glGenTexture(1, a)

which won't work unless 'a' is pointing at something.

Just checking.

Jim
Challenge Trophies Won:

Xetick

Except what jim pointed out I dont see anything wrong with the code.
But I can highly recommend that you run your program using gDebugger. They have a free license for 1 year. Also make sure to check the OpenGL Wiki and the pages around there.
Plane9 - Home of the Plane9 3d screensaver/music visualizer
Challenge Trophies Won:

Blacksheep8Bit

I've already solved the problem, i was forgetting to clear the Depth buffer in the display loop ^^", but i still have another problem: The texture generated from this FBO has a white border into it's top, how can i fix this?
Challenge Trophies Won:

Knurz

Are you setting your viewport to the right dimensions ?

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, width, height);
Remember what the dormouse said: Feed your head

Blacksheep8Bit

Quote from: Knurz on June 24, 2012
Are you setting your viewport to the right dimensions ?

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, width, height);

Yes, actually it's the same size of the screen (800,500), so i don't need to change then viewport between the glBindFramebuffer's
Challenge Trophies Won: