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

Thread: problem with mass-masking

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    155

    problem with mass-masking

    my problem :
    i wanted to draw some 2d-trees, so i did this :

    glblend on
    draw mask of tree (only a black "shadow" of the tree visible)
    draw the tree on the mask

    -> everything looks good.

    no problem so far. but if i draw a second tree behind the first one, the invisible part of the nearest mask (in this case, the first tree) contained the background i've drawn before - the second tree was ...i dont' know what happened to him. everything inside the first trees rectangle was simply not drawn...
    go vegan

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    155

    Re: problem with mass-masking

    the problem occurs every time the trees cross each other...
    go vegan

  3. #3
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    155

    Re: problem with mass-masking

    correction : the problem occurs every time one tree is behind another, so their pixel-coordinates are crossing on the screen
    go vegan

  4. #4
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Lubbock, TX, USA
    Posts
    224

    Re: problem with mass-masking

    If you're using alpha blending, the depth of completely transparent fragments in your first tree will still be written into the depth buffer, so rendering a second tree behind the first one will fail depth test on those pixels on screen. There are three possible solutions for this problem:

    1. Disable depth writes when rendering the trees (render the trees last for this one)

    2. Use alpha test, so that fragments below a certain alpha value will be discarded

    3. Sort your trees back-to-front

    Also, you don't need to render a 'mask' first and then the tree texture on top of that. Using a texture with an alpha channel should be sufficient.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    155

    Re: problem with mass-masking

    thx, but :

    @3 : how can i reverse the order ? is there an opengl function or do i have to sort them manually ?
    @1 : how do disable depth write ?
    @2 : how to add an alpha-channel to a texture with paint shop pro ? i didn't find any button for this...
    go vegan

  6. #6
    Intern Newbie
    Join Date
    Jan 2002
    Posts
    32

    Re: problem with mass-masking

    @3 : how can i reverse the order ? is there an opengl function or do i have to sort them manually ?
    manually.

    @1 : how do disable depth write ?
    glDepthMask( GL_FALSE );
    Note that with the depth mask disabled your trees may be incorrectly drawn on top of each other, once again depending on draw order. However, your trees will be depth-tested correctly against the rest of the scene.

    @2 : how to add an alpha-channel to a texture with paint shop pro ? i didn't find any button for this...
    I don't use PSP so I don't know about this. Since you seem to already have a mask and an RGB texture, you can programatically combine them by using 4 bytes per pixel, and copying the first 3 bytes from the RGB texture and the 4th from the mask/alpha texture.

    That will give you RGBA. For texture loading performance, you might want to flip the colours and use BGRA ( GL_BGRA_EXT ).

  7. #7
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Posts
    155

    Re: problem with mass-masking

    depth writes off solved my problem...
    but i'm worried about the manual depth sort..
    that would need a lot of calculations, and i'm using java ^^
    maybe it's faster to draw a gl_polygon as an "outline" of the 2d-object so the invisible part is not depth-written


    the more opengl does, the lesser java slows down the graphics...
    go vegan

Posting Permissions

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