There is no such thing in OpenGL ES like gluLookAt, assuming this is about iPhone and OpenGL ES. How is that implemented?
Keep in mind that the camera position is (0,0,0) and your square is also on that z plane.
If you call glLoadIdentity(), glTranslatef(0.0f, 0.0f, 0.0f) won't do any changes.
Maybe you could consider moving most of the setup part in a setup method.
ie: GlEnable calls and camera setup.
Make sure the glMatrixMode is used in order to operate on the Projection or the Modelview matrix.
Setup could be:
- (void) setupView {
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// think about the box where all the vertices are.
glFrustum(-8.0f, 8.0f, -12.0f, 12.0f, -8.0f, 20.0f);
// .. all sort of glEnable
}
In drawView make sure that your vertices are in front of the camera, by applying some translation on them. Also have colors for you vertices.
- (void) drawView {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, 5.0f); // move in front
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
// maybe you want to attach colors to your vertices
const GLubyte squareColors[] = {
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// .. some other loadidentity and translate and vertex pointer setup and draw
}
The OpenGL ES reference might be also useful:
http://www.khronos.org/opengles/sdk/1.1/docs/man/