Question about how textures are applied to quads which are scaled unevenly

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
This is a particularly simple question. I've got textured quads -- the leaves on my trees -- which are not squares, per se, but rather are scaled such that one edge is *much* wider than the other. They almost look like triangles, with the tip cut off.

They'rer drawn as quads, nothing fancy.

The issue is that the texture is horribly distorted and not in the way I expect. The way the texture is distorted screams to me that the quads ( GL_QUADS ) are actually being turned into triangles before being rasterized -- which I guess isn't surprising.

Here's a simple drawing of what I'm talking about since the drawing makes clearer what I'm seeing than a screenshot would since the problem, while glaring, is only obvious to me if I'm looking for it.

[Image: quadtacular.png]

What I'm wondering is if there's a way to get around this. The best I can think of is to clamp the texture and just screw with the texture coordinates instead of distorting the quad.

Any suggestions?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
What texture coordinates are you choosing for each vertex? I would think it would draw correctly if you choose the texture coordinates as if it was a non-distorted quad.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
I choose texture coordinates just like I would for any other quad (note I'm drawing both sides, with cull face disabled ):

Code:
/*
    Draw the front side ( CCW )
*/

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 0.0f );
glNormal3fv( frontNormal.v );
glVertex3fv( vertices[0] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 0.0f );
glNormal3fv( frontNormal.v );
glVertex3fv( vertices[1] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 1.0f );
glNormal3fv( frontNormal.v );
glVertex3fv( vertices[2] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 1.0f );
glNormal3fv( frontNormal.v );
glVertex3fv( vertices[3] );

/*
    Draw the backside ( CW )
*/

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 0.0f );
glNormal3fv( backNormal.v );
glVertex3fv( vertices[0] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 1.0f );
glNormal3fv( backNormal.v );
glVertex3fv( vertices[3] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 1.0f );
glNormal3fv( backNormal.v );
glVertex3fv( vertices[2] );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 0.0f );
glNormal3fv( backNormal.v );
glVertex3fv( vertices[1] );
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #4
If cull face is disabled and you're drawing both sides, I could see that potentially causing problems. Try drawing just one side. Since cull face is disabled, it should show through to the other side. Even if it doesn't fix anything, it would at least lessen the drawing.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Most hardware will indeed triangulate quads before drawing them. Why not send triangles, if that's what you want?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
The problem is when the quad is split into triangles, you're unevenly distorting them. If you draw a diagonal onto your trapezoids, one triangle is going to be almost the size of the trapezoid, and the other triangle will be tiny.

Changing the perspective correction won't help for geometry that isn't distorted by perspective will it?

OSC: Don't they always transform quads into triangles?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
arekkusu Wrote:Getting to know the Q texture coordinate...

Please explain...

Isn't that just the texture name for the w-coordinate? How does that help?

edit: Ok, so it works, but I'm a bit befuddled as to how the math works out. How would you calculate the texture coordinates for an arbitrary quad? Compare edge sizes?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #9
arekkusu Wrote:Getting to know the Q texture coordinate...

Excellent, thank you. How I missed this in the Red Book is beyond me, perhaps it didn't cover it? Seems like something I should have known.
Quote this message in a reply
Member
Posts: 41
Joined: 2006.01
Post: #10
The last time I had a problem like this, I changed it to a single triangle.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Replacing edges with degenerate quads (for shadow volumes) Coyote 9 7,252 Jan 15, 2010 07:08 PM
Last Post: Coyote
  One texture... multiple quads? Jones 6 4,418 Jul 12, 2006 01:14 PM
Last Post: kordova
  Quick question, will glCopyTexSubImage2D with with RECT textures? TomorrowPlusX 28 8,626 Jun 8, 2006 07:04 PM
Last Post: akb825
  Nearly overlapping Quads causing Jagged Edges Lunatic 3 3,728 Oct 28, 2005 04:41 AM
Last Post: Lunatic
  White quads instead of textured quads pkraft 3 3,069 Mar 3, 2005 04:23 PM
Last Post: AngelDaniel