Skip to main content
GameDev.net gamedev.net
🔒 Locked

transparent pixel

Started by encom Sep 4, 2000 at 4:22 PM 4 replies 500+ views
Original Post
encom
encom
How to make a texture color pixel (like black) transparent to make sprites ? I use only bmp file. E-Mail : encom_79@worldonline.fr
Andrea
Andrea
You can store your bitmap as 24 bit RGB but you must convert them to 32 bit RGBA in memory. In fact you need an alpha byte to obtain transparency information.

For every pixel in the image set ALPHA byte to 0(transparent) if the RGB color is black otherwise set to 255.

Enable GL_ALPHA_TEST and set glAlphaFunc( GL_GREATER, 0.0f )

That's all.

Edited by - Andrea on September 4, 2000 6:45:42 PM
IpSeDiXiT
encom
encom
Ok, thanks, but how to convert a RGB files to a RGBA files, and how to set only black pixel alpha to 0
Syntax
Syntax
Just tack, on another 8 bits to the end of the pixel, check to see if the pixel is black, by checking it the values or some other method check...

(24 bitpixel in bits)

B G R
[00000000][00000000][00000000] = RGB (or BGR)

to convert it just take that, and add 8 bits

(32 bit pixel in bits)
B G R A
[00000000][00000000][00000000][00000000]

if the pixel is greater than zero (BGR > 0), you know it is not true black, then assign the Alpha byte to one (or whatever).
I hope this helps, I do not program OpenGL so whatever Andrea told ya I could not help ya with, but what I told ya should help you with Direct Draw...





-Lucas
-Dieraxx@programmer.net
-Lucas
encom
encom
Which GLcommand must i use to add 8 bits.
the algortihm is simple but for a dummie like me u must give
sample code.
Im a beginner in OpenGL, and my texture is stored in an AUX_RGBImage not AUX_RGBAImage !
send me a function to read bmp files and stock data.
ga
ga
    
struct pixel24
{
unsigned char R,G,B;
};

struct pixel32
{
unsigned char R,G,B,A;
};
[/source]

If you''ve stored the RGB - Pixels in struct pixel24 pixels[ ]:

[source]

pixel32 *p32 = new pixel32[ height*width];

for(i = 0;i < height*width;i++)
{
p32[ i].R = pixels[ i].R;
p32[ i].G = pixels[ i].G;
p32[ i].B = pixels[ i].B;
if ((pixels[ i].R == 0) && (pixels[ i].G == 0) && (pixels[ i].B == 0)) p32[ i].A = 0;
else p32[ i].A = 255;
}




GA
Visit our homepage: www.rarebyte.de.stGA

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.