OpenGL, SDL, and Transparent Bitmaps
Hello everyone
. 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:
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
!!
. 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
!!
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.
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.
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.
Maybe
?
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.
Maybe
Code:
SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int bitsPerPixel, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Drawing bitmaps in OpenGL | MacGoober | 21 | 19,012 |
Sep 22, 2007 05:50 PM Last Post: MikeC |
|
| Transparent textures | kordeul | 2 | 2,147 |
Aug 27, 2007 01:38 AM Last Post: kordeul |
|
| Loading textures from bitmaps | tehqin | 5 | 3,446 |
Feb 26, 2007 01:58 AM Last Post: unknown |
|
| Loading Bitmaps | Jones | 3 | 2,190 |
May 3, 2006 07:57 PM Last Post: OneSadCookie |
|
| Question about handling non power-of-two bitmaps | Malarkey | 9 | 3,655 |
Apr 23, 2005 09:11 AM Last Post: Malarkey |
|

