Results 1 to 4 of 4

Thread: About glReadPixels

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jan 2001
    Location
    Derry, NH
    Posts
    126

    About glReadPixels

    Two objects overlap each other. The front one is partially transparent. So the color on a pixel of the overlapped part comes partially from the front object and partially from the back one. In this case, if I use glReadPixels(point.x, point.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &ret) to read the depth value of the pixel, what is this value? The depth value of the front object or the back one on that pixel?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Location
    Los Angeles, CA, USA
    Posts
    219

    Re: About glReadPixels

    The depth buffer will contain whatever was drawn there. Unless you disabled writing to the depth buffer, the transparent object will have done the writing, so the closer value will be there.

  3. #3
    Senior Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    764

    Re: About glReadPixels

    Well, when blending, you often do not use depth testing, which means that you will find the depth value of the last drawn object (unless depth writing was disabled). This can be whichever object, unless you do proper depth sorting in software (which is not always possible - depends on the geometry).

    In general, transparency is a difficult thing. If you use a technique called "order independent transparency", which involves using two z-buffer (non standard OpenGL operation), you can at least control what was drawn last - the front most or back most object.

    The easiest solution is probably to do two-pass rendering. A first pass, without transparency, where you get the depth or color information that you need (just do glReadPixels without swapping buffers - need double buffering so that you can hide this operation from the viewer). In the second pass, you draw everything with transparency as you wish the viewer to see it, and then swap front/back buffers (no glReadPixels this time).

    If you have simple planar geometry, it may be easier to sort the object by depth before drawing them (bubble sort based on the Z-value for instance, if the Z component tells the distance from the viwer), so that you draw the frontmost object last. Then you will be sure that glReadPixels will always return the depth value of the closest object.


    [This message has been edited by marcus256 (edited 02-24-2004).]

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jan 2001
    Location
    Derry, NH
    Posts
    126

    Re: About glReadPixels

    Thank you all, as always!

Similar Threads

  1. PBO and glReadPixels()
    By ehsan2004 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-24-2007, 05:20 AM
  2. about glReadPixels
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-05-2006, 08:18 PM
  3. glReadPixels
    By mphanke in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-04-2002, 08:24 AM
  4. glReadPixels()
    By hatemagnet in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-11-2002, 10:17 PM
  5. glReadPixels
    By Dagana in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 08-02-2001, 10:14 PM

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