Results 1 to 10 of 19

Thread: 2D perspective correct texturing ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by SilverWarior View Post
    Why do I have feeling that Nuno spends too much time on communities like Stack Overflow?
    I don't know, because I never used Stack Overflow, and I don't know if any other or the communities I spend too much time on are like that as I never used it.

    Quote Originally Posted by SilverWarior View Post
    I would expect such answer on the Stack Overflow where most people blindly tends to answer the question that was asked and not the question that was intended to be asked.
    I can answer this:

    That's because, in my experience, the question that was intended to be asked is often not the actual question that should be asked. And if I've understood correctly the other messages, this is one of these cases. (Please, correct me if I'm wrong in this: I'm still learning English)

    Quote Originally Posted by SilverWarior View Post
    So Nuno can you please provide short example for rendering skew quad using OpenGL?
    Of course I can, but it would be too similar to the one provided by phibermon.

    [Disclaimer]: I must apoligize. Some times I can be too much sarcastic. Please, no offense intended. If you think I've exceed the limit, please tell me and I'll try to keep my responses under control. Really.

    Quote Originally Posted by SilverWarior View Post
    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?
    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.
    Last edited by Ñuño Martínez; 08-03-2015 at 07:55 PM.
    No signature provided yet.

  2. #2
    Hi Ñuño,

    sorry for may question, but I need only help for my problem. That's it!

    Regards
    Sesilla

  3. #3
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Quote Originally Posted by SilverWarior View Post
    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.

    Quote Originally Posted by Ñuño Martínez View Post
    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.
    Last edited by phibermon; 09-03-2015 at 03:43 AM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •