Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture warping on non-rectangular quads

Started by DrDerekDoctors Jun 5, 2007 at 4:54 PM 7 replies 1.6k views
Original Post
DrDerekDoctors
DrDerekDoctors
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)
janci123
janci123
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()
DrDerekDoctors
DrDerekDoctors
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.
janci123
janci123
code help's (I beliew only what I see)
DrDerekDoctors
DrDerekDoctors
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.
Brother Bob
Brother Bob
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.
DrDerekDoctors
DrDerekDoctors
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,
FReY
FReY
Not sure this'll work, but you can try:

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
do unto others... and then run like hell.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.