Author Topic: [C++][OpenGL] Need help with FBO!  (Read 6365 times)

0 Members and 1 Guest are viewing this topic.

Offline Blacksheep8Bit

  • *Custum Title goes here*
  • C= 64
  • **
  • Posts: 91
  • Karma: 36
  • *useless thing to write goes here*
    • View Profile
[C++][OpenGL] Need help with FBO!
« 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!
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++][OpenGL] Need help with FBO!
« Reply #1 on: June 22, 2012 »
Can you post how 'texture', 'depth' and 'fbo' were defined?
Jim
Challenge Trophies Won:

Offline Blacksheep8Bit

  • *Custum Title goes here*
  • C= 64
  • **
  • Posts: 91
  • Karma: 36
  • *useless thing to write goes here*
    • View Profile
Re: [C++][OpenGL] Need help with FBO!
« Reply #2 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:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++][OpenGL] Need help with FBO!
« Reply #3 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
« Last Edit: June 23, 2012 by Jim »
Challenge Trophies Won:

Offline Xetick

  • Atari ST
  • ***
  • Posts: 132
  • Karma: 80
    • View Profile
    • Plane9
Re: [C++][OpenGL] Need help with FBO!
« Reply #4 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. 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:

Offline Blacksheep8Bit

  • *Custum Title goes here*
  • C= 64
  • **
  • Posts: 91
  • Karma: 36
  • *useless thing to write goes here*
    • View Profile
Re: [C++][OpenGL] Need help with FBO!
« Reply #5 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?
Challenge Trophies Won:

Offline Knurz

  • Atari ST
  • ***
  • Posts: 121
  • Karma: 25
    • View Profile
    • GitHub Repository
Re: [C++][OpenGL] Need help with FBO!
« Reply #6 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);
Remember what the dormouse said: Feed your head

Offline Blacksheep8Bit

  • *Custum Title goes here*
  • C= 64
  • **
  • Posts: 91
  • Karma: 36
  • *useless thing to write goes here*
    • View Profile
Re: [C++][OpenGL] Need help with FBO!
« Reply #7 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
Challenge Trophies Won: