Originally Posted by
SilverWarior
Didn't you also messed up with the coordinates here? Specifically for second triangle?
Shouldn't the order of coordinates for second triagnle be TopLeft, BottomRight, TopRight?
No I didn't mess up, they should be in counter-clockwise order, in this example I did BottomRight, TopRight, TopLeft. You can start at ANY point, as long as you go round in a counter-clockwise direction. Take a look at my coordinates then take a look at a clock. You don't have to start from any specific position, only the winding matters. Imagine yourself standing in the middle of the triangle, now look at each of my points in turn, you are spinning in a counter-clockwise direction.
Originally Posted by
Ñuño Martínez
Yes, on the first triangle is counter-clockwise and the second is clockwise. Both them should have the same "wise" to use back face culling correctly
No, both triangles are counter-clockwise, it's called the winding order and normal determination is used for an awful lot more than just back face culling. I just didn't start from the 'top-left'. There's no such thing as Top Left, Bottom Right etc - these are over simplified descriptions given in examples to teach people. In your world of winding the moment I roll my airpane onto its side, all the polygons disappear. You are mistaken. Please check again.
------------
Code:
glBegin(GL_TRIANGLES);
//Triangle 1 (counter-clockwise)
//Top Left
glTexCoord4f(0, 0, 0, 600-500);
glVertex2f(500, 200);
//Bottom Left
glTexCoord4f(0, 1000-50, 0, 1000-50);
glVertex2f(50, 700);
//Bottom Right
glTexCoord4f(1000-50, 1000-50, 0, 1000-50);
glVertex2f(1000, 700);
//Triangle 2 (counter-clockwise)
//Bottom Right
glTexCoord4f(1000-50, 1000-50, 0, 1000-50);
glVertex2f(1000, 700);
//Top Right
glTexCoord4f(600-500, 0, 0, 600-500);
glVertex2f(600, 200);
//Top Left
glTexCoord4f(0, 0, 0, 600-500);
glVertex2f(500, 200);
glEnd();
Note how Q (fourth argument) is set to the width at the top for the top coordinates, and the width of the bottom for the bottom coordinates, then we've used the width as the maximum value of S *OR* T coordinates. You could add 'perspective' like this on any axis, just be sure to set Q as the width and then know that your maximum position on the texture in either axis is Q.
Perhaps it would be best for you to skew your image in another program and just use that modified image on a regular quad in order to save confusion. currently your 'quad' is on a single plane that is parallel with the camera plane and we're 'skewing'. If our quad were specified in 3D coordinates and orientated to the camera to replicate the results of your code then you'd just specify the texture coordinates like you initially did.
note : glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) is not needed in this example, on *some* drivers it will scale your texture coordinates automatically for polygons specified with glVertex2F (and you may have to use automatic texture coordinate generation) but how we're achieving the results here will work regardless.
Bookmarks