Jump to content
  • Advertisement
Sign in to follow this  
NordCoder

Adding padding and colorkey to image in SDL/OpenGL

This topic is 2436 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

I've been trying to implement a texture class for my engine in C++ and SDL/OpenGL.

One of the loading methods applies padding to a texture (when NPOT textures are
not supported and the image is not POT) and then applies a colorkey. Since OpenGL
does not support colorkeying, I simply loop through the pixels, check if they match
the colorkey, set their alpha value to fully transparent and then draw with blending.

To do this, I create a new POT SDL_Surface with SDL_CreateRGBSurfaceFrom(...) (let's call it
the destination) filled with the colorkey, then blit the source image onto the destination using
SDL_BlitSurface. The problem is that if the source image I'm loading contains an alpha channel,
its colors are blended with the destination and the resulting color will not match the colorkey.
With my test image, there is a visible border of blended colorkey colors around the sprite's edges.

I think I've tried every possible way to do this: Calling with different flags, using different
calls in different order, Googling and reading the docs. It still does not work. The only "solution" I can
think of is to manually go through the pixels in the source image and set them in the destination
disregarding the alpha channel. Both images are SDL_Surfaces which would then be converted to an
OpenGL texture.

Is there an easier way to do this?

Share this post


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