Advertisement

billboarding/transparency in opengl+sdl

Started by November 13, 2004 04:40 PM
3 comments, last by RichardoX 19 years, 9 months ago
I cant seem to make textures transparent in SDL/opengl, what functions should i use to load in a bmp, and texture it to a quad such that black is transparent in SDL? THanks
thought I would add some details...
this is what i have so far...

loading texture...
<code>
image1 = LoadBMP(filename);
SDL_SetAlpha(image1,SDL_SRCALPHA,0);
image1 = SDL_DisplayFormatAlpha(image1);
SDL_SetColorKey(image1, SDL_SRCCOLORKEY,SDL_MapRGB(image1->format, 0, 0, 0));

setup tex params and such...

</code>

display textured quad....

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);
glBindTexture(GL_TEXTURE_2D,tex);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-1,-1,0);
glTexCoord2f(1,0);
glVertex3f(1,-1,0);
glTexCoord2f(1,1);
glVertex3f(1,1,0);
glTexCoord2f(0,1);
glVertex3f(-1,1,0);
glEnd();
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);



but this code shows no transparencies...suggestions?
Advertisement
i have reply this, in opengl forum. you should load your bitmap data with alpha values
+-+-+-+-+-STR
I know I have to load it in with alpha, my question is how to do that in a cross platform way using SDL.

I think there are SDL functions that could convert my bmp to rgba.
Save your image as png or other format that has RGBA format support. TGA works too, but TGA images require more disk space (a lot more).

Then load this image with SDL_Image-library or similar. Then create a new SDL_Pixelformat with RGBA masks, etc. are in the correct order. Then create a new image of the old image with the new pixelformat. Then just do glTexImage2D with the surf->pixels of the _new_ image and put GL_RGBA to the format.

If you want to stick to BMP's and colorkeys, then load the BMP, create a new pixelformat like above and blit the BMP image into the new surface and use that with glTexImage2D.

Using this method frees you from using reversed y-coordinates with glTexCoord, because the pixels are not in a reversed order like they are with BMP images.

I would post my source code, but I am not at home now and I do not have access to my files....

-Richardo

This topic is closed to new replies.

Advertisement