Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2010 15:46
Show Gist options
  • Save anonymous/604786 to your computer and use it in GitHub Desktop.
Save anonymous/604786 to your computer and use it in GitHub Desktop.
-(void)setupView:(GLView*)view
{
const GLfloat zNear = -0.01, zFar = 1000.0, fieldOfView = 45.0;
GLfloat size;
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
CGRect rect = view.bounds;
//glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size /
// (rect.size.width / rect.size.height), zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
[self gluPerspective:45.0 :rect.size.width/rect.size.height :-1.01 :1000.0];
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
}
- (void)gluPerspective:(double)fovy :(double)aspect :(double)zNear :(double)zFar
{
// Start in projection mode.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment