View Full Version : Perspective distorsion using GL_QUAD
11-06-2007, 03:04 AM
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 :(
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 :)
11-06-2007, 05:23 AM
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.
11-06-2007, 06:00 AM
Is it this one (http://www.lysator.liu.se/~mikaelk/doc/perspectivetexture/) ?
EDIT: or this one (http://www-evasion.imag.fr/Membres/Antoine.Bouthors/teaching/opengl/opengl7.html) (in french) ?
Researching with correct keywords helps a lot :p
11-06-2007, 08:37 AM
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
11-06-2007, 03:07 PM
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.
11-06-2007, 03:57 PM
i want to know what that little girl is so happy about.
check out the stuff near the bottom of this page...
11-06-2007, 04:44 PM
Thx for the link modus. /me added it to bookmarks.
11-07-2007, 01:00 AM
Thanks a bunch for the link, that's exactly what I needed :)
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 ;)
11-07-2007, 12:32 PM
I cannot edit my previous post ... weird :p
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:
11-21-2007, 04:36 PM
Hello again :)
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;
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 :(
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 ?
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.