PDA

View Full Version : A question about perspective texture



ChinaShrimp
03-16-2004, 04:28 AM
Hi!
Now I want to project a perspective texture onto a polygon, and get a orthographic view of

the polygon. I did as following:
1.Mapp the texture to the plane
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0,-1.0, -1600);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, 1.0,-1600);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0, 1.0,-1600);
glTexCoord2f(1.0, 1.0);
glVertex3f( 1.0,-1.0,-1600);
2.Set the texture matrix
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glScalef(0.5, 0.5, 1.0);
gluPerspective(20, 1, -1600, 1600);
glRotatef(10, 1.0, 0.0, 0.0);
glTranslatef(0.0, 0.0, -1600);
3.render the scene
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 2000);
DrawObject();
But I got an undesired result. I want to know what's wrong with the method mentioned above?

Can anyone give me some suggestions?
Thank you in advance!

dorbie
03-16-2004, 03:23 PM
One problem is you have 2D texture coordinates not 3D, but also you should probably use texgen around the origin and divide by z using a glFrustum call on the texture matrix and translate & orient to the desired position.

It'll take a bit of doing but there are online examples for you to look at that will help a lot.

[This message has been edited by dorbie (edited 03-16-2004).]