Assume proj contains projection matrix and mv contains modelview matrix...
Matrix4 proj, mv, temp, inv;
temp = proj * mv;
inv = inverse(temp); // compute inverse of matrix
VECTOR4 fr[8]=
{
// near
{-1, -1, -1, 1}, { 1, -1, -1, 1}, { 1, 1, -1, 1}, {-1, 1, -1, 1},
// far
{-1, -1, 1, 1}, { 1, -1, 1, 1}, { 1, 1, 1, 1}, {-1, 1, 1, 1}
};
// Transform all vertices:
// multiply vertex array (fr) by matrix. result is transformed vertex array (tfr)
VECTOR4 tfr[8];
transform_points(fr, 8, inv, tfr);
int i;
for (i=0; i<8; i++)
{
tfr[i].x /= tfr[i].w;
tfr[i].y /= tfr[i].w;
tfr[i].z /= tfr[i].w;
tfr[i].w = 1.0f;
}
glBegin(GL_LINES);
connect tfr points as follow:
0-1, 1-2, 2-3, 3-0,
4-5, 5-6, 6-7, 7-4,
0-4, 1-5, 2-6, 3-7
glEnd();