Sign in to follow this  

billboarding/transparency in opengl+sdl

Recommended Posts

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

Share this post

Link to post
Share on other sites
thought I would add some details...
this is what i have so far...

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

setup tex params and such...


display textured quad....


but this code shows no transparencies...suggestions?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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....


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this