Now, let's look into adding a texture in our example program. Feel free to code along with me. Let's modify our program to show how to use texture mapping. We first copy the world JPEG file into our drawable directory. We first create the function LoadTextureFromResources and define a local variable textureHandle and then call the glGenTextures function to generate the texture handle. Then we use the bitmapFactory.decodeResources to load the bitmap. Then use the glBindTexture to bind the texture handle and also call a textImage2D to load the bitmap image to the texture. Then we modify the MainActivity object to add the variable Contexts and the getContext function to get access to the activity context. In the vertexShader, we first add the attribute variable aTextureCoordinate and the varying variable vTextureCoordinate. We set the vTextureCoordinate to equal to aTextureCoordinate. In the fragment shader, we add the varying variable vTextureCoordinate and a uniform variable uUseTexture and uTextureSampler. Then in the main function, we first check if uUsetexture is true. If it's true, then we find the fragment color by using texture 2D function, and then set the fragment color to equal to the fragment color plus the ambient, specular, and diffuse light color. Then I create a floatBuffer, textureBuffer for storing the texture coordinate, and also defined a handle for pointing to the attribute, and uniform variables. Then create texture coordinate dataBuffer for storing the texture coordinates. Then in a createSphere function, I first define a buffer for storing the texture coordinates and then for each vertex, I set the texture coordinate to equal the column and row number. Then the TextureCoordinate values are then copied to the textureCoordinatedata variable. In the Sphere function, I first call the loadTextureFromResources to load the texture image world from the resources, and then create the texture buffer for storing the texture coordinates. Then I set the mTextureCoordHandle to point to the attribute variable aTextureCoordinate, and then enable this handle and also set the handle to point to the uniform variable uTextureSampler and uUseTexture. In the draw function, I call the glActiveTexture to set the active texture to texture zero, and then bind the texture using the TextureImageHandle, and set the TextureSampler to zero which means using a texture zero, and then pass the texture coordinates to the attribute variable, and also set a UseTextureHandle to one. Then for the other object like the other sphere, I also set the uUseTexture to zero to disable the texture mapping onto those objects. When you run the program, you will see that the world map is mapped onto the surface of the sphere. Let's try to map another image, the image of the sun, onto the other sphere. So first, we copy the image of the sun onto the drawable directory. Then I add a variable mTextureImageHandle2 to point to the texture image. Then in the sphere function, I then call the loadTextureResources function to load the image of the sun as a texture. In the draw function, I call the glActiveTexture and set the active texture to TEXTURE1, and then bind the texture with the TextureImageHandle2, and then set the TextureSampler to one, which means we're going to use TEXTURE1, and then pass the TextureCoordinates onto the attribute variable aTextureCoordinates. When you run the program, you'll see that the other sphere will be mapped with the image of the sun. Let's map a texture image onto the polygon connecting the two spheres, a gradient image for this polygon object. Then I add another texture buffer called ringTextureBuffer and another image handle called ImageHandle3, and the texture coordinate buffer for storing the new texture coordinates. Then in the createSphere function, I add the buffer for storing the new texture coordinate data. For each section of the polygon, I set the texture coordinate to equal to the column, and then it depends on which section, for the first section, I set the y-coordinate for the texture to be zero, and in the first section, to be 0.33, and then the second, to be 0.66, and then the last section it will be equal to one. Then I need to set the ringTextureIndex, so you go to the total number of texture coordinates. Then I copy all of the texture coordinates onto the ring texture coordinate data buffer. Then the sphere function, I call the load texture from resources function to load the texture image gradient, and then also create another texture buffer called ringtextureBuffer for storing the new texture coordinates. In the draw functions, I call the glActiveTexture function again, but this time, I set the active texture to TEXTURE2, and also set the sampler to point to TEXTURE2. So when you run the program, you'll see that the connecting polygon will be filled with the texture color, texture image.