Jump to content

  • Log In with Google      Sign In   
  • Create Account


Transparency Question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Kukakente   Members   -  Reputation: 105

Like
0Likes
Like

Posted 12 September 2012 - 08:28 PM

Hey Everyone i just wanted to ask how i would go about making a certain color transparent in opengl.
Example:
I want to be able to load a texture onto an object but when it appears on the screen it doesnt show a certain color that i gace chosen. srry if this is worded wierd. Like how would i go about setting a Color key for a certain color so opengl doesnt show it or loads it with the texture.
I would love for someone to help much thx.

Sponsor:

#2 larspensjo   Members   -  Reputation: 1526

Like
0Likes
Like

Posted 12 September 2012 - 10:42 PM

Transparent objects are drawn using a technique called "blending". It is the opposite to "opaque" objects. You first draw all your opaque objects, and then you draw your transparent objects.

When blending is used, the colors of the object you draw are mixed with the colors drawn in the opaque phase. Usually, you use a value called alpha, that controls to what extent the blending shall be done. Alpha 0 means completely transparent, and the opaque object will not be changed. Alpha 1 means completely opaque, and you will overwrite the previous pixels.

When you draw the transparent objects, they need to be sorted form far to near. The near objects will be drawn last, which is good as they matter most.

See more details for how it is done at http://www.opengl.org/wiki/Blending. If you are new to OpenGL, make sure you know about Legacy OpenGL.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#3 samoth   Crossbones+   -  Reputation: 4634

Like
0Likes
Like

Posted 13 September 2012 - 03:16 AM

If alpha blending is not an option and you really want color key transparency, your only option is to write a shader that either ignores a particular value read from the the texture (replacing it with the object's background color) or discards the fragment alltogether (if the color key should generate a "hole" in an object).

Note that other than for alpha blending, enabling GL_BLEND will generally not be very helpful for what you want. First of all, it's not immediately obvious how to get a non-cardinal color to be used as a key, and then, with lighting, your colors in the frame buffer are not what they are in the texture (pretty obvious). So, in one word, that just won't work.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS