Matrix cam, ocam; // vanilla 4x4 matrix class
Vector texcoords[4]; // vanilla 4 vectors
ocam.getModelview(); // save the modelview matrix
cam=ocam; // copy it
cam.c41=0.0; // remove the translation part
cam.c42=0.0;
cam.c43=0.0;
cam.invert3d(); // invert it, assuming some niceties
glLoadIdentity(); // no modelview
float x=maxd/mind; // mind..maxd are depth range
float y=aspect*x; // aspect is aspect ratio (all from glFrustum)
// here we generate texture coordinates that point along the
// edges of the view frustum (ie including the rotation of
// the view frustum, but no translation)
texcoords[0]=cam*Vector(-1, aspect, -1); // upper left
texcoords[1]=cam*Vector(-1, -aspect,-1); // lower left
texcoords[2]=cam*Vector(1, -aspect, -1); // lower right
texcoords[3]=cam*Vector(1, aspect, -1); // upper right
glDepthFunc(GL_ALWAYS); // don't need to clear depth buffer
glDisable(GL_LIGHTING);
env.notify(); // this binds the cubemap texture
// and sets the texture environment GL_REPLACE
glBegin(GL_QUADS); // just draw a full screen
glTexCoord3fv(texcoords[0].xyz); // quad using the method of your
glVertex3f(-x, y, -maxd); // choice. I've used GL immediate
glTexCoord3fv(texcoords[1].xyz); // mode for clarity
glVertex3f(-x, -y, -maxd);
glTexCoord3fv(texcoords[2].xyz);
glVertex3f(x, -y, -maxd);
glTexCoord3fv(texcoords[3].xyz);
glVertex3f(x, y, -maxd);
glEnd();
env.endnotify(); // turn off the texture
glEnable(GL_LIGHTING);
glDepthFunc(GL_LESS); // normal depth buffering
ocam.load(); // restore modelview |