render a simple tree
i want to render a simple tree using only 2 crossing textures
i tried to do it with masking like it is made in nehes tutorials but i had problems with the depth-test and blending.
whats the best way to do that?
Make use of alpha testing.
Load your tree texture, a texel thats part of the tree should have alpha 1. Then:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);
DrawTree();
Thats one way to do it anyway.
Load your tree texture, a texel thats part of the tree should have alpha 1. Then:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);
DrawTree();
Thats one way to do it anyway.
Using alpha testing with wrongly sorted objects can and will lead to strange looking edges where the alpha value changes.
A good solution is to use 4 billboards instead of 2, and sort them from back to front. You can use the angle of the tree to quickly do this.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
A good solution is to use 4 billboards instead of 2, and sort them from back to front. You can use the angle of the tree to quickly do this.
Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Sorting and alpha testing? The real great thing about alpha testing is that you don''t have to sort (and it doesn''t mess up your Z buffer). If you have problems with the edges, try:
glAlphaFunc(GL_GREATER, 0.99f);
or
glAlphaFunc(GL_EQUAL, 1.0f);
That should take care of those nasty edges
- An eye for an eye will make the world go blind -
glAlphaFunc(GL_GREATER, 0.99f);
or
glAlphaFunc(GL_EQUAL, 1.0f);
That should take care of those nasty edges

- An eye for an eye will make the world go blind -
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
I agree with smarechal. you don''t need to depthsort objects for alpha testing. that''s the beauty of it. but i agree that trees look much nicer if created with blending(sun can shine trough leaves and stuff like that) but he can''t use this aproach if he wants to use just 2 quads.
You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
so, to make shure if i understood it right
first i draw the mask the i enable alpha_test and call alpha func and then i draw the tree.
first i draw the mask the i enable alpha_test and call alpha func and then i draw the tree.
well.. bether:
set the alpha-component of your texture to 1 if its visible and 0 if its not (for every pixel)
load this up in GL_RGBA format (GL_RGBA8 i think..
)
then simply draw the tree, and use glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,.75f); for example
"take a look around" - limp bizkit
www.google.com
set the alpha-component of your texture to 1 if its visible and 0 if its not (for every pixel)
load this up in GL_RGBA format (GL_RGBA8 i think..

then simply draw the tree, and use glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,.75f); for example
"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
Adema:
loose the masking all together. Alpha test will take care of everything. Just 1 pass with alpha test enabled. Man, I love alpha testing :-)
in pseudocode:
glAlphaFunc(GL_EQUAL, 1.0f);
glEnable(GL_TEST_ALPHA);
texture->bind(); //32 bit texture!!!!
tree->Render(); //just draw the 2 quads
glDisbalbe(GL_TEST_ALPHA);
Okay, loose the pseudo in pseudocode
- An eye for an eye will make the world go blind -
loose the masking all together. Alpha test will take care of everything. Just 1 pass with alpha test enabled. Man, I love alpha testing :-)
in pseudocode:
glAlphaFunc(GL_EQUAL, 1.0f);
glEnable(GL_TEST_ALPHA);
texture->bind(); //32 bit texture!!!!
tree->Render(); //just draw the 2 quads
glDisbalbe(GL_TEST_ALPHA);
Okay, loose the pseudo in pseudocode

- An eye for an eye will make the world go blind -
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
Well, actually...
Alpha testing does eliminate the need for sorting, but ONLY for alpha values of 0 and 1.
Textures which include ''soft'' alpha values do need to be sorted - because if you''re not z-buffering you obviously need to draw back-to-front, and if you ARE z-buffering you still need to draw back-to-front otherwise a tinted window will obscure anything behind it. BUT...you only need to sort stuff with alpha textures. The z-buffer will take care of the solids, then you sort the alphas and draw them on top.
alpha testing is ALWAYS a sharp edge.. alpha test does NOT combine with the previous framebufferimage so it NEVER NEEDS SORTING
its just plain fact, not more to talk about
what you think about is the blending, where alpha of .5 means combination of both framebuffer and current image, wich needs sorting
alpha TEST does always only draw or not draw, nothing more
its just plain fact, not more to talk about
what you think about is the blending, where alpha of .5 means combination of both framebuffer and current image, wich needs sorting
alpha TEST does always only draw or not draw, nothing more
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement