Results 1 to 8 of 8

Thread: to draw a tree

  1. #1
    Guest

    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!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Caracas/Venezuela
    Posts
    182

    Re: to draw a tree

    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.

  3. #3
    Guest

    Re: to draw a tree

    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.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Redlands, CA, USA
    Posts
    233

    Re: to draw a tree

    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

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: to draw a tree

    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).]

  6. #6
    Senior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Caracas/Venezuela
    Posts
    182

    Re: to draw a tree

    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.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: to draw a tree

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

  8. #8
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    Re: to draw a tree

    Can I have the source code to draw a tree ?

    Thanks in advance.

    dylan.leyder@ibelgique.com

Similar Threads

  1. How to Draw tree using OpenGL
    By Alghafri in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-16-2014, 06:03 AM
  2. Bsp tree
    By exiled in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-23-2011, 02:54 AM
  3. Help ?? How can i draw a tree???
    By NeoRoland in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-14-2004, 08:06 AM
  4. draw recursive tree
    By caophong in forum OpenGL: Linux
    Replies: 3
    Last Post: 04-29-2001, 10:13 PM
  5. help with my bsp tree
    By Bruno in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 08-30-2000, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean