Jump to content
  • Advertisement
Sign in to follow this  
disanti

OpenGL OpenGL alpha channel and SDL_Surface.

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm using SDL_LoadBMP to load my bitmap textures into OpenGL... however since this is for a 2d game, I'm trying to get the color (255,0,255) to have an alpha of 0. My first step is to convert the color format to BGRA, but it isn't working very well and GL is only drawing the blue channel. Code:
SDL_Surface* image = SDL_LoadBMP(filename);

//Make a temperary data space to add alpha channels
SDL_PixelFormat format;
format.palette = NULL;
format.BitsPerPixel = 32;
format.BytesPerPixel = 4;
format.Bmask = 0xff000000;
format.Gmask = 0x00ff0000;
format.Rmask = 0x0000ff00;
format.Amask = 0x000000ff;
format.Bshift = 24;
format.Gshift = 16;
format.Rshift = 8;
format.Ashift = 0;
format.Bloss = 0;
format.Gloss = 0;
format.Rloss = 0;
format.Aloss = 0;
format.colorkey = 0xff00ff00;	format.alpha = 255;
SDL_Surface* imageBGRA = SDL_ConvertSurface(image, &format, SDL_SWSURFACE);

I know I must be doing something wrong. Will I have to make a loop to go through and test all of the colors too make them an alpha of 0? Sorry if this doesn't belong in the OpenGL forum, but I don't know where else to put it since it is more SDL based. Oh yeah, and this is the code I'm using to get the data into OpenGL:
glTexImage2D(GL_TEXTURE_2D,0,4,image->w,image->h,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,imageBGRA->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

Thank you very much~ John DiSanti

Share this post


Link to post
Share on other sites
Advertisement
What I did is to actually read the data pixel by pixel, flip it horizontally, swap the B and R channels then allocate a temporary buffer and add an alpha channel.

Here's an example with source.

http://rel.betterwebber.com/junk.php?id=48

The texture loader is in texture.cpp.

The default mask is (0,0,0) though. But you can change it with texture::setmask()

Hope it helps:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!