[MUSIC] When drawing objects with texture, sometimes we want the background of the texture to be removed, like this example texture image of a gorilla. Instead of drawing a grey background I just want to draw the gorilla so that I can show the 3D character S as the background. To do that, I first convert the gorilla image to a portable network graphic, or PNG file format. As the PNG file format allows the storage of the alpha component. Then I remove the grey background by setting the alpha component for the background pixel to be zero. Afterwards I modify the fragment shader to discard all fragments where the alpha components of the corresponding texture is < 0.1. Apart from discarding background pixels by checking the corresponding texture's alpha component we can create a transparency effect using the OpenGL blending functions. To use blending we can set the blending effect by calling the glBlendFunc for setting the factors for blending. And the glBlendEquation for setting the blending methods. And the glEnable to enable the blending effect. In addition the depth test would disrupt the banding. As you won't be able to see through the transparent object if you enable it. Hence, we need to disable the depth test. Let's implement this in our example program. I first gorilla PNG file image file with the background removed and then create a new FlatSurface Java object. I basically copy most of the source code from the object Sphere to draw a 3D object with texture. So I define the vertices to show a flatsurface on the screen and also define the index color and texture buffers. Then I load the image, gorilla, as a texture image for this flat surface object. Then in the MyRenderer object, I create a new object, msurface with type flat surface. And then take out the face culling functions. To show the effect I want to show the character S, the 3D character S and then the msurface object. I move the msurface object slightly to the back with 0.6 units. And then when you run the program you'll see that a flat surface with an image of a gorilla shown in front of the 3D character S. To remove the grey background of the gorilla image, I add one if statements in the frafmentShaderCode of the flat surface to discard all the background pixels with alpha Value less than 0.1. And when you run the program you'll see the background is removed. Apart from discarding background pixels by checking the corresponding texture's alpha components, we can create a transparency effect using the OpenGL blending functions. Let's have a look at this now. The blending effect is created by a fairly simple equation where the fragment color is equal to the sum of the source factor times the source color with the destination factor times the destination color. f_s is the source factor and f_d is the destination factor. We us the glBlendFunc to set the source and destination factors. In addition, the glBlendEquation function sets the operator of the equation. For example, if we have two circles, one blue and one red, the overlapping area can be set to be blended with red and blue. If we set the blending factors to be GL_ONE and GL_ONE_MINUS_SRC_ALPHA, the fragment will have the color 1, 0, 0.5, and 1. To set the blending effect, we can choose different factors. For example, GL_SRC_ALPHA means that the factor is equal to the alpha components of the source color. GL_CONSTANT_COLOR means the factor is equal to a constant color. And the constant color can be set by calling the glBlendColor function. Here is an example of a different destination factor. For example, if we set the GL_SRC_ALPHA as a destination factor, the gorilla is almost completely transparent. By default, the GL_FUNC_ADD is used as a blending equation. You can change it to other equations such as subtract, and we will subtract by calling the GL blend equation with the corresponding equation. Let's try adding the blending function in our program. So we first add the blend function to use the factor to GL_ONE and GL_CONSTANT_COLOR. And I set the constant color to be red. And then enable the blend function. When you run the program you'll see that the overlapping area between the gorilla and the character S is highlighted with red. Now let's change it to the blending equation to subtract and see what happens. So when you run the program you'll see that the overlapping area between the gorilla and the 3D character S now becomes green. Let's modify this arbitrary 3D object to make it transparent and add the 3D character A. You will see that the character A is blended within the arbitrary 3D object. Let's modify our program to show the effect. So I want to change the blend function to GL_ONE_MINUS_CONSTANT_ALPHA. And then show my arbitrary 3D object msphere and the 3D character A. And then I changed the blend equation back to add and disable the face culling and also disable the blending for the character A. When I run the program, you'll see this almost transparent 3D arbitrary object with the 3D character A in the middle. [MUSIC]