PDA

View Full Version : Using gluLookat after texture projection



Toshminosh
07-09-2010, 09:27 AM
Hiya. I have a problem where after using gluLookAt to orient a texture projection in a scene, on subsequent calls of gluLookAt, the texture is projected according to the new coordinates. I want to leave the projection as it is but be able to look around the scene with gluLookAt.

void renderPrimitive(int width, int height)
{

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0);
glScalef(0.5, 0.5, 1);
glOrtho (-15.0f*width/height, 15.0f*width/height, -15.0f, 15.0f, -100.0f, 100.0f);
gluLookAt(0.0, 0.0, 0.0,
0.0, 0.0, -1.0,
0.0, 1.0, 0.0);


GLfloat Splane[] = {1.f, 0.f, 0.f, 0.f};
GLfloat Tplane[] = {0.f, 1.f, 0.f, 0.f};
GLfloat Rplane[] = {0.f, 0.f, 1.f, 0.f};
GLfloat Qplane[] = {0.f, 0.f, 0.f, 1.f};

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, Splane);
glEnable(GL_TEXTURE_GEN_S);

glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, Tplane);
glEnable(GL_TEXTURE_GEN_T);

glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, Rplane);
glEnable(GL_TEXTURE_GEN_R);

glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, Qplane);
glEnable(GL_TEXTURE_GEN_Q);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 0.0,
5.0, 0.0, -60.0,
0.0, 1.0, 0.0);

glBegin(GL_QUADS);

glVertex3f(-15.0f*width/height, -15.0f, -90.0f);

glVertex3f(15.0f*width/height, -15.0f, -90.0f);

glVertex3f(15.0f*width/height, 15.0f, -90.0f);

glVertex3f(-15.0f*width/height, 15.0f, -90.0f);
glEnd();
glColor3f(.0f, 1.0f, 0.0f);

DrawObject(x, y, -60.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glDisable( GL_TEXTURE_2D );

glLoadIdentity();


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
gluPerspective(20, width/height, 1, 1000);
glMatrixMode(GL_MODELVIEW);

strattonbrazil
07-09-2010, 11:03 AM
I'm not sure if I understand what the problem is. I don't see any errors in the code, per se. Are you saying when you move your eye, the projected textures on the objects "swim" around the object instead of staying fixed on the object?

If that is the problem, it might be related to

glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

where you're telling OpenGL to generate UVs dependent on where the eye is, so when the eye moves, you get different UVs. Try GL_OBJECT_LINEAR.