Results 1 to 5 of 5

Thread: Always on top (in front) sphere

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Always on top (in front) sphere

    Hi All,

    Suppose to have a scene of multiple 3D objects. I would like to draw a sphere staying always on top (in front) of the others while rotating the scene.

    I thought about drawing first all the other 3D objects then disabling the DEPTH_TEST and drawing the sphere but the result is: an always on top sphere, but with its triangles messed up as well.

    What is the best approach for this problem?

    Thanks,

    Alberto

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2005
    Location
    South Tyrol, Italy
    Posts
    107

    Re: Always on top (in front) sphere

    Instead of disabling the depth test you can try to simply clear the depth buffer.

    [ www.trenki.net | vector_math (3d math library) | software renderer ]

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

    Re: Always on top (in front) sphere

    Because a sphere is a convex object you can also simply switch off depth test and enable back face culling while rendering the sphere.
    If it is transparent, render it twice, first with front face culling, then with back face culling.

  4. #4
    Member Newbie
    Join Date
    Apr 2008
    Location
    Germany
    Posts
    38

    Re: Always on top (in front) sphere

    OpenGL renders triangles in the order your applications specifies them. The depth test prevents fragments (aka pixels) to be drawn, if there is already a pixel at the given position which is - according to it's depth - supposed to be in front.

    If you disable depth testing, your triangles will be draw in the order you specify them. Because that order will most likely not be sorted according to the depth for your viewpoint, frontside and backside of the sphere will be mixed up.

    Two possible solutions:
    As long as you only want to draw convex objects on top of your scene, enabling backface culling is sufficient (that's in most cases a good idea anyway).

    If you want to draw concave objects (or even intersecting triangles), you need some sort of depth sorting. Instead of disabling the depth test, just clear the depth buffer before you draw your in-front-objects.

    Edit: too late

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Dec 2005
    Location
    Italy
    Posts
    659

    Re: Always on top (in front) sphere

    Wonderful, clearing the depth buffer works like a charm.

    Thanks a lot to you all!

    Alberto

Similar Threads

  1. Replies: 5
    Last Post: 05-27-2015, 03:28 AM
  2. Render a trimmed sphere ? (a quarter of sphere)
    By HaVyThoai in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-07-2007, 12:05 PM
  3. Front to Back vs Back to Front Compositing
    By balogna in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-11-2005, 12:11 PM
  4. View front part of a sphere
    By GreenCat in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-10-2005, 12:08 AM
  5. what is faster? fill front and back or only front
    By Jan in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 02-21-2002, 06:11 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