Advertisement Jump to content
Sign in to follow this  

OpenGL OpenGL alpha channel and SDL_Surface.

This topic is 4928 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:

Thank you very much~ John DiSanti

Share this post

Link to post
Share on other sites
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.

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!