OpenGL, SDL, and Transparent Bitmaps

Nibbie
Posts: 3
Joined: 2007.06
Post: #1
Hello everyone Smile. I'm new, here, nice forum! I am currently making a game in opengl + sdl, and I ran into a bit of a problem. My current functions can load bitmap images and convert/store them into textures, but I don't know how to change my functions to support transparency, using say magenta, (RGB: 255 0 255) as the transparent color. Is it possible to add this functionality to what I already have, or do I need to design it totally differently? (This code is modified from the Nehe tutorials.)

Okay, so under main.c I can load a texture by doing this:
Code:
GLuint test = loadGLTexture("test.bmp");

the function loadGLTexture calls LoadBMP to get the data, then converts the data into a texture.

I didn't know the policy about posting a lot of code in one post, so I just linked it here:
http://ryanazar.com/texture.html
It has syntax highlighting, too.

Thanks for looking! And thanks for all your help Wow !!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
No need to triple-post...

OpenGL doesn't support color-key transparency; it needs a full alpha channel. Loading a format (like PNG) which already supports the alpha will make your life easier.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2007.06
Post: #3
Sorry for the triple post, the topic wasn't showing up, so I thought something was up with my browser. Aarku cleared things up, for spam control all users first post have to be moderated. Sorry again.

I really want to just use plain bitmap files, because after this one function is written it will make things speedier for me as I wont have to deal with alpha channels in photoshop. I can just use mspaint and drag it to the networked image folder on my mac. This topic is about to turn into a sole SDL problem, so if it needs to be moved i'll understand.

After I have the bitmap loaded, I think I can convert the surface to RGBA and then set the alpha channel where I want it? I dunno if it is possible, but it makes sense to me. Wacko

Maybe
Code:
SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int bitsPerPixel, int pitch,
                                      Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
You can certainly turn color-key transparency into an alpha channel post load, it'll just be harder (and slower) than loading a format that already includes alpha. I wouldn't necessarily expect SDL to provide such a feature.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2007.06
Post: #5
I switched to TGA and got it going with the same functionality with the help of Joseph Duchesne. Thanks for your input OSC, I really appreciate it. Grin
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Drawing bitmaps in OpenGL MacGoober 21 22,602 Sep 22, 2007 05:50 PM
Last Post: MikeC
  Transparent textures kordeul 2 2,754 Aug 27, 2007 01:38 AM
Last Post: kordeul
  Loading textures from bitmaps tehqin 5 4,067 Feb 26, 2007 01:58 AM
Last Post: unknown
  Loading Bitmaps Jones 3 2,646 May 3, 2006 07:57 PM
Last Post: OneSadCookie
  Question about handling non power-of-two bitmaps Malarkey 9 4,329 Apr 23, 2005 09:11 AM
Last Post: Malarkey