Pro OpenGL ES for iOS

(singke) #1

84 CHAPTER 3: Building a 3D World^


You should now recognize many of the elements from the cube examples.
„ First, in line 1, tell the system that we want to work with the
GL_MODELVIEW matrix (the one that supports the transformation
information).
„ Lines 2 and 3 are identical to the ones used previously to cull out the
back of the sphere that we cannot see.
„ Lines 4 and 5 are again familiar and tell OpenGL to accept both vertex
and color information.
„ Next we supply the vertex data in line 6 and the color data in line 7.
„ Line 8 does the heavy lifting in drawing the arrays, both color and
vertices.
Now that the planet object is complete enough for this example, let’s do the driver. First,
create a new Objective-C object and call it something like
OpenGLSolarSystemController. Now add the code from Listing 3-8a and 3-8b to
initialize the object and universe.
Listing 3-8a. Initializing your universe: the header

#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
#import "Planet.h"

@interface OpenGLSolarSystemController : NSObject
{
Planet *m_Earth;
}

-(void)execute;
-(id)init;
-(void)initGeometry;

@end
Listing 3-8b. Initializing your universe: the rest of the stuff

-(id)init
{
[self initGeometry];

return self;
}

-(void)initGeometry
{
m_Earth=[[Planet alloc] init:10 slices:10 radius:1.0 squash:1.0];
}
The earth model here is initialized at fairly low resolution: 10 stacks high, 10 slices
around.
Free download pdf