Results 1 to 10 of 19

Thread: 2D perspective correct texturing ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Your vertices are in clockwise order and your texture coordinates are in counter-clockwise order, the GPU actually draws two triangles and not a quad and because you have opposite winding, the two triangles are getting different relative texture coordinates. Always draw two triangles instead of one quad so this fact is always present in your mind and such issues become more obvious. It's better for all kinds of technical reasons that you don't need to learn if you don't want to. try the following instead :

    Code:
    glBegin(GL_TRIANGLES);
            
    glTexCoord2f(0, 0);
    glVertex2f(500, 200);
    
    glTexCoord2f(0, 1);
    glVertex2f(50, 700);
    
    glTexCoord2f(1, 1);
    glVertex2f  (1000,  700);
    
    
    glTexCoord2f(1, 1);
    glVertex2f  (1000,  700);
    
    glTexCoord2f(1, 0);
    glVertex2f  (600,  200);
    
    
    glTexCoord2f(0, 0);
    glVertex2f(500, 200);
    
    glEnd();
    Counter-clockwise always for coordinates. OpenGL and other API's like Direct3D use what is called the 'winding order' to determine if a one sided polygon is facing you (the 'camera') ( one sided polygon = default OpenGL state - simply meaning that it will be invisible if viewed from the other side. This implies that you can render two-sided polygons that are visible from both sides and this is true. This would seem preferable as you don't have to care about winding but in reality it slows down rendering as discarding polygons that can't be seen is one of the main principals behind rendering things more quickly. In 2D this isn't really an issue as you'll never be 'looking' from the other side of the polygon but it's best practice and should you move to 3D you'll already be doing things correctly)
    Last edited by phibermon; 06-03-2015 at 08:32 PM.
    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
  •