Sign in to follow this  
DrDerekDoctors

OpenGL Texture warping on non-rectangular quads

Recommended Posts

I am probably the stupidest man alive for asking this, but I've been developing a 2D game engine using OpenGL and it's been pretty peachy up until now. However that's because all my quads have been rectangles but I've decided I want to allow arbitrary shaped quads with textures on them, and so when I have something trapezoidal I get that horrible texture spread problem. All polygons in my engine are perpendicular to the screen so it's not like I can fix this using perspective, so how can I get texture mapping like in "wanted" instead of what I've "got" at the moment? Thanks, (and apologies for thickness)

Share this post


Link to post
Share on other sites
just fix mapping coordinates. I think, that first 3 points of quad have it right, but last one is not right assigned. Put some code, that draw polygon inside glBegin(GL_QUAD(S)) ... glEnd()

Share this post


Link to post
Share on other sites
The mapping co-ordinates are correct. If you look at all four corners they're in the right place, it's just that rather than stretching the texture over the entire quad evenly, it's mapping it as two triangles.

Share this post


Link to post
Share on other sites
Sadly, it's part of a HUGE function which it can't really be unpicked from in a manner which would allow you to compile it.

But basically if you draw a trapezoidal GL_QUAD perpendicular to the screen with a rectangular/square bit of texture on it, then half the texture goes on one of the triangles in the quad and the other half goes on the other triangle, but as the triangles are of differing sizes it means you get a texture which looks warped.

It may be that I *have* to subdivide the quad into lots of smaller quads in order to fix it, but ideally there'd be some simple texture switch I could flick which would make it distribute the texels evenly in a quad.

Share this post


Link to post
Share on other sites
Here's some reading. Clicky. Reason is you want a perspctive effect, but neither your vertext or texture coordinates contains any perspective information. If you don't want to actually place the top vertex coordinates further away with perspective projection, you need to introduce the perspective in the texture coordinates instead.

Share this post


Link to post
Share on other sites
Righty, I had a look at that thing, Brother Bob and while it's good for some purposes it introduces fake perspective into the texture, which I really would prefer not to have in some instances. i.e, now it's a case of:



I fiddled around with the program but there wasn't anything I could find to alleviate this effect. Is this simply not possible?

Thanks,

Share this post


Link to post
Share on other sites
Not sure this'll work, but you can try:

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this