SDL_image png transparency

Post: #1
I've been trying to get transparency to work with SDL_image and pngs. I have a png image with the alpha channel, but when I display it nothing is affected.

Loading code
    //Init variables
    itsFileName = fileName;
    itsID = 0;
    itsStatus = false;
    SDL_Surface * TextureImage[1];
    int pixelFormat;
    if(fileName.substr(fileName.length() - 3) == "bmp") //if its a bmp
            pixelFormat = GL_BGR_EXT;
            pixelFormat = GL_RGBA;
     //Try and load bitmap
         if ( ( TextureImage[0] = IMG_Load( fileName.c_str() ) ) )
        itsStatus = true;

        //Generate texture
        glGenTextures( 1, &itsID );

        //Set our focus to new texture
        glBindTexture( GL_TEXTURE_2D, itsID );
        if(gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->w, TextureImage[0]->h, pixelFormat, GL_UNSIGNED_BYTE, TextureImage[0]->pixels))
                 itsStatus = false; //non-zero return = failure to load
        //Set filtering for this texture to Linear, I don't know if this is needed - oh well works with it :)
    if ( TextureImage[0] )
        SDL_FreeSurface( TextureImage[0] );

and the display code:
    glBindTexture(GL_TEXTURE_2D, poly->getTextureID() );
        glTexCoord2f( 0.0f, 1.0f ); glVertex2f(  0.0f,  poly->getYSize() );
        glTexCoord2f( 1.0f, 1.0f ); glVertex2f(  poly->getXSize(),  poly->getYSize() );
        glTexCoord2f( 1.0f, 0.0f ); glVertex2f(  poly->getXSize(),  0.0f );
        glTexCoord2f( 0.0f, 0.0f ); glVertex2f(  0.0f,  0.0f );        

I don't understand why it doesn't work, the image shows up but is not transparent at all. Thanks for the help!
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
I see a problem in your call to gluBuild2DMipmaps. The second parameter should be GL_RGBA. Passing 3 basically tells GL to discard any alpha channel you pass it in the texture image.

- Alex Diener
Quote this message in a reply
Post: #3
Oh, wow, I can't belive I over looked that. Thanks that fixed all my problems.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Sprite transparency in OpenGL? Guest! 26 39,299 Feb 17, 2012 09:24 AM
Last Post: Skorche
  Trouble using SDL_image with XCode 3.2.3 Snow Leopard code4fun 1 5,463 Sep 22, 2010 10:47 PM
Last Post: OneSadCookie
  OpenGL ES 2.0, 2D Alpha Transparency Artifacts Macmenace 3 10,330 Mar 28, 2010 11:18 PM
Last Post: AnotherJake
  SDL_image and bmp loading Duane 13 11,484 Dec 21, 2009 09:14 AM
Last Post: Skorche
  libpng transparency problem wyrmmage 3 6,920 Mar 1, 2007 05:53 PM
Last Post: OneSadCookie