Perspective distorsion using GL_QUAD

Hi !

I have a question about something that bugs me since a long time : I’m rendering textured quads to the framebuffer. I don’t have any z axis, so the texture is splitted in 2 triangles by the graphic card before rendering.
The problem is that the original quad, which is in the same plane, is transformed into 2 bound triangles which aren’t in the same plane anymore, leading to graphical distorsion ugliness :frowning:
3 screenshots :

  • original texture :
  • texture rendered, triangles on different planes :
  • texture the way I want it to be :

So my question is : is there a way to have a better handling of quad textures without z axis, ie having the texture rendered like in the 3rd image ?

Thanks for reading me :slight_smile:

You need to emulate perpective correction, use the w texture coordinate for it.
There is a web page somewhere that deals with exactly your problem, but I can’t find it at the moment.

Is it this one ?
EDIT: or this one (in french) ?
Researching with correct keywords helps a lot :stuck_out_tongue:
Thanks :wink:

Not really, these deal with perspective correction on 3D quads, and nowadays all GL implementations should do it with perspective correction by default.
It was a specific article on 2D trapezoidal quads.
Well anyway, either do it by rotating your quad, or tweak the last parameter to glTexCoord4 (q instead of w):
glTexCoord4f(x,y,0,0.5); // something like that

Assuming you use a 3x3 matrix to do the 2D projection you can just use the “w” coordinate from that calculation.

A short intro to 3x3 projective matrix can be found in the OpenVG 1.0 spec.

i want to know what that little girl is so happy about.

check out the stuff near the bottom of this page…

Thx for the link modus. /me added it to bookmarks.

Thanks a bunch for the link, that’s exactly what I needed :slight_smile:
I’ll give it a go later today.

The little girl texture is from a Sega Saturn game named Baku Baku Animals, she’s happy because she’s going to compete with someone in a puzzle game :wink:

I cannot edit my previous post … weird :stuck_out_tongue:

Anyway, after a bit of tweaking, I got everything right in my rendering : it works marvelously !
A little before / after pic :

Thanks again to everyone involved in this thread, you’re great :cool:

Hello again :slight_smile:
I still need help …
I’m trying to make this work in every possible configuration, and I still have trouble : it works great for trapezoids like these :

but for regular quads like this one :

it doesn’t work well …

For quad n°1 for instance, I’m using the following code :

// farther side of the texture
fTextureSmallSide = (float)( max(XA,XB)-min(XA,XB) ) / (float)usXLengthMax;
// closer side of the texture
fTextureBigSide = (float)( max(XC,XD)-min(XC,XD) ) / (float)usXLengthMax;

// calculation of s,t & q for each dot, r is fixed to 0
fsA=0; ftA=0; fqA=fTextureSmallSide;
fsB=fTextureSmallSide; ftB=0; fqB=fTextureSmallSide;
fsC=fTextureBigSide; ftC=fTextureBigSide; fqC=fTextureBigSide;
fsD=0; ftD=fTextureBigSide; fqD=fTextureBigSide;


glTexCoord4f(fsA,ftA,0,fqA);	glVertex2f(ConvertPixelX(XA),ConvertPixelY(YA));
glTexCoord4f(fsB,ftB,0,fqB);	glVertex2f(ConvertPixelX(XB),ConvertPixelY(YB));
glTexCoord4f(fsC,ftC,0,fqC);	glVertex2f(ConvertPixelX(XC),ConvertPixelY(YC));
glTexCoord4f(fsD,ftD,0,fqD);	glVertex2f(ConvertPixelX(XD),ConvertPixelY(YD));


But for quad n°5, I’m a bit confused about how the q coordinate is working, and how I should do … I’ve tried a lot of things, but results aren’t good at all :frowning:
I tried calculating fsA and ftA to be relative to the position into the quad, results were a bit better, but far from what is expected …

Any ideas on how to implement this ?

Thanks :slight_smile: