Advertisement Jump to content
Sign in to follow this  
Wooh

OpenGL OpenGL && SDL : Transparent image, make textures

This topic is 3683 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;

	if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
	{
		rmask = 0xff000000;
		gmask = 0x00ff0000;
		bmask = 0x0000ff00;
		amask = 0x000000ff;
	}
	else
	{
		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 ); 
	
	SDL_FreeSurface(surface);

	return paddedSurface;
}

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.

GameDev.net 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!