Hello,
I am currently implementing GLSL shadows as described in this tutorial:
http://fabiensanglard.net/shadowmapping/index.php
It works quite well with the default Matrix transformations but as soon as I set up my camera like this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, aspectRatio, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(posCoord[0], posCoord[1], posCoord[2], eyeCoord[0], eyeCoord[1], eyeCoord[2], upVec[0], upVec[1], upVec[2]);
glScalef(1, -1, 1);
glTranslatef(0, -h, 0);
everything is fucked up. I do the scaling and translating so that 0,0 is the top left and not the bottom left as it is openGLs default. I am pretty new to matrix calculations and I tried everything I could possibly think of on the texture matrix to make it work with this transformation but I failed. Does anybody have an idea about how to fix that? It’s propably something simple I just don’t see.
I setup my Texture Matrix like this:
void setTextureMatrix()
{
static double modelView[16];
static double projection[16];
// This is matrix transform every coordinate x,y,z
// x = x* 0.5 + 0.5
// y = y* 0.5 + 0.5
// z = z* 0.5 + 0.5
// Moving from unit cube [-1,1] to [0,1]
const GLdouble bias[16] = {
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0};
// Grab modelview and transformation matrices
glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glMatrixMode(GL_TEXTURE);
glActiveTextureARB(GL_TEXTURE7);
glLoadIdentity();
glLoadMatrixd(bias);
// concatating all matrice into one.
glMultMatrixd (projection);
glMultMatrixd (modelView);
// Go back to normal matrix mode
glMatrixMode(GL_MODELVIEW);
}
Thank you!