Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Feeding Opengl a Z-buffer?

  1. #1
    Guest

    Feeding Opengl a Z-buffer?

    Is it possible to have a "saved" Z-buffer array, and then feed that value to opengl to use for each frame? I want to create a "backdrop" style game like "Resident Evil, or Myst". Is it possible to do this, and then render other objects as normal, checking against the "feed in" z-buffer?

  2. #2
    Guest

    Re: Feeding Opengl a Z-buffer?

    Yes, you can set the z-buffer using:

    Code :
    glDrawPixels(width, height, GL_DEPTH_COMPONENT, GL_FLOAT, myPtrToASavedZBufferAsFloats);

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Feeding Opengl a Z-buffer?

    glDrawPixels with GL_FLOAT will probably not be fast enough. If you want glDrawPixels at all save and restore it as GL_UNSIGNED_INT.
    Much(!) faster is to draw it once and save and restore it with the WGL_ARB_buffer_region extension.

  4. #4
    Guest

    Re: Feeding Opengl a Z-buffer?

    Ok, that last post slightly confused me. Are you saying, I can load my array into the Z-buffer in memory for frame #1, and then simply restore said buffer for frames #2-#n? Or am I WAY off of that understanding?

    Also, what is the difference between using ints vs floats for the depth buffer, I thought the depth buffer was ALL float values?

  5. #5
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Feeding Opengl a Z-buffer?

    Yes that is what is being said.

    The depth buffer only pretends to be a float value. Same as color values in OpenGL, the actual hardware uses a hidden internal representation.

  6. #6
    Guest

    Re: Feeding Opengl a Z-buffer?

    Ok, after reading that last post, I am now a little worried. Say I create a "grand" scene in blender3D, or lightwave, etc. Now I render it using said program and save that render to a texture file. Now I find a way to either save, or export the Z-buffer built of that image, from said program.

    I take the rendered image, and load it as a texture on a backdrop quad, and render the quad. I then overwrite the current OpenGL depth buffer, with the depth buffer I exported from my program (I am attempting to create a backdrop, that objects can be rendered "in" kind of like how resident evil, although it is a backdrop image, you can walk in front of some stuff, etc). Now, when I attempt to render any "new" objects in my scene, will they work with the current depth buffer? OR, will there be problems? I was figuring as long as I used the same "unit" dimentions, frustum, etc, there wouldnt, but now I am unsure. I dont want to end up with somethings being placed and rendered correcly, and others showing halfway through stuff.

  7. #7
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Feeding Opengl a Z-buffer?

    If you have the same setup for projection and modelview matrices and depthrange, you can do this (pseudo code):
    Code :
    // Init backdrop (slow)
    glDrawPixels(GL_RGBA) // fill color
    glDrawPixels(GL_DEPTH_COMPONENT) // depth buffer 
    wglSaveBufferRegion(whole_window) // depth and color
    for (animation)
    {
      draw_moving_objects()
      SwapBuffers()
      wglRestoreBufferRegion() // either the whole window or if your pixelformat 
      // is PFD_SWAP_COPY and you know where you drew the objects, 
      // only those rects
    }

  8. #8
    Senior Member Regular Contributor
    Join Date
    Nov 2004
    Location
    San Diego, CA, USA
    Posts
    122

    Re: Feeding Opengl a Z-buffer?

    I'm on a Mac, so I can't use WGL_ARB_buffer_region. Is there any other way to restore a depth buffer that would be faster than the glReadPixels/glDrawPixels route?

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: Feeding Opengl a Z-buffer?

    Those posts were written over 3 years ago. Things have changed.

    The correct way to save the depth buffer nowadays is to use a Renderbuffer for the depth buffer. You can use the EXT_framebuffer_blit extension to copy from/to renderbuffers.

  10. #10
    Senior Member Regular Contributor
    Join Date
    Nov 2004
    Location
    San Diego, CA, USA
    Posts
    122

    Re: Feeding Opengl a Z-buffer?

    None of the computers I have access to support EXT_framebuffer_blit, so I guess things haven't changed enough. Thanks anyway.

Page 1 of 2 12 LastLast

Similar Threads

  1. opencl buffer from premade opengl buffer
    By MohamedSakr in forum OpenCL
    Replies: 0
    Last Post: 11-21-2012, 03:42 PM
  2. How does the OpenGL get (x,y) at the Z-Buffer?
    By litstrong in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 05-04-2011, 07:26 AM
  3. OpenGL buffer from OpenCL buffer?
    By ksi in forum OpenCL
    Replies: 1
    Last Post: 01-20-2011, 06:20 PM
  4. Z-Buffer on OpenGL ES
    By cobrahc in forum OpenGL ES
    Replies: 2
    Last Post: 02-26-2008, 12:04 PM
  5. Z-Buffer in OpenGL
    By Brorsson in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-14-2001, 03:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean