Jump to content
  • Advertisement
Sign in to follow this  
LackOfGrace

Frame - Render Buffer and depth maps

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im rendering my scene to a texture using frame buffers. The color map works fine, but the depth map fails i tried to bind a texture to the depth to the framebuffer, but that didnt work. so now i have attached a render buffer so that the depth test will work. i need to get the depth data into a texture, since i can make some pretty cool effects that way. can i in some way properly attach a texture to the framebuffer, or can i convert the data in the render buffer into a texture?

Share this post


Link to post
Share on other sites
Advertisement
You shouldn't need to use a render buffer to get a depth map. The render buffer is like a storage space to do some offscreen rendering IIRC.

1st do you have your window setup correctly for a depth buffer and at least 16bits or 24bits?

I have my depth textures rendering just fine without using a RB...

Share this post


Link to post
Share on other sites
When i render to the screen (backbuffer) the depth buffer works.
When i render to a texture via a frame buffer the depth test isnt working.
When i attach a render buffer to the frame buffers depth buffer the depth test works.


here is my code for setting up the renderbuffer.
sample code for attaching a texture would be welcome.
ive tried but it didnt work

Quote:

//==========================================================//
//Generate Frame Buffer
//==========================================================//
glGenFramebuffersEXT( 1 , &mFrameBuffer );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT , mFrameBuffer );

//==========================================================//
//Generate Depth Buffer
//==========================================================//
glGenRenderbuffersEXT(1, &mDepthBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT,mWidth,mHeight);

//==========================================================//
//Bind Depth Buffer
//==========================================================//
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,mDepthBuffer);

Share this post


Link to post
Share on other sites
first u need to gen null texture for depth-map like this:

glBindTexture(GL_TEXTURE_2D,depth_map);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,mapsizex,mapsizey,0
,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,NULL);

after that u need to attach depth map from frame buffer to this texture depth_map
by doing this :

glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_map, 0);

glReadBuffer(GL_NONE);
glDrawBuffer(GL_NONE);


this done after setupping the frame buffer

take care ^_^.

Share this post


Link to post
Share on other sites
Got it to work.
heres the code if anyone gets the same problem.

opengl is really picky when it comes to texture types.
Quote:

//==========================================================//
//Generate Frame Buffer
//==========================================================//
glGenFramebuffersEXT( 1 , &mFrameBuffer );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT , mFrameBuffer );

//==========================================================//
//Generate Color Texture
//==========================================================//
glGenTextures( 1 , &mColorTexture );
glBindTexture( GL_TEXTURE_2D , mColorTexture );
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,BUFFER_WIDTH,BUFFER_HEIGHT,0,GL_RGBA,GL_UNSIGNED_BYTE,0);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

//==========================================================//
//Generate Depth Texture
//==========================================================//
glGenTextures( 1 , &mDepthTexture );
glBindTexture( GL_TEXTURE_2D , mDepthTexture );
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,BUFFER_WIDTH,BUFFER_HEIGHT,0,GL_DEPTH_COMPONENT,GL_INT,0);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

//==========================================================//
//Bind Color Texture
//==========================================================//
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_2D , mColorTexture , 0 );

//==========================================================//
//Bind Depth Texture
//==========================================================//
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_TEXTURE_2D , mDepthTexture , 0 );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!