Pro OpenGL ES for iOS

(singke) #1

CHAPTER 7: Well-Rendered Miscellany (^235)
We need to add a floor or platform underneath the cube that the shadow will render up
against, as shown in Listing 7-14.
Listing 7-14. The drawPlatform() routine that renders a floor beneath the cube
-(void)drawPlatform:(float)x y:(float)y z:(float)z
{
static const GLfloat platformVertices[] = //1
{
-1.0,-0.01,-1.0,
1.0,-0.01,-1.0,
-1.0,-0.01, 1.0,
1.0,-0.01, 1.0
};
static const GLubyte platformColors[] =
{
128, 128, 128, 255,
128, 0, 255, 255,
64, 64, 64, 0,
255, 64, 128, 255
};
GLfloat scale=1.5; //2
glEnable( GL_DEPTH_TEST );
glShadeModel( GL_SMOOTH );
glDisable(GL_CULL_FACE); //3
glVertexPointer(3, GL_FLOAT, 0, platformVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, platformColors);
glEnableClientState(GL_COLOR_ARRAY);
glPushMatrix();
glRotatef(m_WorldRotationX, 1.0, 0.0, 0.0); //4
glRotatef(m_WorldRotationY, 0.0, 1.0, 0.0);
glTranslatef(x,y,z);
glScalef(scale,scale,scale); //5
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glEnable(GL_CULL_FACE);
glPopMatrix();
}
This merely draws the square base object that the shadow is projected against.

Free download pdf