OpenGL && SDL : Transparent image, make textures

Started by
1 comment, last by Wooh 15 years, 4 months ago
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;
}
Advertisement
Try removing the SDL_SRCALPHA flag from the source surface before using SDL_BlitSurface.

Example:
SDL_SetAlpha(surface, 0, 0);
0xa0000000
Thank you! That solved the problem.

This topic is closed to new replies.

Advertisement