Alpha testing & no blending for trees. How to?

I followed the recent post about this topic, but it didn’t
have enough detail for me to figure out how to actually get it off the ground. If someone has a small program they could e-mail me that spells out where all of the various gl* functions go and how you prepare the images for use with transparency it would be great. My e-mail address is kmyers@bardstowncable.net.

Thanks much

After the last tree thread i updated the wiki, perhaps that’ll help?
http://wiki.java.net/bin/view/Games/AlphaTestingWithOpenGL

Although it sounds like you’re having problems actually loading a suitable texture. Hunt back though the forum and you’ll find the texure loader classes which can do that for you, then you can just load a .png with a built-in alpha channel and use that.

Other than that, where are you having problems?

Orangy,

From the Red Book I can’t really get a solid idea of which gl* calls go in the init() method, and which ones go in the display() method. For that matter, I ALSO can’t get a solid idea of what ORDER the calls should be placed inside of those 2 methods…

I can see that there are method calls that pertain to
2D textures in general, and then others that pertain to
the use of transparent 2D textures. If someone is willing to list the order of all methods concerned, the order they should appear in, and where they appear that would be wonderful.

Feel free to assume I have a valid texture loaded.

Thanks again.

Theres very little difference between the init and display methods, the only thing to remember is that init only gets called once at startup (so may be a good place to load textures and other resources). Most GL state (blending, alpha testing etc.) is best left to be specified in the display since it generally causes less problems debugging.

Remember that GL is a state machine, so a lot of the time the particular order of operations is pretty flexible. Mainly as long as the state is setup before you draw your objects then you’ll be ok. Assuming you’ve already got textures set up and displaying on screen, you simply have to add:
glEnable(GL_ALPHA_TEST);
and set your compare function with:
glAlphaFunc(GL_GREATER, 0.5f); // Or whatever values you actually need.

If that doesn’t give the correct effect, then odds are you’re not generating the alpha correctly (either because the texture isn;t loaded right, or you’re getting lighting and materials interfering). Start from a simple textured triangle and work up.

I just got this working, and I’m quite happy about it :slight_smile:

Thanks Orangy