CHAPTER 3: Building a 3D World (^57)
if (!self.context)
{
NSLog(@"Failed to create ES context");
}
GLKView view = (GLKView )self.view;
view.context = self.context; //3
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
}
#pragma mark - GLKView and GLKViewController delegate methods
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect //4
{
static int counter=0;
static const GLfloat squareVertices[] = { //5
-0.5, -0.33,
0.5, -0.33,
-0.5, 0.33,
0.5, 0.33,
};
static const GLubyte squareColors[] = { //6
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};
static float transY = 0.0;
glClearColor(0.5, 0.5, 0.5, 1.0); //7
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); //8
glLoadIdentity(); //9
glMatrixMode(GL_MODELVIEW); //10
glLoadIdentity(); //11
glTranslatef(0.0, (GLfloat)(sinf(transY)/2.0), 0.0); //12
transY += 0.075f;