Pro OpenGL ES for iOS

(singke) #1

CHAPTER 7: Well-Rendered Miscellany (^205)
But we’re still not quite done, because we now have to rejigger drawInRect() to use
both FBOs.
To the end of the viewDidLoad() method, add the following lines:
m_FBOHeight=480;
m_FBOWidth=320;
m_FBOController=[[FBOController alloc]initWidth:m_FBOWidth height:m_FBOHeight];
Then modify the header as needed. The first line caches the original FBO so that it can
be restored properly as needed.
Now add the new drawInRect() method shown in Listing 7-3.
Listing 7-3. The new drawInRect(), renders to both FBOs



  • (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
    {
    static const GLfloat squareVertices[] =
    {
    -0.5, -0.5, 0.0,
    0.5, -0.5, 0.0,
    -0.5, 0.5, 0.0,
    0.5, 0.5, 0.0
    };


static const GLfloat fboVertices[] = //1
{
-0.5, -0.75, 0.0,
0.5, -0.75, 0.0,
-0.5, 0.75, 0.0,
0.5, 0.75, 0.0
};


static GLfloat textureCoords1[] =
{
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};


static float transY = 0.0;
static float rotZ = 0.0;
static float z = -1.5;


if(m_DefaultFBO==0)
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &m_DefaultFBO); //2


glDisableClientState(GL_COLOR_ARRAY|GL_DEPTH_BUFFER_BIT);


//Draw to the off-screen FBO first.


glBindFramebufferOES(GL_FRAMEBUFFER_OES, [m_FBOController getFBOName]); //3

Free download pdf