tags:

views:

53

answers:

2

how could I do the same as GluPerspective without Glu? Thanks

ex: gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);

+2  A: 

It's explained fairly clearly in the gluPerspective documentation. You just build up the appropriate 4x4 transformation matrix and use glMultMatrix to multiply it into the current transform:

void myGluPerspective(double fovy, double aspect, double zNear, double zFar)
{
    double f = 1.0 / tan(fovy * M_PI / 360);  // convert degrees to radians and divide by 2
    double xform[16] =
    {
        f / aspect, 0, 0, 0,
        0,          f, 0, 0,
        0,          0, (zFar + zNear)/(zFar - zNear), -1,
        0,          0, 2*zFar*zNear/(zFar - zNear), 0
    };
    glMultMatrixd(xform);
}

Note that OpenGL stores matrices in column-major order, so the order of array elements above is transposed from what's written in the gluPerspective documentation.

Adam Rosenfield
+3  A: 
void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
{
    GLdouble xmin, xmax, ymin, ymax;

    ymax = zNear * tan( fovy * M_PI / 360.0 );
    ymin = -ymax;
    xmin = ymin * aspect;
    xmax = ymax * aspect;

    glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
SurvivalMachine