Hey Everyone i just wanted to ask how i would go about making a certain color transparent in opengl.
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.
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.
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.