Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How do I render the Depth Buffer using FBOs?

  1. #1
    Intern Contributor
    Join Date
    Feb 2006
    Posts
    62

    How do I render the Depth Buffer using FBOs?

    I have a test app that I wrote some months ago which used the NV Depth Texture extension. In the end what is rendered is the contents of the depth buffer. I want to modify this app to use FBOs. How can I do this using FBOs? Also, what is the relation between FBO and Render Buffers?

    CD

  2. #2
    Intern Newbie
    Join Date
    Jun 2004
    Posts
    34

    Re: How do I render the Depth Buffer using FBOs?

    This is from the EXT_fbo spec, you might want to read it:
    Also, what is the relation between FBO and Render Buffers?
    Again, from the EXT_fbo spec:
    (3) As a consequence of issue (2), this extension adds the concept of
    share-able, non-texturable renderable entitites that can be
    used as color buffers, depth buffers, stencil buffers, etc.
    The OpenGL spec refers to these entities as "logical buffers".
    What should this spec call them?

    RESOLUTION: "renderbuffer", (one word)

    We could just call them "logical buffers", but is there a
    better name?

    The group considered:
    logical buffer - possible, kind of general
    render buffer - clear, (one word or two?)
    renderable - clear, but may conflict with glx "drawable"
    drawable - confusing: glx "drawable" == gl "framebuffer"
    render surface - possible
    render target - possible
    image buffer - may get confused with Tex"Image"
    image - may get confused with Tex"Image"
    surface buffer - too verbose?
    surface - too general
    others???

    The group felt "render buffer " (or possibly "renderbuffer")
    provides for the clearest expression of the purpose for
    these buffers.

    We finally decided on "renderbuffer" because we didn't want
    to use "render" as an adjective to describe a generic
    buffer, but rather decided to coin a new compound word to
    describe this concept.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2005
    Location
    Thailand
    Posts
    5

    Re: How do I render the Depth Buffer using FBOs?

    CelticDaddio. Would you mind if I post my question in your topic. I've gotten the same problem and searched for the solution for two days. I have written a code for casting shadow using shadow map. I have ever used FBO for creating depth texture before, so, I use it again in this program. Although, the code has a littile change from the previous, it doesn't work this time. I search through every posted topic about FBO and follow any suggessions in the forum but it still not work.

    This is from my FBO generation and texture binding routine:
    Code :
    	fbo = new FramebufferObject();
    	fbo->Bind();
     
    	glGenTextures(1, &offscnTexture);
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, offscnTexture);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    	glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT,
    		GL_FLOAT, 0);
     
    	fbo->AttachTexture(GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, offscnTexture);
     
    	fbo->IsValid();
    	FramebufferObject::Disable();
    This is how I render to depth texture:
    Code :
    // Render to texture
    	fbo->Bind();
    	glDrawBuffer(GL_NONE);
    	glReadBuffer(GL_NONE);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	camera.setUp(45.0, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);
    	camera.setPosition(50.0, 100.0, 100.0);
    	camera.lookAt(0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     
    	AddLight();
    	glEnable(GL_LIGHTING);
     
    	glRotatef(angle1++, 0.0, 1.0, 0.0);
    	teapot->render(SOLID);
    	FramebufferObject::Disable();
     
    	// Render to primary buffer
    	glClearColor(0.0, 0.0, 0.0, 0.0);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	// Initialize view
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	glRotatef(angle2, 0.0, 1.0, 0.0);
     
    	glDisable(GL_LIGHTING);
    	glDisable(GL_CULL_FACE);
    	glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, offscnTexture);
    	glBegin(GL_QUADS);
    		glTexCoord2f(0.0, 0.0); glVertex2f(-0.8, -0.8);
    		glTexCoord2f(1.0, 0.0); glVertex2f(0.8, -0.8);
    		glTexCoord2f(1.0, 1.0); glVertex2f(0.8, 0.8);
    		glTexCoord2f(0.0, 1.0); glVertex2f(-0.8, 0.8);
    	glEnd();
    And this is the result:


    Can any one tell me what am I do wrong in this code.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,749

    Re: How do I render the Depth Buffer using FBOs?

    This has been asked many times, make a search !

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2005
    Location
    Thailand
    Posts
    5

    Re: How do I render the Depth Buffer using FBOs?

    Yeah I know this is asked many times because I make a lot of search not only this forum but also the google. But, you know, still I don't get why my code not work, after I've tried every suggestion and solution in this world. I think my problem does not come from a misconception in FBO. I think it in my code but I can't figure out where's the problem (if not because this problem is beyond my knowledge, it must be a very silly mistake I made). So, I need some one to point me out. Honesly, I'm not a man who asks some one help and sit back and wait for solution, I also do my resarch myself.

  6. #6
    Intern Newbie
    Join Date
    Jan 2002
    Location
    Steamboat Springs, CO, USA
    Posts
    43

    Re: How do I render the Depth Buffer using FBOs?

    Ohms, did you enable depth testing? i.e. glEnable(GL_DEPTH_TEST)?

    -Brian

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,749

    Re: How do I render the Depth Buffer using FBOs?

    Didn't want to hurt you. Did you looked at the specs ?

    http://oss.sgi.com/projects/ogl-samp...fer_object.txt

    Look at the examples.

    Also, what does the validation test of the FBO returns ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •