Removing #FF00FF in texture
hi there i was wondering if there is an easy way to tell opengl that color #FF00FF in a texture is suppose to be fully transparent..
If u understand i dont want to have to create masks for every texture, nor do i want to save them in tga format with transparency.
Dawid
No, OpenGL doesn't support colour-keying. If you want a texture to be transparent it needs to have an alpha channel.
You can either use a second texture as an alpha map with some kind of masking (OpenGL blending)
OR
Read in the texture data to a buffer, create a new buffer with enough room for an alpha channel. ie instead of 3 bytes per pixel youd have 4 bytes (something like that). then you check each pixel's colour and if its FF00FF (magenta?) then you set the alpha channel to 255 otherwise set it to 0.
OR
Read in the texture data to a buffer, create a new buffer with enough room for an alpha channel. ie instead of 3 bytes per pixel youd have 4 bytes (something like that). then you check each pixel's colour and if its FF00FF (magenta?) then you set the alpha channel to 255 otherwise set it to 0.
Creating an alpha channel texture is probably your best bet.
If you want to save some space while at it, try the 5-5-5-1 texture format.
Or you could just write a fragment shader, then you don't need an alpha channel. Alternatively texture combiners should be able to also do the trick, while being supported on slightly older hardware. (Not 100% sure about the last one though. Didn't bother to check.)
If you want to save some space while at it, try the 5-5-5-1 texture format.
Or you could just write a fragment shader, then you don't need an alpha channel. Alternatively texture combiners should be able to also do the trick, while being supported on slightly older hardware. (Not 100% sure about the last one though. Didn't bother to check.)
Quote:Original post by dawidjoubert
hi there i was wondering if there is an easy way to tell opengl that color #FF00FF in a texture is suppose to be fully transparent..
OpenGL does not support color key transparency, you'll have to use alpha to get the same effect.
Quote:
nor do i want to save them in tga format with transparency.
Hmm, that would be the easiest option. It would also allow you to have blended sprites.
However if you really don't want to store alpha data, you can still use color keys in your files and convert them to alpha on load. Something like:
for(i = 0; i < pixel_count; i++) { if(color_data == color_key) alpha = 0; else alpha = 1;}
tga isnt really a problem i can load them already the thing is i dont know how to do transparent blending in photoshop so thats why i ticked that off...
i did do masking by creating 2 bitmaps per sprite but could get the masking to work, i dont know why i did everything the way the tutorial in the nehe.pdf says..
Thirdly i tried to do tga transparency and couldnt get the damn thing to work...
I dont really care what the solution is i just need code that works for example here was my masking code
glEnable*GL_BLEND)
glBlendFunc("","") // replace "" with what it says in nehe tut
drawmask()
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
drawsprite()
Any solution would do, preferable the one with the least code, and i would like to stick to using .bmp format since i can save in 2/4/8/16/24 bit mode and keep the file sizes small!
i did do masking by creating 2 bitmaps per sprite but could get the masking to work, i dont know why i did everything the way the tutorial in the nehe.pdf says..
Thirdly i tried to do tga transparency and couldnt get the damn thing to work...
I dont really care what the solution is i just need code that works for example here was my masking code
glEnable*GL_BLEND)
glBlendFunc("","") // replace "" with what it says in nehe tut
drawmask()
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
drawsprite()
Any solution would do, preferable the one with the least code, and i would like to stick to using .bmp format since i can save in 2/4/8/16/24 bit mode and keep the file sizes small!
do not use masking, its both slower + consumes more resources than a texture with an alpha channel (look up in the paint programs help how to create a tga texture with an alpha channel)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement