Archived

This topic is now archived and is closed to further replies.

Making a certain color see though?

This topic is 5307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

colors are stored as color components on a PC... for example, the pixels you see with bitmaps and such have a RED, GREEN, and BLUE channel (the values of these channels blend to form all the colors available).

some graphics file formats (and textures in OGL) have an ALPHA channel also, which is another channel that determines how transparent that pixel is.

by adding an alpha channel to your graphics, you can have parts be clear, or slightly see-through.

hope that helps.

PS - if you only want to have some parts completely clear, and the rest regular, you can also use MASKING instead of the alpha stuff, see the tutorials on nehe.gamedev.net to see how to do this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Check out NeHe''s Blending tutorial:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08

Or look up "Alpha Blending" in google.

Share this post


Link to post
Share on other sites
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);

is this how blending is done and glColor4 the 4th is the alpha value and the blend function I am completely lost on.... But its not that i want to blend the whole thing just a specific color im lost :/ lol

coder requires 0xf00d before continue().

Killer Eagle Software

Share this post


Link to post
Share on other sites
just found this old topic and i d still know if it is possible to get rid of one specific color

maybe an extension or what ever

any idea?

Share this post


Link to post
Share on other sites
quote:
Original post by Basiror
just found this old topic and i d still know if it is possible to get rid of one specific color

maybe an extension or what ever

any idea?


Write a loader that inserts a fourth channel into the image and set the value of the fourth channel to zero when the RGB color a pixel is equal to the color you wish you set transparent. You''ll want to check the syntax you use to register your texture with OpenGL to ensure that it recognizes that the image contains an alpha channel, and you need to turn on certain settings when rendering while using the texture in order to utilize the transparency - I believe that is accomplished with alpha testing.

That "bright pinkish/purplish" color is known as Magenta. For your information, magenta is the highest possible combination of red and blue, Cyan is the highest possible combination of blue and green, and Yellow is the highest possible combination of red and green.


"Last time, I asked: ''What does mathematics mean to you?'' And some people answered: ''The manipulation of numbers, the manipulation of structures.'' And if I had asked what music means to you, would you have answered: ''The manipulation of notes?''" - S. Lang

Share this post


Link to post
Share on other sites
actually i was asking for a renderwise solution

if i d write such a loader it write a convertor and spare some time while loading maps ...

Share this post


Link to post
Share on other sites
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=38
This tutorial demonstrates what I want to do it seems as if the color black is seen as transparent im just not sure how its done... Ive looked though code just kinda still lost ?

Share this post


Link to post
Share on other sites
Here is one way to do it,

1 Load an image, This image can a bmp.

load it into an 4 bit array to include the alpha channel.

so you have
R,G,B,A, R,G,B,A, R,G,B,A, R,G,B,A, ...

GLubyte Data[4*SizeX*SizeY];

now scan the array for a specific color and make its Alpha 0 and the rest to Alpha 255.


for (int x=0; x < SizeX*SizeY; x+=4)
{
Data[x+3]=255;
if (Data[x]==0)
if (Data[x+1]==0)
if (Data[x+2]==0)
Data[x+3]=0
}

Make this into a texture. useing glTexImage2D

Then when you are ready to draw it do this,

glEnable(GL_ALPHA_TEST); // turns on the alpha test
glAlphaFunc(GL_GREATER,0.5f); // Only renders pixels with alpha above 0.5f - in our case its either 1/0 so this will work fine.
glBindTexture(GL_TEXTURE_2D,Texture); // Bind your texture
drawthing();// Draw your shape, object, char, thing whatever
glDisable(GL_ALPHA_TEST); // disable alpha test


[edited by - Xero-X2 on June 3, 2003 2:16:57 PM]

Share this post


Link to post
Share on other sites