Saturday, December 27, 2008

gluPerspective to glFrustrumf

gluPerspective is a nice, intuitive helper function for setting the projection matrix in OpenGL. However, it's part of the glu library, which doesn't seem to be (readily) available for the iPhone (OpenGL ES).

Here is how to call glFrustrumf with the values you would give to gluPerspective:

float fov = 45;
float near = 0.01, far = 10;
float aspect = (float)windowWidth / (float)windowHeight;

// glPerspective(fov, aspect, near, far);

top = tan(toRad(fov)) * near;
bottom = -top;
left = aspect * bottom;
right = aspect * top;

glFrustumf(left, right, bottom, top, near, far);

No comments: