CHAPTER 6: Will It Blend? (^169)
glLoadIdentity();
glTranslatef( (GLfloat)(sinf(transY)/2.0),0.0, -3.0); //6
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //7
transY += 0.075; //8
}
(void)setClipping
{
float aspectRatio;
const float zNear = .01;
const float zFar = 100;
const float fieldOfView =30.0;
GLfloat size;
CGRect frame = [[UIScreen mainScreen] bounds];
//h/w clamps the fov to the height; flipping it would make it relative to the width.
aspectRatio=(float)frame.size.height/(float)frame.size.width;
//Set the OpenGL projection matrix.
glMatrixMode(GL_PROJECTION);
size = zNear tanf((fieldOfView/57.3)/ 2.0);
glFrustumf(-size, size, -size aspectRatio,
size *aspectRatio, zNear, zFar);
glViewport(0, 0, frame.size.width, frame.size.height);
//Make the OpenGL modelview matrix the default.
glMatrixMode(GL_MODELVIEW);
}
And as before, let’s take a close look at the code:
You should now recognize the bouncy square’s coordinates. And in
this case, the z component is added to make a 3D bouncy square.
Of course, in line 2, the buffer is cleared. But make the background
black instead of the default gray.
In line 3 the square is moved back by 4 units.
Because there is no coloring per vertex, this call to glColor4f() in line
4 will set the entire square to blue. However, notice the last
component of 1.0. That is the alpha, and it will be addressed shortly.
Immediately following gColor4f() is the call to actually draw the
square.
singke
(singke)
#1