Skip to main content
gamedev.net
🔒 Locked

Frame - Render Buffer and depth maps

Started by LackOfGrace Jan 31, 2007 at 10:52 AM 3 replies 950+ views
Original Post
LackOfGrace
LackOfGrace
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?
MARS_999
MARS_999
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...
LackOfGrace
LackOfGrace
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);
ff8
ff8
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 ^_^.
LackOfGrace
LackOfGrace
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 );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.