View Full Version : How to render a transparent textured object
12-03-2008, 04:10 PM
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
glColor4f(1.0f, 1.0f, 1.0f, material->transparency);
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:
12-04-2008, 05:28 AM
If you have lighting enabled, setting color with glColor.* won't help. You have to set alpha on material.
12-04-2008, 07:34 AM
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 ?
12-04-2008, 08:07 AM
Yes I think MichalST is right, look at the glTexEnv (http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml) function. First check if GL_TEXTURE_ENV_MODE is GL_MODULATE, the default one for the material texture.
12-05-2008, 10:37 AM
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
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?
Thank you :)
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.
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...)
12-05-2008, 11:49 AM
This should be ok :
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 :
And this :
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 :
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.