PNG mess up again & 'manual' picture creation

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 ImageShack.us

http://img487.imageshack.us/img487/3448/p6lq5.jpg

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];
    memset(img,0xFFFF0000,sizeof(img));
    SDL_Surface* imgsurf;
    imgsurf=SDL_CreateRGBSurfaceFrom( img, 32, 32, 32, 4*32, RMASK, GMASK, BMASK, AMASK );
    if(imgsurf==NULL)
        MessageBox(NULL,"Surface null",     "Error",  MB_OK | MB_ICONERROR);

    // Create Nearest Filtered Texture
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    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]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    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]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    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
                                
}

 glMatrixMode(GL_TEXTURE);
 glScalef(1.0f, -1.0f, 1.0f);
 glMatrixMode(GL_MODELVIEW);

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
SDL_Surface
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.

Abhijit---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2?/min or less.

Abhijit Nandy wrote:

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

You may want to check that the surface loaded by SDL_image has an alpha
channel, also check that it hasn’t generated a surface which is ARGB
rather than RGBA, or something like that.

Note to Sam - for SDL 1.3, can we please have a function that takes an
SDL_Surface * and uploads it as a GL texture, with all the grunt work
taken care of ? :slight_smile:

Pete.

Hello !

Note to Sam - for SDL 1.3, can we please have a function that takes an
SDL_Surface * and uploads it as a GL texture, with all the grunt work
taken care of ? :slight_smile:

For OpenGL and Direct3D.

Something like that would be really great.

CU

Note to Sam - for SDL 1.3, can we please have a function that takes an
SDL_Surface * and uploads it as a GL texture, with all the grunt work
taken care of ? :slight_smile:

Yes, oh please yes.

I think that would cut game development forum questions down by
a 1/3 or so…

MC

How would you choose options like mipmaping and such?

Or would his function just do a “generic” surface and if you wanted anything
special you’d have to roll your own?> ----- Original Message -----

From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of mal content
Sent: Thursday, July 27, 2006 2:43 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] PNG mess up again & ‘manual’ picture creation

Note to Sam - for SDL 1.3, can we please have a function that takes an
SDL_Surface * and uploads it as a GL texture, with all the grunt work
taken care of ? :slight_smile:

Yes, oh please yes.

I think that would cut game development forum questions down by
a 1/3 or so…

MC


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I don’t know really. I suppose the function could do a best guess
depending on the type of surface that you give to it, with a bitwise OR-d
set of flags to pick certain options.

MCOn 27/07/06, Alan Wolfe wrote:

How would you choose options like mipmaping and such?

Or would his function just do a “generic” surface and if you wanted anything
special you’d have to roll your own?