SDL & OpenGL Texture Transparency

Started by
11 comments, last by MatrixCubed 18 years, 4 months ago
The code I use looks pretty much exactly like the code I posted earlier, minus the SDL_SetColorKey() call.
I like the DARK layout!
Advertisement
Ok... I've been trying like crazy to get this working - nothing has worked!

I attempted using colorkeying - I used it before AND after copying the surface to the new surface before returning the GL texture.

I have also attempting using a TGA texture - this, instead of displaying with an alpha value, displays nothing at all! - it displays a pure white box...

can anyone, perhaps, take a look at the actual function I posted above and help me find where, in my code that I should place colorkeying functions or such of that sort?

Thanks for any more help..
"Everything begins with Nu and everything ends with Nu. This is the truth! This is my belief... at least for now." - Mysteries of Life Volume 184 Chapter 26
This is the code from my engine, which loads textures in a format supported by the SDL_image library.

	SDL_Surface* lpTexture = IMG_Load(szFilename); 	if (!lpTexture)	{		// some error		return;	}		m_iTextureWidth	= lpTexture->w;	m_iTextureHeight = lpTexture->h;	glGenTextures(1, &m_iglTexture);	rval = glGetError();	if (rval != GL_NO_ERROR)	{	    if (lpTexture)	    {		    SDL_FreeSurface(lpTexture);		    lpTexture = NULL;		}			// some error		return;	}		glBindTexture(GL_TEXTURE_2D, m_iglTexture);	rval = glGetError();	if (rval != GL_NO_ERROR)	{	    if (lpTexture)	    {		    SDL_FreeSurface(lpTexture);		    lpTexture = NULL;		}			// some error		return;	}				int byte = 0;	int w = lpTexture->w, h = lpTexture->h;	int iTotalBytes = w * h * 4;	unsigned char* lpNewTexture = new unsigned char[iTotalBytes];	if (!lpNewTexture)	{	    if (lpTexture)	    {		    SDL_FreeSurface(lpTexture);		    lpTexture = NULL;		}			// some error		return;	}		for (int y = 0; y < h; y++)	{		for (int x = 0; x < w; x++)		{			Uint8 r,g,b,a;			Uint32 color = GetPixel(lpTexture, x, y);			if(!bUseColorKey)			{				SDL_GetRGB(color, lpTexture->format, &r, &g, &b);				a = 0xff;			}			else			{				SDL_GetRGBA(color, lpTexture->format, &r, &g, &b, &a);								if ((r == iColorKeyRed) && (g == iColorKeyGreen) && (b == iColorKeyBlue))				{					a = 0x00;				}				else				{					a = 0xff;				}			}			lpNewTexture[byte++] = r;			lpNewTexture[byte++] = g;			lpNewTexture[byte++] = b;			lpNewTexture[byte++] = a;		}	}	


...and the GetPixel() function used...

Uint32 GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y){   Uint8  *bits;   Uint32 Bpp;   if (X<0) puts("x too small in GetPixel!");   if (X>=Surface->w) puts("x too big in GetPixel!");   Bpp = Surface->format->BytesPerPixel;   bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;   // Get the pixel   switch(Bpp) {      case 1:         return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);         break;      case 2:         return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);         break;      case 3: { // Format/endian independent         Uint8 r, g, b;         r = *((bits)+Surface->format->Rshift/8);         g = *((bits)+Surface->format->Gshift/8);         b = *((bits)+Surface->format->Bshift/8);         return SDL_MapRGB(Surface->format, r, g, b);         }         break;      case 4:         return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);         break;   }    return -1;}


Hopefully the code is straightforward.

Best regards,

This topic is closed to new replies.

Advertisement