How to render a transparent textured object

Hi,
i have a 3D textured model and i want to render it with some level of transparency.

The model has 2 textures. Every texture is a sequence of rgb triplets. I use the following code but it does not works:

before binding the texture, i do

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f, 1.0f, 1.0f, material->transparency);
glDepthMask(GL_FALSE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);

where material->transparency is a float between 0.0 and 1.0.

The model is rendered not transparent, but it has some artifacts (like if it is rendered without the use of the depth buffer…). If i disable lighting, all the scene is very dark, but the model is rendered with transparency… :sorrow:

If you have lighting enabled, setting color with glColor.* won’t help. You have to set alpha on material.

Are you sure You use material->transparency value as your GL_SRC_ALPHA in blend equation ?

if its not a shader-based aproach, how do you apply your texture on model (how do you use glTexEnv) ? Maybe You need to setup glTexEnv correctly to mix your texutre’s rgb color with “glColor4f(1.0f, 1.0f, 1.0f, material->transparency)” color ?

Yes I think MichalST is right, look at the glTexEnv function. First check if GL_TEXTURE_ENV_MODE is GL_MODULATE, the default one for the material texture.

Ok, the problem is this.

First i have a 3D textured model completely opaque. Second, i want to render a special effect. The sfx is a simple object: two textured plane, one orthogonal to the other (they intersect each other at the middle). They are textured with the same texture. I render this sfx with no backface culling. I want it transparent. I have tried

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
glDepthMask(GL_FALSE);

and it does works. I see the effect rendered in the right way.
If i do not use glDepthMask(GL_FALSE), the effect is not rendered correctley (i do not know how to explain this…).

Suppose that i use glDepthMask(GL_FALSE).
I have some strange effects when i render the 3D model (i want the 3D model to be inside the 3D effect).

The scene is rendered in the following way:
1]draw the background (a static image) in the color buffer
2]render the 3D opaque model
3]render the sfx

All is correct if i do not execute the second step. If, otherwise, i render the 3D opaque model, it is a mess!!!
Instead of seeing the 3D model or some combination of the 3D effect and the 3D model, i see part of the background…
(the 3d opaque model is rendered with the depth test and z-write enabled…)

Suppose that glDepthMask(GL_FALSE) is not executed. The 3D model is rendered correctly inside the sfx, but the sfx, like i said, is not rendered in the right way at 100%.

What can i do?!? What am i doing wrong?
Help please!!
Thank you :slight_smile:

Ps.
The sfx wants to represent a simple flame. Actually, it is a bit more complex because i use four planes instead of two, but that does not change anything.
Pss.
I cannot use pixel shader and the hardware i am using is slow…so using textures to make effects (with blending enabled) is the only effective way (some particle effects can be done, but with not too much particles…)

This should be ok :
1)
2)
3) changed to :
a - glDepthMask(GL_FALSE)
b - render ‘sfx’
c - glDepthMask(GL_TRUE

Depending on the effect you want to achieve, you can also try this :
1)
3)
2)

And this :
1)
2)
3) changed to :
a - glDisable(GL_DEPTH_TEST);
b - render sfx
c - glEnable(GL_DEPTH_TEST);

Each have its pros and cons, so it depends on what you like best.

EDIT: and for best flame effect, try additive blending :
glBlendFunc(GL_SRC_ALPHA,GL_ONE);