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

Thread: How does the OpenGL get (x,y) at the Z-Buffer?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    How does the OpenGL get (x,y) at the Z-Buffer?

    In my application, I drag a rectangle and want to get the object in the frontest of me in it.

    I try to enumerate the objects(triangles) and compute the three vertex mapped into Z-Buffer, (x,y,z)->(winX,winY,float_z), through gluUnProject.

    Then I get the buffer_z though glReadPixels(winX,winY), and try to judge if it is frontest by comparing float_z and buffer_z.

    But the (winX,winY) I compute have some error compare with the (winX',winY') OpenGL compute, How does the OpenGL get (winX', winY') at the Z-Buffer?

    I'm thankful for any hint or comment.

  2. #2
    Member Contributor
    Join Date
    Jan 2010
    Location
    Japan - Greece
    Posts
    99

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Hmm I am not sure I understand exactly what you ask but in case it might be that, you should know that openGL counts X and Y coordinates as strarting from the bottom left corner of the viewport as opposed to most GUI libraries so maybe you would need to invert the Y axis?
    My Blog

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Thank you.

    It is not the problem of Y-conversion.

    I want to check whether a triangle is blocked by other triangles or not through using Z-Buffer in OpenGL. However, it is the fact that this method is not good because of the error that converting Vertex to Pixel produces.

    I know that i can use ray method to check it and accelerate it by using Octree.

    But what I want to do is to check all the triangles in a dynamic rectangle by dragging mouse.



    The solid triangle in the image above which is in the frontest is what i what.

    by the way, the number of triangles in the rectangle is about 10^4.

    Thank you.

  4. #4
    V-man
    Guest

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    http://www.opengl.org/wiki/Vertex_Transformation
    explains how vertices are transformed to window space.
    The final conversion is that windowCoordinate[2] gets converted to a integer and written to the depth buffer.
    The conversion depends on the format of the z-buffer : 16 or 24 or 32 bit.

    0.0 to 1.0 values get remmaped to 0 to 0xFFF...FF

    If the precision is a problem, then use
    http://www.opengl.org/wiki/Common_Mi..._Feedback_Mode

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Quote Originally Posted by V-man
    http://www.opengl.org/wiki/Vertex_Transformation
    explains how vertices are transformed to window space.
    The final conversion is that windowCoordinate[2] gets converted to a integer and written to the depth buffer.
    The conversion depends on the format of the z-buffer : 16 or 24 or 32 bit.

    0.0 to 1.0 values get remmaped to 0 to 0xFFF...FF

    If the precision is a problem, then use
    http://www.opengl.org/wiki/Common_Mi..._Feedback_Mode
    Thanks a lot and i really appreciate it.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Quote Originally Posted by V-man
    http://www.opengl.org/wiki/Vertex_Transformation
    explains how vertices are transformed to window space.
    The final conversion is that windowCoordinate[2] gets converted to a integer and written to the depth buffer.
    The conversion depends on the format of the z-buffer : 16 or 24 or 32 bit.

    0.0 to 1.0 values get remmaped to 0 to 0xFFF...FF

    If the precision is a problem, then use
    http://www.opengl.org/wiki/Common_Mi..._Feedback_Mode
    I am sorry that the selection and picking in the OpenGL just could hit the triangles in the frustum.

    It can not get the frontest triangles which I can see in the view position.

    Thank you!

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,655

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Don't cross-post. (Re this duplicate post)

    Lots of ways to do that depending on your needs.

    One for instance is: render your entire opaque scene with depth tests (LEQUAL) and writes enables. Then re-draw with depth test EQUAL and occlusion query for each object. Any object you get a non-zero occlusion query back for, you can see. Anyone you don't, you can't.

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Quote Originally Posted by Dark Photon
    Don't cross-post. (Re this duplicate post)

    Lots of ways to do that depending on your needs.

    One for instance is: render your entire opaque scene with depth tests (LEQUAL) and writes enables. Then re-draw with depth test EQUAL and occlusion query for each object. Any object you get a non-zero occlusion query back for, you can see. Anyone you don't, you can't.
    I can't use occlusion query because of the version of OpenGL my hardware can support. Does other method which using some graceful algorithms on object space exist?

    Thank you very mush~

  9. #9
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    Are you sure?
    Occlusion queries are OpenGL 1.5, they should be supported universally (perhaps not on some ancient intel igfx's).

  10. #10
    Junior Member Newbie
    Join Date
    Apr 2011
    Posts
    11

    Re: How does the OpenGL get (x,y) at the Z-Buffer?

    I am sorry that my version of OpenGL is 1.1 and my laptop is equipped with a integrated graphics card.

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. OpenGL buffer from OpenCL buffer?
    By ksi in forum OpenCL
    Replies: 1
    Last Post: 01-20-2011, 06:20 PM
  3. Z-Buffer on OpenGL ES
    By cobrahc in forum OpenGL ES
    Replies: 2
    Last Post: 02-26-2008, 12:04 PM
  4. Triple-buffer in OpenGL?
    By Scorpion in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-18-2001, 11:17 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