Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Texture visibillty and transparency

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    10

    Texture visibillty and transparency

    Hey Guys,

    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?

    Thanks,
    Tom

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Texture visibillty and transparency

    Use alpha test.
    Code :
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.1);
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    10

    Re: Texture visibillty and transparency

    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.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Texture visibillty and transparency

    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 ?

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    10

    Re: Texture visibillty and transparency

    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

    Thanks!

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Texture visibillty and transparency

    If you texture really have a correct alpha channel, default blending will work out of the box, or even Alpha test as explained above.

    drawVideo()
    glEnable(GL_BLENDING);
    glColor(1,1,1,1)
    drawTexturedQuad();

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    10

    Re: Texture visibillty and transparency

    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!

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Texture visibillty and transparency

    Quote Originally Posted by gumman
    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?
    Regards,
    Mobeen

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: Texture visibillty and transparency

    Maybe you forgot to call glBlendFunc()?

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    Zbuffer, I would also opt for blending in this case not the alpha test, but how come blending is often faster than the test?

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    10

    Re: Texture visibillty and transparency

    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:

    glLoadIdentity();
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glColor4f(1,1,1,1);
    glEnable(GL_TEXTURE_2D);

    glBindTexture(GL_TEXTURE_2D, textures[0].texID);

    glBegin(GL_QUADS);
    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);
    glEnd();


    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    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);

    http://img510.imageshack.us/i/1111at.jpg/

    with: glColor4f(1, 1, 1, 0.5);

    http://img692.imageshack.us/i/11105.jpg/

    with: glColor4f(1, 0, 0, 1.0);

    http://img3.imageshack.us/i/1001cu.jpg/

    with: glColor4f(1, 0, 0, 0.5);

    http://img249.imageshack.us/i/10005c.jpg/


    Hope it's a bit clearer now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •