Transparent color
Started by DarkLight, Mar 25 2003 03:33 PM
13 replies to this topic
#1
Posted 25 March 2003 - 03:33 PM
Dear all,
I'm writting a computer game using Delphi/OpenGL. Almost all is done, now I should make more levels and fix some bugs. And here comes the question.
The stage is viewed from above and I have one object like a three. It uses texture with some green pixels and all other pixels should be transparent. This mean that if there is an object under the "three", all pixels that aren't green should be in the color of coresponding object pixel, otherwise thay should be in the background color. I was wondering if it is possible to write this type of blending - it will be quite usefull if in OpenGL is possible to define transparent color. Or maybe I should use glBitmap() to draw the green pixels after all another objects are drawn?
I'm writting a computer game using Delphi/OpenGL. Almost all is done, now I should make more levels and fix some bugs. And here comes the question.
The stage is viewed from above and I have one object like a three. It uses texture with some green pixels and all other pixels should be transparent. This mean that if there is an object under the "three", all pixels that aren't green should be in the color of coresponding object pixel, otherwise thay should be in the background color. I was wondering if it is possible to write this type of blending - it will be quite usefull if in OpenGL is possible to define transparent color. Or maybe I should use glBitmap() to draw the green pixels after all another objects are drawn?
<a href='http://www.kaldata.net' target='_blank'>kaldata.net - IT News</a>
#2
Posted 25 March 2003 - 03:48 PM
Hi!
You can create a tree, where each branch is a triangle or a quad plane and the
texture is of the type GL_RGBA.
Then, if you turn on GL_BLEND and provide the proper blending function
at glGlendFunc() the pixels with alpha > 0 will be more or less
transparent.
But this means, you have to provide an alpha channel in your texture image.
Most image manipulation programs can handle transparency. I suggest to
use The Gimp, its free and very powerful.
I hope this helps a bit
Greetings
Stefan
You can create a tree, where each branch is a triangle or a quad plane and the
texture is of the type GL_RGBA.
Then, if you turn on GL_BLEND and provide the proper blending function
at glGlendFunc() the pixels with alpha > 0 will be more or less
transparent.
But this means, you have to provide an alpha channel in your texture image.
Most image manipulation programs can handle transparency. I suggest to
use The Gimp, its free and very powerful.
I hope this helps a bit
Greetings
Stefan
#3
Posted 25 March 2003 - 04:07 PM
This is not exactly three, it is object which should particulary hide another objects. It is small and textures are created via RGB arrays. It is possible to use RGBA array and A-value 1 for all pixels that should be transparent? I think this should work (you say texture should be of the type GL_RGBA).
Thank you for the help
Thank you for the help
<a href='http://www.kaldata.net' target='_blank'>kaldata.net - IT News</a>
#4
Posted 25 March 2003 - 04:22 PM
Ever tried TGA??
They will have all that stuff embedded directly into the image.
It will greately ease your development time.
They will have all that stuff embedded directly into the image.
It will greately ease your development time.
#5
Posted 25 March 2003 - 04:41 PM
CyraX said:
Ever tried TGA??
They will have all that stuff embedded directly into the image.
It will greately ease your development time.
They will have all that stuff embedded directly into the image.
It will greately ease your development time.
Can you tell me how to use TGA in OpenGL and what exactly it will give me?
<a href='http://www.kaldata.net' target='_blank'>kaldata.net - IT News</a>
#6
Posted 25 March 2003 - 04:44 PM
Have a look at this page: http://nehe.gamedev.net/data/lessons/lesso...n.asp?lesson=08
It adresses directly the transparency and blending concept, and as I just read, 1 means opaque and 0 means transparent, not vice versa as I said earlier...
Cyrax: TGA is cool, yes. I use it quite often, too. Just for Info: Nearly any file format is described here: http://www.wotsit.org/
Greetings
Stefan
It adresses directly the transparency and blending concept, and as I just read, 1 means opaque and 0 means transparent, not vice versa as I said earlier...
Cyrax: TGA is cool, yes. I use it quite often, too. Just for Info: Nearly any file format is described here: http://www.wotsit.org/
Greetings
Stefan
#7
Posted 25 March 2003 - 05:07 PM
Problem is that I don't want to make texture transparent, only one color from it. I know the basic of alpha blending. Of cource, 0 for transparent and 1 for solid -exuse me. But this have no matter - I'm not seeking for exact code, only for solution.
<a href='http://www.kaldata.net' target='_blank'>kaldata.net - IT News</a>
#8
Posted 25 March 2003 - 06:06 PM
well, the trick is.. you actually need an alpha value to determine transparency (and 1 or 0 == transparent is up to your set up of the blending equation..)
you just want one color, so what you need to do is to set there alpha to transparent..
you can do that eighter before uploading the texture (and upload as GL_RGBA!! :D)
or, depending on hw, you can do it in the pixelshaders..
base idea:
those are the two ways possible..
you just want one color, so what you need to do is to set there alpha to transparent..
for every pixel if pixel.rgb == colorkey.rgb pixel.alpha = transparent else pixel.alpha = opaque
you can do that eighter before uploading the texture (and upload as GL_RGBA!! :D)
or, depending on hw, you can do it in the pixelshaders..
base idea:
distance = fragment.rgb - colorkey.rgb out.alpha = dot_product(distance,distance)and then using for example alpha test to check if alpha is greater than some threeshold, say 0.01.. that means, distance to colorkey is far enough => color != colorkey => passes the alpha test
those are the two ways possible..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
#9
Posted 25 March 2003 - 06:13 PM
what you can do with the TGA is simple. The TGA format allows for 4 bytes of data per pixel. RGBA, red, green, blue and alpha. The alpha 'channel' can be different for each pixel. All you do is set it to 0 for all the pixels you want to be transparent, and 1 for all the ones you want to be opaque. You can also have values in between, but that produces semi-transparent pixels. You might want to look at the TGA format, as it actually stores the pixels in BGRA format. You need to switch the R and B bytes.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
#10
Posted 26 March 2003 - 11:17 AM
Thank to all of you for the replyis. This is exactly what I've searched for. As I said I'm using RGB arrays for textures and there is no matter if I'll use RGBA or I'll convert TGA - this is the same. I'm just didn't know that I can specify Alpha for each pixel in texture and then blend only transparent pixels :)
Again, thank you
Again, thank you
<a href='http://www.kaldata.net' target='_blank'>kaldata.net - IT News</a>
#11
Posted 26 March 2003 - 11:25 AM
good luck. happy to helped out
btw, this is what is done in the bumpmapping demo from nehe, to show the logos. he adds the alpha values manually in code to make them transparent..
took me ages those days to find that out, hehe...:D but its so simple:D
anyways, good luck
btw, this is what is done in the bumpmapping demo from nehe, to show the logos. he adds the alpha values manually in code to make them transparent..
took me ages those days to find that out, hehe...:D but its so simple:D
anyways, good luck
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
#12
Posted 26 March 2003 - 06:22 PM
although it's possible, surely pixel shaders would be a VERY stupid way to do it. It won't provide much if any speed increase and it reduces your target audience wildly, because only top end Radeons support pixel shaders in hw.
not a flame, just an opinion :)
not a flame, just an opinion :)
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.
#13
Posted 27 March 2003 - 08:46 AM
Advantage with TGA-
Setting an ALPHa value in an editor (I suggest GimP) like Photoshop would be far more easier and would also be less headache.Then you also have the runtime Alpha value. If today you think htat you are on Earth and Everything that is green is transparent in the world, suppose you get a state where you have to render jungle - lo behold you are in deep trouble - you would only be showing off Space or Desert. Not exactly the kinda things you expect.
However TGA textures could be nasty big.
Setting an ALPHa value in an editor (I suggest GimP) like Photoshop would be far more easier and would also be less headache.Then you also have the runtime Alpha value. If today you think htat you are on Earth and Everything that is green is transparent in the world, suppose you get a state where you have to render jungle - lo behold you are in deep trouble - you would only be showing off Space or Desert. Not exactly the kinda things you expect.
However TGA textures could be nasty big.
#14
Posted 27 March 2003 - 08:56 AM
But the compression algorithm for TGAs (RLE encoded) is quite simple to implement, too. So you
can reduce the size on Harddrive a bit.
can reduce the size on Harddrive a bit.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












