Let's now look at implementing the frame buffer from the last video in our example project. It's quite complicated. So feel free to pause and rewatch, also try to code along with me if you'd like. As I mentioned, I first create class called FrameBufferDisplay, and then in the vertexShader, I basically set the GL_Position and I also set the VTextureCoordinates. Then fragment shaders, I basically set the fragment color to the texture color, and also check if the fragment color is very dark or has black color. If so, I discard that fragment, otherwise, I set the GL_FragColor to the fragment color. Then I create a function called initializeTexture to activate the texture, bind the texture, and also set the texture parameters. Then also call the GL_TEXTURE_2D function to set that 2D texture parameters. Then I define a CreateFrameBuffer function to generate the frame buffers, and then generate the texture, and initialize this texture, bind the frame buffer and then attach the texture to the frame buffer as is GL_COLOR_ATTACHMENT0. Then I generate a renderBuffer, bind a render buffer, set the render buffer to have a format of GL_DEPTH_COMPONENT24, and then attach this render buffer to the frame buffer as the GL_DEPTH_ATTACHMENT. Then I check the frame buffer if it is created successfully, then unbind the texture and unbind the frame buffer. To display the content of the frame buffer, we'll need to create a 2D plane. So I define the vertexes of a 2D plane in the 3D space. And also defined the indexes, and also the texture coordinates. Then in the constructor of the FrameBufferDisplay, I create the buffers for the vertex buffer, the index buffer, and a texture buffer. Then I create the GL program. I attach the shader program to the GL programs, then set the handle to points to the attribute and uniform variables in the shaders. In this example, I want the frame buffer to have half width of the full dispay and set the width to be half. Then also define a projection matrix as a perspective projection to draw the 3D object in this frame buffer. Then I create this frame buffer by calling the CreateFrameBuffer function. So then I define a draw function. Basically, draw the 2D plane in the 3D space. And then map the texture which is the color texture of the frame buffer onto this 2D plane. Then in the MyRenderer, I create a new variable viewportwidth and viewportheight, and also a new variable called msphericalmirror of type framebufferdisplay. Then in the onSurfaceChanged function, I set the viewportwidth and viewportheight to be of width and height of the screen. Then change the projection matrix to be an orthogonal projection matrix, and then create the msphericalmirror object to be a new FrameBufferDisplay object. Let's now we change the projection matrix to be an orthogonal projection matrix. When we draw this sphere on the screen, we're actually zooming in on this sphere. So create a background of our screen. So in the onDrawFrame function, I first set GL Viewport to be of size viewportwidth and viewportheight, and also add the function setLightLocations with minus -10 -10 before drawing the sphere. This is to remove the lighting effect, removing the 3D effect of the background sphere. Then I call the GL_FrameBuffer to use our newly created a frame buffer, set the viewport, clear this frame buffer and then create a new view projection, new view matrix with the eye location of 0, 0, -9. This is for looking at the back of the sphere. and then updated view projection matrix, and then set the light location of the sphere to be of 2, 2, 0. This is to create a 3D lighting effect on the sphere, and then draw the sphere in this frame buffer, and then we unbind the frame buffer. Then now we can draw our frame buffer on the plane. So basically set the GL Viewport, and then update the model matrix to be of size of the exact ratio of the spherical mirror object. Then we update the model view projection matrix and just call the draw function, to draw this 2D plane with the texture of the frame buffer. So when you run the program you can select the image as a texture of the sphere. Remember, I used the orthogonal projection matrix. So when we draw the sphere, the first sphere, it actually becomes a zoomed in view of a sphere, so it looks like the background. Then with a middle sphere which is actually is the sphere we draw on the frame buffer. So basically, we're overlaying the 2D plane with the texture of the frame buffer on top of the big sphere. We also use the lighting effect to create this 3D effect of this sphere, and also draw the back of the texture of the spherical image on this sphere to create this kind of effect.