Jump to content
  • Advertisement
Sign in to follow this  
w_poons

OpenGL texture mapping

This topic is 4637 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
PERSPECTIVE TEXTURE MAPPING

so yes, you can do that.... look at the options for perspective texture mapping

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!