Hello,
I’m trying to implement projective texture mapping, but can’t get it quite working ok.
Here’s what i’m doing atm:
static GLfloat perspectiveMatrix[16];
static GLfloat modelViewMatrix[16];
void EnableProjectiveTexturemapping(void)
{
GLfloat objPlaneS[] = { 1.0f, 0.0f, 0.0f, 0.0f };
GLfloat objPlaneT[] = { 0.0f, 1.0f, 0.0f, 0.0f };
GLfloat objPlaneR[] = { 0.0f, 0.0f, 1.0f, 0.0f };
GLfloat objPlaneQ[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_OBJECT_PLANE, objPlaneS);
glTexGenfv(GL_T, GL_OBJECT_PLANE, objPlaneT);
glTexGenfv(GL_R, GL_OBJECT_PLANE, objPlaneR);
glTexGenfv(GL_Q, GL_OBJECT_PLANE, objPlaneQ);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);
glMultMatrixf(perspectiveMatrix);
glMultMatrixf(modelViewMatrix);
}
int InitGL(GLvoid)
{
—>8—
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
glPushMatrix();
{
glRotatef(-15.0f, 1.0f,0.0f,0.0f);
glRotatef(0.0f, 1.0f,0.0f,0.0f);
glRotatef(-12.0f, 0.0f,1.0f,0.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix);
}
glPopMatrix();
EnableProjectiveTexturemapping();
—8<—
}
and then the main drawing loop:
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -15.0f);
glRotatef(xRotate,1.0f,0.0f,0.0f);
glRotatef(yRotate,0.0f,1.0f,0.0f);
glRotatef(zRotate,0.0f,0.0f,1.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);
glMultMatrixf(perspectiveMatrix);
glMultMatrixf(modelViewMatrix);
glBindTexture(GL_TEXTURE_2D, texture[0]);
cube.renderClassicWithoutTexCoords();
xRotate+=xRot;
yRotate+=yRot;
zRotate+=zRot;
}
Could anyone explain me why this isn’t working or how it actually SHOULD be done?
source & win32 executable can be found here: wslinux.website.fi/superdivine/projtex.zip
I’d really appreciate if someone could explain me this projective texture mapping thingie
Thanks in advance,
-t33