Download iPhone Game Development
Transcript
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES,
backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES,
GL_RENDERBUFFER_OES, gles_depthRenderbuffer);
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) !=
GL_FRAMEBUFFER_COMPLETE_OES)
{
DebugLog(@"failed to make complete framebuffer object %x",
glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
You don’t have to understand all of the OpenGL functions being used here; it’s enough
that you know we are adding a depth buffer. If you were to try to render a 3D scene in
a GLESGameState instead of a GLESGameState3D, it would probably look pretty weird (assuming it didn’t crash)!
POWERVR
As you know, we are using OpenGL ES as our 3D graphics library. On the iPhone, the
specific hardware solution that OpenGL ES runs on top of is called POWERVR. The
company that makes this chip (Imagination Technologies, or ImgTec for short) has
released a supplemental API that you can use to get the most out of its hardware. This
API is free to use and available for download from http://www.imgtec.com/powervr/
insider/powervr-sdk.asp. You can find additional utilities for handling POWERVR at
http://www.imgtec.com/powervr/insider/powervr-utilities.asp.
For ease of use, we have included the PVRT SDK with our Chapter5Example.zip file.
We will use PVRT to represent our 3D vectors and matrixes, to load and draw our 3D
models, and to perform quaternion rotations (more on quaternions later).
Vectors and matrixes
Conceptually, there is no real difference between using the PVRTVec3 and PVRTMat4
structures versus the simple float[3] and float[16] arrays OpenGL uses. In fact,
wherever a float[3] is expected, we can use a PVRTVec3, and wherever a float[16] is
expected, a PVRTMat4.
However, the PVRT structs also have overloaded operators, so we can do something
such as this:
PVRTVec3 vecB = vecA * matrixA; //vector-matrix multiplication
//or this
PVRTVec3 vecC = vecA.cross(vecB); //cross-product
We will use the PVRT structs for convenience.
184 | Chapter 5: 3D Games