masking problem
I am trying to mask leaves on a tree. Unfortunately when I follow lesson 20 I can still see the part that should be masked. I looked at the archives and tried different things like changing
glBlendFunc(GL_DST_COLOR,GL_ZERO); to
glBlendFunc(GL_SRC_COLOR,GL_ZERO);
and enabling glDepthTest for the mask and disabling it for the normal texture.
Without posting alot of code, is there some general common mistake I am making ? It almost seems like instead of the mask getting drawn in black, it gets draw in whatever color glColor4f was set to for the previous polygon (brown for the branches). I tried glDisable(GL_COLOR_MATERIAL) before drawing the leaves, but it doesnt seem to make a difference.
Can anyone help ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
no, I am disabling depth testing.
Also if I try and position the camera to look at only one polygon it still doesnt look right.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Also if I try and position the camera to look at only one polygon it still doesnt look right.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
I dont understand it. You can''t even get the masking work? Basically
-make sure you are loading alpha channels cortrectly
-make sure you turn on blending
-use glDepthFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
-First render all the solid world as you would, then sort the alpha-channelled polygons and render them back to front. DISABLING DEPTH TESTING WILL NOT WORK ALONE!!! You need some kind of depth sorting and back to front rendering.
I use BSP''s for achieving depth sorting. For beginners, you can use qsort() function and just test the distance of the center of polygon maybe.
-make sure you are loading alpha channels cortrectly
-make sure you turn on blending

-use glDepthFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
-First render all the solid world as you would, then sort the alpha-channelled polygons and render them back to front. DISABLING DEPTH TESTING WILL NOT WORK ALONE!!! You need some kind of depth sorting and back to front rendering.
I use BSP''s for achieving depth sorting. For beginners, you can use qsort() function and just test the distance of the center of polygon maybe.
glDepthFunc doesnt take 2 parameters. Did you mean glBlendFunc ?
How does Medal of Honor draw the leaves on its trees and bushes ? I find it hard to believe that I cant just specify for openGL not to draw a certain color on a texture.
Here is a wierd thing, if I disable depth testing, and look at the tree through my landscape (the landscape is drawn infront of the leaves but the leaves show through due to lack of depth testing), the leaves are masked correctly.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
How does Medal of Honor draw the leaves on its trees and bushes ? I find it hard to believe that I cant just specify for openGL not to draw a certain color on a texture.
Here is a wierd thing, if I disable depth testing, and look at the tree through my landscape (the landscape is drawn infront of the leaves but the leaves show through due to lack of depth testing), the leaves are masked correctly.
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
you want to mask leaves on a tree... can i assume that each leaf is a texture-mapped polygon, the texture containing an alpha channel, and parts to be masked have an alpha of 0 (or any value you have determined to be the masking value)? You don't actually want to blend the leaves together do you? (I don't see why you would)
This being the case, you should not be using blending (ie glBlendFunc)... try using glAlphaFunc(GL_NOTEQUAL, 0.0) ...that will simply not allow fragments/pixels with alpha of 0 to be drawn.
So, the way to put it all together:
- Leave depth testing enabled.
- Draw in whatever order you want.
- Before you go to draw the leaves, ensure that blending is disabled.
- Set the alpha test as I have suggested.
- Draw your leaves.
[edit] - Remember to set the alphfunc back to GL_ALWAYS after you have drawn the leaves (so other stuff drawn after this doesn't get screwed up)
This should produce masked leaves (ie allow stuff to show through where texture has alpha of 0).
Well... that's how I would do leaves on a tree... it's much faster than blending. Sorry if I this is not the approach you are trying to take... come to think of it, i suspect you are trying to use a separate bitmap/texture to mask with? (was that in one of Nehe's tuorials?)
[edited by - Bad Monkey on April 11, 2002 2:23:27 AM]
This being the case, you should not be using blending (ie glBlendFunc)... try using glAlphaFunc(GL_NOTEQUAL, 0.0) ...that will simply not allow fragments/pixels with alpha of 0 to be drawn.
So, the way to put it all together:
- Leave depth testing enabled.
- Draw in whatever order you want.
- Before you go to draw the leaves, ensure that blending is disabled.
- Set the alpha test as I have suggested.
- Draw your leaves.
[edit] - Remember to set the alphfunc back to GL_ALWAYS after you have drawn the leaves (so other stuff drawn after this doesn't get screwed up)
This should produce masked leaves (ie allow stuff to show through where texture has alpha of 0).
Well... that's how I would do leaves on a tree... it's much faster than blending. Sorry if I this is not the approach you are trying to take... come to think of it, i suspect you are trying to use a separate bitmap/texture to mask with? (was that in one of Nehe's tuorials?)
[edited by - Bad Monkey on April 11, 2002 2:23:27 AM]
So I have to create an alpha channel for my bmp file ? Do I have to load it in a special way ? I created an alpha channel for it and when I draw it I get a white square. Any ideas ?
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
Nitzan
-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------
bmp files don''t actually support an alpha channel, so you will either have to load your texture from another format like a targa (.tga), or you can dodgy up a colour keying approach. To do that, just decide what colour you wan to be transparent, then as you load the file, check the colour of each pixel... if it matches the "transparent colour", assign it an alpha value of 0, otherwise, assign it an alpha of 1.0 (ie 255 in a byte).
Your texture will have to be loaded into and RGBA structure (ie 4 bytes for each pixel).
This shouldn''t take too much modification. Hope that helps
Your texture will have to be loaded into and RGBA structure (ie 4 bytes for each pixel).
This shouldn''t take too much modification. Hope that helps

You want masking so why are you using blending? Thats whats got me confused here.
-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement