Jump to content
  • Advertisement
Sign in to follow this  

OpenGL OpenGL && SDL : Transparent image, make textures

This topic is 3588 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 and OpenGL and I try to convert a SDL_Surface to one of the 'power of 2' sizes. I do this because I want it to be an OpenGL texture. I have tried to make an function to add some extra space to the surface using SDL_CreateRGBSurface and SDL_BlitSurface (see below). It works fine as long as the png files not use transparency. Transparent images will not be visible at all. If the surface already have the right size it will work with transparent images so it must be some problem with the way I'm using SDL_CreateRGBSurface and SDL_BlitSurface but I can't find what it is.
SDL_Surface* powerOfTwoTex(SDL_Surface* surface)
	int w,h;
	SDL_Surface* paddedSurface;
	SDL_Rect offset; 
	offset.x = offset.y = 0; 

	Uint32 rmask, gmask, bmask, amask;

		rmask = 0xff000000;
		gmask = 0x00ff0000;
		bmask = 0x0000ff00;
		amask = 0x000000ff;
		rmask = 0x000000ff;
		gmask = 0x0000ff00;
		bmask = 0x00ff0000;
		amask = 0xff000000;

	w = nextPowerOfTwo(surface->w);
	h = nextPowerOfTwo(surface->h);
	if(surface->w == w && surface->h == h)
		return surface;

	paddedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask);

	SDL_BlitSurface( surface, NULL, paddedSurface, &offset ); 

	return paddedSurface;

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!