206 CHAPTER 7: Well-Rendered Miscellany^
glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, (GLfloat)(sinf(transY)/2.0), z);
glRotatef(rotZ, 0, 0, 1.0); //4
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_Texture.name);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //5
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_DefaultFBO); //6
glLoadIdentity();
glTranslatef(0.0, (GLfloat)(sinf(transY)/2.0),z);
glBindTexture(GL_TEXTURE_2D, [m_FBOController getTextureName]); //7
glClearColor(1.0, 0.0, 0.0, 1.0); //8
glClear(GL_COLOR_BUFFER_BIT);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, fboVertices); //9
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
transY += 0.075;
rotZ+=1.0;
}
In line 1, the vertices for the FBO are specified, not much different
from those for the bouncing image.
In line 2, we fetch and save the default FBO, the one used for the main
display. And if you haven’t done it yet, this should be declared as a
GLint m_Default_FBO.
Line 3 is where we actually tell OpenGL to use our new FBO using a
bind method not unlike those used for basic texture mapping.
Following that is the standard setup code to manage the
transformations and so on.