Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Blacksheep8Bit on June 21, 2012

Title: [C++][OpenGL] Need help with FBO!
Post by: Blacksheep8Bit on June 21, 2012
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:

Code: [Select]
// 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!
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Jim on June 22, 2012
Can you post how 'texture', 'depth' and 'fbo' were defined?
Jim
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Blacksheep8Bit 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
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Jim on June 23, 2012
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
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Xetick on June 23, 2012
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 (http://www.gremedy.com/). They have a free license for 1 year. Also make sure to check the OpenGL Wiki (http://www.opengl.org/wiki/Common_Mistakes) and the pages around there.
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Blacksheep8Bit on June 23, 2012
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?
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Knurz on June 24, 2012
Are you setting your viewport to the right dimensions ?

Code: [Select]
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, width, height);
Title: Re: [C++][OpenGL] Need help with FBO!
Post by: Blacksheep8Bit on June 24, 2012
Are you setting your viewport to the right dimensions ?

Code: [Select]
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