Perspective backprojection of 2D

Hello everybody,

I am bloody new in OpenGL and up to now I found all answers in the forum, thanks for that.
But now I have a problem where I’m not quite sure if it is solvable.

The task:
Back project a photo of an arbitrary object as texture to its corresponding 3D model surface.

Given:

  1. Photo of an object.
  2. 3D obj-model of this object.
  3. Parameters which determine the location and orientation of the object in 3D.
    So if this scene will be rendered, the object on the photo and rendered image overlap exactly.

Process:

  • Rotate, scale, and shift the object to the “matching” position.
  • Figure out the 2D coordinates for each vertex of the model using gluProject(3D coordinates) and write these coordinates in the obj-file.

Additional info:
The model consists of triangles.
Ignore the fact that the backside gets no texture.

This all works fine for orthographic projection, see picture 1

For perspective projection the mapping is only correct for the 3 vertex coordinates which specify the triangle (the corners). In between these corners, OpenGL seem to perform a non linear interpolation. See picture 2.

The effect reduces while the vertices shrink. Thus one way is to split all triangles to sub triangles unless they are so small that they usually get one pixel as texture. But since this is only a work around and blows up the complexity of the model exponentially, I am interested in a more elegant and efficient way.
I also tried to use glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST) but this should be set as default I think and had no effect.
I am not sure if this is really a problem with the perspective correctness texture mapping.

Thanks for help and tips in advance.

Cheers Jan

Is that what you are after ?
http://www.ozone3d.net/tutorials/glsl_texturing_p08.php?lang=2
http://www.opengl.org/resources/code/samples/mjktips/projtex/index.html

You actually need to work with 4d homogeneous coordinates to make it work.

Thx I’ll have a try.