View Full Version : Texture visibillty and transparency
01-27-2011, 02:00 AM
I'm doing OpenGL for a few months now. I have a problem with texture bindung and I'm totally confused about alpha blending / testing right now.
My problem is the following:
I create a GL_QUAD Object and put a texture on it. The texture is a 32bit tga with alpha channel. I can change the color of the GL_QUAD Object with glColor3f to every Color I like and the alpha channel of the texture works fine. Behind the GL_QUAD there is a video running, so the GL_QUAD should be 100% invisible - only the texture shall be visible, and not the quad on which the texture is put on. How do I achieve this?
If I change glColor3f to (0.0, 0.0, 0.0, 0.0) the Alpha value is set to GL_QUAD and the Texture on it and so QUAD and Texture vanish.
Anyone can help me out?
01-27-2011, 02:05 AM
Use alpha test.
01-27-2011, 02:12 AM
But if i use Alpha Testing, my quad and my texture vanish.
How do i set Alpha Values for my QUAD and my Texture invidually?
Sorry for creating 3 Threads - There was a error with the database, and I thought the thread wasn't created. Can anyone delete them? Sorry.
01-27-2011, 02:14 AM
I deleted the 2 other threads.
the GL_QUAD should be 100% invisible - only the texture shall be visible, and not the quad on which the texture is put on
You can't have your cake and eat it.
The quad final RGBA values are determined (by default) by base color multiplied by texture. So to fully see the texture, use glColor 1,1,1,1 which is the default too.
Can you explain better what you want ? Some king of HUD overlay on top of a video ?
01-27-2011, 02:33 AM
Okay, I will try to explain it, but my english is not so good....
I have a video running in the background of my opengl application. it's a live video from a webcam. I didn't developed that part, so i can't give you further details.
I like to create a countdown above that video, so there is a 3 shown, then a 2, then a 1 .. and so on. I created some nice tga's with photoshop that contain those numbers as an image file.
Now I want to display that images above the video. I try to do that with a GL_QUAD and put the image file as a texture on it.
My problem is that, the quad itself should be completely invisible, and only the texture - the numbers - are visible.
The transparency of my textures works perfect so far.
Hope it is clearer now :)
01-27-2011, 02:46 AM
If you texture really have a correct alpha channel, default blending will work out of the box, or even Alpha test as explained above.
01-27-2011, 02:50 AM
mh, okay. Then the bug must be in my .tga files. If I use your commands. It blends just a black quad (+texture) with my background.
Thanks for your help! :)
01-27-2011, 02:58 AM
But if i use Alpha Testing, my quad and my texture vanish.
For this to work the order of rendering is also important. You should render the background texture (your video first) and then render the transparent texture on top of it. R u doing it and this order?
01-27-2011, 03:33 AM
Maybe you forgot to call glBlendFunc()?
Zbuffer, I would also opt for blending in this case not the alpha test, but how come blending is often faster than the test?
01-27-2011, 04:03 AM
So, i'm back again, i'm still not getting it to work.
my .tga files seems to be correct, because they do perfect transparency in the quad itself.
@mobeen: yes, the video in the background is drawn before my objects are drawn.
And yes, i call the glBlendFunc...
Here is my code:
glTexCoord2f(0.0f, 0.0f); glVertex3f(-64.0f, -64.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 64.0f, -64.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 64.0f, 64.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-64.0f, 64.0f, 0.0f);
And here are some Screenshots (because there is no live video at the moment, there is a gray frame in the background)
with: glColor4f(1, 1, 1, 1);
with: glColor4f(1, 1, 1, 0.5);
with: glColor4f(1, 0, 0, 1.0);
with: glColor4f(1, 0, 0, 0.5);
Hope it's a bit clearer now :)
01-27-2011, 04:18 AM
Also, be sure to glDisable(GL_LIGHTING); before anything else.
1111 looks perfect, what is wrong with it ?
Can you post your exact TGA image, so we can inspect the alpha channel ?
01-27-2011, 04:37 AM
1111 is wrong, because the inner quad you see in it shouldn't be there. I want a complete gray (the same gray everwhere) and in the middle my number :).
like that: just a fast edit with paint to clarify what i want ;)
Yes of course, i uploaded my .tga to http://tinyurl.com/488z7jg but I guess my .tga is allright.
01-27-2011, 04:56 AM
Ah ok now I understand the first images. And there is a strange gradient accross the texture, not sure where this comes from.
Indeed the 1.tga is good.
So what is left ? Maybe GL defaults have been modified elsewhere so :
- set the glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- be sure to use only 1 texture, disable any multitexturing.
If this does not fix it, try to post the shortest compilable version of your code. What do you use as TGA loader ? can you verify you read alpha values correctly ?
01-27-2011, 05:14 AM
the gradient you see, was from my lightning, i disabled it after i made the screenshots. The Color is now really saturated and exactly the value I set with glColor. I don't use multitexturing. When i use that glBlendFunc, it has the same effect as before. Both - quad and texture - get transparent.
I figured out, when i use glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); it's getting near to what i want. But i miss contrast and color... strange.
i use the tga loader included in nehe #lesson 24 for glut:
I'm going to play now with other options of glBlendFunc, and when i'm total dissappointed, i'm going to post a compileable code...
01-27-2011, 06:58 AM
.... so finally, it works.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
did the magic.
Now it works, thanks for your help guys ;)
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.