Toanso's picture

Problem on drawing a tree?

hi, everyone,
i have been doing some work on simulation on trees in the past few days,
but i met some problems now, may someone can help me. Thanks a lot.

i bind the texture of leaf and after alpha test,
the edge of these textures are black, just as it background color,
so it looks not very well,

the code are shown as blow.

glBindTexture(GL_TEXTURE_2D,texture_leaf);
glEnable(GL_TEXTURE_2D);
glNormal3f(0.0, 0.0, -1.0);
 
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0x0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-0.5f,0.0f,0.0f);	
glTexCoord2f(1.0f, 0.0f);glVertex3f(0.5f,0.0f,0.0f);	
glTexCoord2f(1.0f, 1.0f);glVertex3f(0.5f,1.0f,0.0f);
glTexCoord2f(0.0f, 1.0f);glVertex3f(-0.5f,1.0f,0.0f);
glEnd();
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);

texture and simulation results are show in the followed pictures

as the third picture shown, the black edge looks not well,
so how can i fix this problem or is there any better method to simulate tree?

Images
texture leaf used in program
simulation result
the simulation result show that the black edge looks not well.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
puklaus's picture

Use blending

                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

and your leaf image should be .png with alpha channel (and transparent background).

Toanso's picture
puklaus wrote:

Use blending

                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

and your leaf image should be .png with alpha channel (and transparent background).

Thanks for your reply, and i have a question to ask that is it necessary to use PNG format image file?
i am using bmp format image file now,
and after following your suggest, the program gets better results,

results
but it still have some black edge with sawtooth,

sawtooth edge

i am wondering why the egde's color is the same as its backgroud color?
and is it the reason that i donot use PNG file ?

or how to fix this problem?
what's more, the limps of the tree looks not very well,
so could someone give me some suggest how to make it better? and mike it looks more realistic?

Thanks you all.
good luck~

puklaus's picture

"i am wondering why the egde's color is the same as its backgroud color?"

There are almost black pixels on leaf's sides (you can see these when you open that texture in Paint and paint that black background with white), you want to get rid of these (ie with Paint.Net software, using Magic wand -tool).

If you dont smooth the edges (with alpha), then I suppose you dont need transparency (translucenty), and dont need to use .png fileformat. Smoothing the edges can be done ie blur when background is transparent.

Toanso's picture

someone said billoard is a good solution?
but how to use billoard for simulating a tree?

and the limps look not very well?
should i use fractal technolgy to generate limps of the tree?

is there anyone have some source code relate with billoard and fractal' using on simulating tree?

Thanks a lot

Radar's picture

Use a picture that has a fitting background. Blur the leaf a few times an past that behinde the actual leaf.

Do you want the trees in a game? Best thing would be: get a 3d-artist building and texturing it for you. There are many cheap tricks to give it volume. Also i would not use a single leaf as a trexture. On that space you could put a few branches, roots and the bark. Having branches in the texture also makes the thin branches look better because they are more organic.

Billboarded trees look strange because the leafes move around with the camera. Maybe that works in the distance but when you get close it just looks very strange.

Toanso's picture

hi,
could you explain it more in details?
i am new in 3D rendering.

Thanks a lot.