PNG Texture bleding

Hello!
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.
George Mihaila

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.

Hello!
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.
George Mihaila

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 :slight_smile:

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 :
http://www.opengl.org/resources/faq/technical/transparency.htm

http://www.opengl.org/resources/faq/technical/transparency.htm

A related note: before you buy into the whole SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA blending thing discussed in this link, read this and this.

But as ZbuffeR said, it’s mighty hard to tell what your problem is. Picture and code, please.