OpenGL Transparency Questions

This is a discussion on OpenGL Transparency Questions within the Game Programming forums, part of the General Programming Boards category; Question 1 I'm using TGA images in OpenGL because they have an alpha channel, which makes it relatively easy for ...

  1. #1
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970

    OpenGL Transparency Questions

    Question 1
    I'm using TGA images in OpenGL because they have an alpha channel, which makes it relatively easy for me to create texture-mapped sprites with transparent pixels.

    Do any of you guys have an OpenGL TGA loader you're willing to share? I'm currently using NeHe's TGA loader in lesson 33. It works fine, but I'm wondering it anybody here thinks he has a more efficient/shorter version.

    Question 2
    Is there a way to achieve transparency effects with plain Windows bitmaps? I'd like to use them to texture-map a quad, with specific pixels left out. But bitmaps do not have an alpha channel so I can't use glEnable(GL_ALPHA_TEST) like I could when dealing with TGA.

    I suppose I would have to use blending of some sorts with glEnable(GL_BLEND) but I'm not certain of the details. If anybody has accomplished this before, I would like to hear how they did it.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Use 32-bit bitmaps for the alpha channel.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Thanks for replying MrWizard, but I'm afraid I'm limited to working with bitmaps that are 24-bits and below.
    Last edited by Dante Shamest; 03-25-2005 at 01:34 PM.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you're only interested in either 0% or 100% transparency you could assign a certain color to be transparent. I don't know how this is done in OpenGL though, I know it's possible in DX.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    For bitmaps, use multi-texturing. Each texture unit respectivly would be your base(colored) texture and your alpha-map. From there, use OGL blending functions.

    Code:
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,  g_Texture[textureID]);
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,  g_Texture[textureID]);
    
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 1.0);glVertex3f(0.5, 0.5, 0.0);
    glTexCoord2f(0.0, 0.0f);glVertex3f(-0.5, 0.5, 0.0);
    glTexCoord2f(1.0, 0.0f);glVertex3f(-0.5,- 0.5, 0.0);
    glTexCoord2f(1.0, 1.0);glVertex3f(0.5, -0.5, 0.0);
    glEnd();
    I'm 80% sure this would, work, but i'm no guru nor do I have self-confidence, lol

    -psychopath
    Last edited by psychopath; 03-25-2005 at 08:20 PM.
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    Why not download the TGA spec from wotsit and write your own loader? its pretty easy, especially if you dont bother with compressed TGA's, plus its good experience.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  7. #7
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Quote Originally Posted by psychopath
    For bitmaps, use multi-texturing. Each texture unit respectivly would be your base(colored) texture and your alpha-map. From there, use OGL blending functions.
    Thanks, that information seems helpful.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    with help from bubba i have recently implemented sprites with transparent pixels with the tga image format rendered in opengl. i looked at nehe's code to figure out the format and wrote my own loader, however it is actually slower. i would not worry about the execution speed of loaders. i can help out in any other way possible however. bitmaps are stupid.
    See you in 13

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGl questions
    By Shadowwoelf in forum Windows Programming
    Replies: 4
    Last Post: 06-20-2007, 05:35 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. Some OpenGL Questions:
    By Krak in forum Game Programming
    Replies: 7
    Last Post: 04-29-2003, 12:07 AM
  4. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM
  5. MISC questions about OpenGL
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 01-25-2003, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21