Game Development Reference
In-Depth Information
11. First, we set up the GLKView with an OpenGL context, as shown in the follow-
ing code. Because, if we don't do this, none of our OpenGL commands will do
anything.
GLKView* view = (GLKView*)self.view;
view.context = [[EAGLContext alloc]
initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:view.context];
12. Next, we create the buffers starting with the vertex buffer:
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
13. The vertex buffer is then filled with the vertex information:
glBufferData(GL_ARRAY_BUFFER,
sizeof(SquareVertices),
SquareVertices, GL_STATIC_DRAW);
14. The same thing is then done for the index buffer, which you'll recall stores in-
formation on which vertices the two triangles will use:
glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
_indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(SquareTriangles), SquareTriangles,
GL_STATIC_DRAW);
Once this is done, all of the information has been passed to OpenGL. GLKit
provide several effects, which are the objects that contain information such as col-
or, position, orientation, and so on. In this activity, we will make one square to be
red and to be present it in the middle of the screen.
15. The first step is to create the effect object, and then provide it with a projection
matrix. The projection matrix controls the overall sizes of things on the screen. In
this case, we create a projection matrix that uses the aspect ratio of the screen and
uses a 60 degrees field of view:
_squareEffect = [[GLKBaseEffect alloc] init];
float aspectRatio = self.view.bounds.size.width/
Search WWH ::




Custom Search