PDA

View Full Version : perspective projection & texture problem

ugluk
02-01-2010, 03:37 PM
I need to display a texture as is, with texels mapping to pixels perfectly. I need to do it under perspective projection, the frustum being symmetrical and with the screen aspect ratio. I can't use point sprites. So I am calculating the quad coordinates on which I paste the texture like this:

half_width = (-zeye * ((texture.get_width() - 1) /
GLfloat(width)) * (GetL(frustum) - GetR(frustum)) - (GetL(frustum) + GetR(frustum))) / (2 * GetN(frustum));

-zeye is the distance from the camera to the texture plane

I make a quad with coordinates (+-half_width, +-half_width). That's a quad symmetrical over the origin. Texture coordinates for the corners are the usual zeros and ones. The formula shows promise, but there appear artifacts now and then. Can you help? I cannot toss the perspective projection requirement.

dletozeun
02-01-2010, 04:19 PM
Could we have a screenshot of the artifacts? It is hard to realize what could happen from this formula. There is something that I can't understand, how could map a texture to screen pixels perfectly while using perspective projection? With this kind of projection the texture will always been rescaled and distorted.

You may also use the gl function glFrustum (http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml) to check if your custom projection is correct.

ugluk
02-02-2010, 04:00 AM
The idea is to convert the halfwidth of the texture in screen coordinates into halfwidth of the texture in world coordinates. It's a kind of inverse transform of the perspective projection.

Hence, if the camera is far away the world halfwidth will increase.