texture mapping

Started by
7 comments, last by w_poons 18 years, 5 months ago
This maybe a stupid question but is such a mapping of a texture possible with OpenGL? Maybe by changing the texture matrix? checkerboard left side: texture right side: textured polygon thanks for any help!
Advertisement
Texture co-ordinates are attached to vertices, and vertices are used to define the corners of a quadrangle. If the quadrangle becomes stretched, so the mapped texture becomes. So the simplest way to yield the requested result is to map the texture "normally" (upper left vertex with (u,v)=(0,0), upper right vertex with (u,v)=(1,0), lower left with (u,v)=(0,1), and lower right with (u,v)=(1,1)), and to locate the vertices of the quad as shown in your picture. OpenGL will interpolate the texture co-ordinates accordingly.

Or do you actually want to stretch the texture before mapping it on a regular square?
PERSPECTIVE TEXTURE MAPPING

so yes, you can do that.... look at the options for perspective texture mapping
Quote:Original post by haegarr
Texture mapping basics

The problem is more subtle than you think.

Notice that both images are "correct", in that the texture mapping has been interpolated from the three vertices. The first image, however, is actually correct, because it's using perspective correct texture mapping.

To the OP: I believe graphics hardware always does perspective correct texture mapping now, but I may be wrong.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
I'm always getting the result of your right picture.

So I will have to look up perspective texture mapping. Has somebody some good starting points on this?
Quote:Original post by Promit
The problem is more subtle than you think.

Not really. I know of the problem of texture interpolation, since my first attempts with this stuff were on Glide API, and there the 1/w interpolation was to set-up by hand to get the stuff work.

However,
Quote:Original post by Promit
I believe graphics hardware always does perspective correct texture mapping now, but I may be wrong.

is what also I believed, so I'm surprised that w_poons has this problem today.
Quote:Original post by haegarr
is what also I believed, so I'm surprised that w_poons has this problem today.


Note that all the four vertices lay at the same z-value. could that lead to my problem?
The problem occurs from the fact how the OpenGL implementation interpolates the texture co-ordinates. The quad is divided up into 2 tris (you already have seen this ;-) and each tris is textured w/o considering the other tri. What you want is an interpolation that considers weighting of 4 corners, but you get 2 independend interpolations that each one considers weighting of 3 corners only.

To solve the problem, the standard linear interpolation has to be replaced. The first possibility may be what the Red Book says:
Quote:Red Book
Note: The checkerboard image on the tilted polygon might look wrong when you compile and run it on your machine - for example, it might look like two triangles with different projections of the checkerboard image on them. If so, try setting the parameter GL_PERSPECTIVE_CORRECTION_HINT to GL_NICEST and running the example again. To do this, use glHint().

This isn't absolutely the same situation as yours, but maybe it help?!

However, as I have interpreted the stuff well I've read recently, an OpenGL implementation need not support perspective correct interpolation this way. Maybe texture matrix math may help, but I don't know.
Quote:Original post by haegarr

Quote:Red Book
Note: The checkerboard image on the tilted polygon might look wrong when you compile and run it on your machine - for example, it might look like two triangles with different projections of the checkerboard image on them. If so, try setting the parameter GL_PERSPECTIVE_CORRECTION_HINT to GL_NICEST and running the example again. To do this, use glHint().




Tried this but does not change anything. This is all wired. Thanks for your explanations!

This topic is closed to new replies.

Advertisement