# projective texture in 2D

is possible to make the projective texture-
mapping when I use OpenGl to make 2d graphics???

You can send 4d vertices with non-uniform w through OpenGL.

1/w usually controls texture minification and filtering parameters, so if you control w you also control projection.
The problems of this method are
1)You can’t turn off perspective division, so you need to premultiply the x/y/z coordinates by w. They’ll get divided by w later down the pipe and you end up getting the original coordinates used for drawing.

2)Not all matrix operations work with arbitrary w. Scaling does work, translation does not, I’m not sure about rotation but probably not. I’ve been doing this kind of stuff with an identity projection matrix and a scaled modelview matrix (0;0;0;1 being the center of the screen - you can’t change that).

eg

``````//load a 45° perspective projection (1 unit in z yields one unit in w)
...

glBegin(GL_TRIANGLES);
glVertex3f( 1.0f, 1.0f,-1.0f);
glVertex3f(-1.0f, 1.0f,-2.0f);
glVertex3f( 0.0f,-1.0f,-5.0f);
glEnd();
``````

This will need to be changed to the following

``````glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
glScalef(something,something,this_doesnt_matter);
//no other matrix operations allowed!

glBegin(GL_TRIANGLES);
glVertex4f( 1.0f, 1.0f,0.0f,1.0f);
glVertex4f(-1.0f, 1.0f,0.0f,2.0f);
glVertex4f( 0.0f,-1.0f,0.0f,5.0f);
glEnd();
``````

These two are equivalent.
If you want a flat ortho view with pseudo-perspective correct textures (pseudo because you effectively turn off perspective division), do this

``````//note the premulted vertex coords
glBegin(GL_TRIANGLES);
glVertex4f( 1.0f, 1.0f,0.0f,1.0f);
glVertex4f(-2.0f, 2.0f,0.0f,2.0f);
glVertex4f( 0.0f,-5.0f,0.0f,5.0f);
glEnd();
``````