to draw a tree

hi everybody,

i want to draw a tree, so firstly, i draw a plane and map a texture (tree.bmp) on it. the texture is a tree texture.

but the problem is:
the texture is a tree with black background. so when i load the image, the tree appears, but the black background appears as well.

so it is obviously that the tree is not ‘original’, i mean, it comes with its background as well.

so i am looking for solutions on how to erase the background the tree texture.

i really appreciate anybody who are willingly to help me out!

generate an alpha channel to the tree.bmp so when the color is black the alpha value is 0 and else 255, then use blending with glBlendfunc(gl_src_alpha, gl_one_minus_src_alpha) or glAlphaFunc(GL_Greater,0.5)
there are other ways, but try this first.

hi coco,

i’m sorry if i am asking such a silly question. but i have followed your suggestion. (thanks for replying).

am i on the right track (guide me if i am wrong) if i put the command glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUE_SRC_ALPHA) in init function?

then i have run the program, but it remains the same. the background is still there. (arrgh, can you or anybody else help me again?)

then i was using glAlphaFunc(GL_Greater, 0.5), but the error msg appears: undefined identifier GL_Greater.

can someone help please…

thanks in advance.

If you want to use blending - you should enable it first.
glEnable( GL_BLEND );

> then i was using glAlphaFunc(GL_Greater, 0.5), but the error msg appears: undefined identifier GL_Greater.

Actually, it is GL_GREATER.


If you use the above mentioned method, you don’t have to enable blending at all. Pixels with alpha less than 0.5 (in this case, where there “are no tree” in the texture) is rejected, and blending is unecessary.

If you DO want to use blending, the result will be slightly better. But not very noticable to a user unaware of whats going on. You also have to sort the trees and draw them from back to front.

So my advice is to skip blending. I do so in my engine, and it looks great.

[This message has been edited by Bob (edited 01-11-2001).]

Well, I originally said two techniques, one with blending (which can generate soft edges) and one with alpha test (with can be faster).
For the one with blending, yes you need to do glEnable(GL_BLEND).
For the one with alpha, you should call glEnable(GL_ALPHA_TEST)

Sorry about the lower case macros in my first post.

Hmm, sorry for misunderstanding you post. Probably read that ‘or’ as ‘and’, or somthing like that. You are absolutely correct, my fault

Can I have the source code to draw a tree ?

Thanks in advance.