View Full Version : PNG Texture bleding
02-12-2008, 02:57 PM
I am trying to learn OpenGL and so far everything was OK until today :mad: . Let me explain you what I tried to do and where the problem comes.
The project is a simple one. I want to make a cube with textures. The top of the cube is red and the bottom is blue. On each side (front, left, back and right) I want to bind a texture. The texture is a PNG file that has a circle in the middle and alpha 1 on the sides and corners. I would like to apply this texture on the sides with the appropriate alpha (nothing to be seen where the alpha is 1) and in the same time to blend the visible part of the texture with the gradient formed from the bottom to the top (from blue to red) on each side. The short version is: I would like to blend the background gradient only with the visible part of the PNG texture.
Thank you very much.
02-13-2008, 12:54 AM
First, understand that in OpenGL (and the PNG file format), 0.0 is fully transparent, with 1.0 (255) fully opaque.
What you need is to set the texture environment blending mode (*not* the same as the blending mode, ie glBlendFunc() ). Use the glTexEnvi() function:
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param)
where param is GL_MODULATE, GL_DECAL, GL_BLEND, or GL_REPLACE (and GL_ADD_ARB if your hardware supports the GL_ARB_texture_env_add extension). You'll probably want GL_BLEND.
What this does is specify how the texture is blended with the object's color.
02-15-2008, 12:45 PM
Thanks for the solution. Now that I learned to do that I have a trickier question. In fact I donít even know if it is possible.
I have a card game. It is destined to ďimproveĒ the memory. It is a project used to learn opengl (I donít think will be finished). So: I have for each card a texture in png. The cards have rounded corners with alpha. I managed to load the card (textures) onto the polygons and to build reflections. I would like to insert a gradient color to the reflection. In fact more like a fading effect (to become transparent). The inconvenient is the light that changes the floor colors (thus the ambient color is not the same) and the fact that I donít want to see the reflection in the back (you can not see a reflection through another reflection). If I draw the reflections from the back to the front I cans see through my reflection the reflection in back (through the fadeout texture). If I draw the reflection from front to back, the corners that must be transparent get the background color and the transparency illusion is no more. The question is: is there any way to fadeout a texture (or give this illusion) using transparency (or any other method) and in the same time to be able to draw the objects from front to back without seeing the object in the background (through the fading part).
Thank you very much.
02-15-2008, 04:31 PM
For classic transparency, you have to draw from back to front.
Please post some screenshots to illustrate your problems and your aim, because, it is not so easy to understand from your description :-)
Set a white opaque glcolor for 2 corners, and white transparent glcolor for the other 2. It will be multiplied with the texture color values and should give you the "gradient fading" effect.
Oh, and if you did not read it yet :
02-15-2008, 06:04 PM
A related note: before you buy into the whole SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blending thing discussed in this link, read this (http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D) and this (http://www.gimp.org/docs/plug-in/appendix-alpha.html).
But as ZbuffeR said, it's mighty hard to tell what your problem is. Picture and code, please.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.