Alpha Channel Woes

GraySupreme
Unregistered
 
Post: #1
Hello all! I'm a bit new to OpenGL, but I started using it for a group project recently and managed to get almost everything running except for one problem The code I have to load Targas loads the red, green, and blue channels perfectly, but when it comes to the alpha channel, it either isn't loading properly or I'm not saving the photoshop CS file properly. The loading code is fairly straight forward:
Code:
    if(file==NULL ||            fread(TGAcompare,1,sizeof(TGAcompare),file)!=sizeof(TGAcompare) ||        memcmp(TGAheader,TGAcompare,sizeof(TGAheader))!=0||fread(header,1,sizeof(he​ader),file)!=sizeof(header))
    {
        if (file == NULL)        
            return false;        
        else
        {
            fclose(file);                                
            return false;        
        }
    }
    texture->width  = header[1] * 256 + header[0];
    texture->height = header[3] * 256 + header[2];    
    if(texture->width<=0 || texture->height <=0 || (header[4]!=24 && header[4]!=32))    
    {
        fclose(file);                                
        return false;                        
    }
    texture->bpp    = header[4];            
    bytesPerPixel    = texture->bpp/8;                    
    imageSize        = texture->width*texture->height*bytesPerPixel;
    texture->imageData=(GLubyte *)malloc(imageSize);        
    if(texture->imageData==NULL || fread(texture->imageData, 1, imageSize, file)!=imageSize)
        {
        if(texture->imageData!=NULL)
            free(texture->imageData;
        fclose(file);
        return false;
    }

    for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel)
    {                                
        temp=texture->imageData[i];                    
        texture->imageData[i] = texture->imageData[i + 2];
                texture->imageData[i + 2] = temp;
        }

    fclose (file);                        
    glGenTextures(1, &texture[0].texID);
    glBindTexture(GL_TEXTURE_2D, texture[0].texID);         
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);    
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    

    if (texture[0].bpp==24)            
        {
        type=GL_RGB;
        }
    glTexImage2D(GL_TEXTURE_2D, 0, type, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);

When I load the image, however, all the parts of the image which are supposed to be transparent turn white. I also have GL_BLEND enabled and glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) in the code. Can anyone help me figure out what's wrong?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
It's not inverted is it? Photoshop fills in fully transparent parts of the image to get better compression, is that perhaps responsible for the white?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
What's the 'type' variable set to if texture[0].bpp != 24?

- Alex Diener
Quote this message in a reply
GraySupreme
Unregistered
 
Post: #4
The image itself loads fine, but is there anyway to turn off photoshop's transparency filling tendencies? I set the first type in the glTexture2d function to 4 and commented out the 24 bit code because I know that my image is 32 bits and right now I'm mostly concerned about functionality, but still the problem persists. Recently I created a layer-masked image in photoshop and saved that as a 32 bpp targa with an alpha channel and that made all the parts which were supposed to be transparent black. The part of all this that confuses me is if and how I can access an individual channel of an image after I've loaded the data. If I someone could help explain that I might be able to make my own simple function to do the transition, or at least figure out what's wrong.
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #5
I believe it will flatten the layers for Targas. So if the top layer has transparency but the one below it doesn't, then you will end up with what you're describing.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Member
Posts: 157
Joined: 2002.12
Post: #6
I used to have that problem also with Photoshop Layer Masks and transparencies.

if you have a layer with transparencies, then just select the area you want to reveal then add a layer mask to the layer with Layer->add Layer Mask->Reveal selection.

Create a new channel and Copy the layer mask and paste it into the new channel (usually alpha 1) then remove the layer mask and export.

that should get ridof the white border.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Alpha Channel Problem Moganza 1 3,141 Jan 19, 2013 08:25 AM
Last Post: sealfin
  Alpha woes esunder 7 7,316 Feb 15, 2011 08:32 PM
Last Post: esunder
  Trouble writing PNGs with 16 bits per channel using libpng flash 2 3,845 Aug 28, 2006 11:01 AM
Last Post: flash
  Using 8-bit greyscale texture as an alpha channel? TomorrowPlusX 12 4,997 Apr 10, 2006 08:43 AM
Last Post: TomorrowPlusX
  png without alpha fine, png with alpha, nothing dave05 6 6,858 Jun 11, 2005 10:31 AM
Last Post: dave05