PDA

View Full Version : to draw a tree



01-10-2001, 06:19 PM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif

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!

coco
01-10-2001, 06:46 PM
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.

01-10-2001, 09:12 PM
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.

Serge K
01-10-2001, 09:59 PM
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.

glAlphaFunc (http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/opengl/glfunc01_5qhv.htm)

Bob
01-11-2001, 04:47 AM
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).]

coco
01-11-2001, 05:25 AM
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.

Bob
01-11-2001, 06:28 AM
Hmm, sorry for misunderstanding you post. Probably read that 'or' as 'and', or somthing like that. You are absolutely correct, my fault http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Leyder Dylan
01-11-2001, 10:27 AM
Can I have the source code to draw a tree ?

Thanks in advance.

dylan.leyder@ibelgique.com