View Full Version : problem with mass-masking
HamsterofDeath
12-26-2002, 06:36 AM
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...
HamsterofDeath
12-26-2002, 07:23 AM
the problem occurs every time the trees cross each other...
HamsterofDeath
12-26-2002, 08:44 AM
correction : the problem occurs every time one tree is behind another, so their pixel-coordinates are crossing on the screen
Dodger
12-26-2002, 08:58 AM
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.
HamsterofDeath
12-26-2002, 09:31 AM
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...
Dakeyras
12-26-2002, 04:11 PM
@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 ).
HamsterofDeath
12-27-2002, 12:59 AM
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...
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.