PNG alpha channel not rendered in openGL(SDL_image used)+"manually" creating images in code

I am trying to read in a PNG image which has a transparent region .The picture is as shown in fig3 (picture below) with the transparent regionn being the blue surrounding area. So the pic appears as in fig 1.I have verified that the transparent region is stored correctly as in windows folder filmstrip view it appears as 1.I used irfanview to set the transparent region. then i use thecode below to read in the picture below which is modified code from Nehe tutorial 8 on Alpha Blending. I used SDL_image to load the png

This is the referenced picture with all figures numbered:-
Image Hosted by

1.The png is loaded using a load_image() function(given at end).The code below “// Create Linear Filtered Texture” should load the texture correctly

glTexImage2D(GL_TEXTURE_2D, 0, 4, TextureImage[0]->w, TextureImage[0]->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);

Its give in NEHE tutorial that GL_RGBA must be passed to above function & of course the no. of color components is 4(?).Yet the texture appears as in Fig 4. With blending enabled it appears as in figure 6.The pixels are not correct at all.

2.The code below “// CreateMipMapped Texture” loads the texture correctly but is without the alpha channel. The the cube appears as in fig 2 & with blending as in fig 5. Here as the alpha channel is ignored it does not make any difference how i save the pic(blue transparent region or not)

3.Then i tried to generate a texture “manually” using the code below “//Create image manually” & create a texture out of it(below “// Create Nearest Filtered Texture”). The intention is to create a blue square 32 by 32 in size.But i get a blank when i try to view the cube…absolutely dark screen ,nothing at all.!!

#define RMASK 0x000000FF
#define GMASK 0x0000FF00
#define BMASK 0x00FF0000
#define AMASK 0xFF000000

//Loads textures
int LoadGLTextures() // Load Bitmaps And Convert To Textures
int Status=FALSE; // Status Indicator

SDL_Surface* TextureImage[1];                    // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1);               // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=load_image("Data/glass.png"))
    Status=TRUE;                                    // Set The Status To TRUE

    glGenTextures(3, &texture[0]);                    // Create Three Textures
    //Create image manually
    unsigned int img[32*32];
    SDL_Surface* imgsurf;
    imgsurf=SDL_CreateRGBSurfaceFrom( img, 32, 32, 32, 4*32, RMASK, GMASK, BMASK, AMASK );
        MessageBox(NULL,"Surface null",     "Error",  MB_OK | MB_ICONERROR);

    // Create Nearest Filtered Texture
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, imgsurf->w, imgsurf->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgsurf->pixels);

    // Create Linear Filtered Texture
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexImage2D(GL_TEXTURE_2D, 0, 4, TextureImage[0]->w, TextureImage[0]->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);

    // Create MipMapped Texture
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->w, TextureImage[0]->h, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);

if (TextureImage[0])                                // If Texture Exists
    SDL_FreeSurface(TextureImage[0]);                // Free The Texture Image Memory

 glScalef(1.0f, -1.0f, 1.0f);

return Status;                                        // Return The Status


Here is the load_image function-superfluous really as i could have put up the little code above

//Loads a texture BMP image
SDL_Surface load_image( std::string filename )
//Temporary storage for the image that’s loaded
loadedImage = NULL;

//Load the image
loadedImage = IMG_Load( filename.c_str() );

return loadedImage;


So could someone please tell me how to correctly load the png alpha channel…& how to “manually” create a texture image as shown above.

Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.