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 2 of 2

Thread: Blending Lines and Polygons

  1. #1
    Junior Member Newbie san3Designer's Avatar
    Join Date
    Jul 2010
    Posts
    2

    Blending Lines and Polygons

    I am developing a general 3D Simulator in JOGL which can render a wide range of Geographic data. The data can be in the form of points, lines and polygons.

    But I am facing annoying problems while blending. If the data contains lines as well as polygons the blending goes for a toss as the depth test does not allow lines behind the polygon to be displayed.

    Of course, ideally I should be sorting the primitives according to depth and render them from far to near. But since I am using both GL_TRIANGLE_STRIP and GL_LINE_STRIP primitives, in different functions calls this is not possible. Here is a snippet of my JOGL display() function:

    Code :
    if(polyLen > 0) {
        gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, polyStart, polyLen);
    }
    if(lnLen > 0) {
       gl.glMultiDrawArrays(GL.GL_LINE_STRIP, lineFirst, 0, lineCount, 0, lineFirst.length);
    }
    if(ptLen > 0) {
        gl.glDrawArrays(GL.GL_POINTS, ptStart, ptLen);
    }

    As you can see, each of the primitives are rendered using a separate function call. So any points or lines behind the polygons will be hidden by the depth test. All three primitives can be transparent/translucent. Worse, individual parts (some triangles in TRIANGLE_STRIP, some lines in LINE_STRIP) of each primitive may be transparent/translucent. So I am not sure if I can use the glDepthMask(false) trick.


    How can blending between the different primitives be handled?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Blending Lines and Polygons

    Perhaps you need to split the draw function up into lines and polys and also handle transparency separately.
    I suggest you render in this order:

    1. solid polys
    2. 'Solid' lines - disable z writes/depth test
    3. Blend transparent polys
    4. blend transparent lines

    This may not be the best way, but I don't see why this would not work. You do need some way to break up/tag the data into different batches.

Posting Permissions

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