Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: 2D perspective correct texturing ?

  1. #1

    2D perspective correct texturing ?

    Hi,

    Have you idea about opengl texturing skew quad ?

    Regards

  2. #2
    Yes I have.
    No signature provided yet.

  3. #3
    Good!!!!.....and?


    Regards
    Sesilla

  4. #4
    Why do I have feeling that Nuno spends too much time on communities like Stack Overflow?
    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.
    Yes sometimes it is hard to figure out what asker is trying to ask. But here I think it is quite clear that Sesilla also wants to see an example of how this is done.

    So Nuno can you please provide short example for rendering skew quad using OpenGL?
    Last edited by SilverWarior; 06-03-2015 at 10:03 AM.

  5. #5
    @Sesilla
    While here on PGD we usually don't treat weak or broad questions as plague like they are commonly treated on Stack Overflow it is still good if you can provide more information in your question about what kind of an answer do you expect as this helps us understand of what do you need.

    Also sometimes it might be better to provide description of that final results do you expect instead of asking about specific approach. Why? This way you might get answer with multiple possible approaches so you can then chose the one that suits you best.

  6. #6
    @SilverWarior
    Thanks for your suggestions!

    Thi is my quad:




    This is a texture:



    And this the result with possibilities to "deform" the scale or tile of the texture:



    Thanks in advance
    Sesilla
    Attached Images Attached Images

  7. #7
    Do you wan't the texture to be projected on your quad so that it looks like rotated plane (texture rotates and scales with the quad) or just use your quad as mask to show only part of the texture as it is done in your image example?

  8. #8
    The first one! The texture projected like pseudo 3d!

    Sesilla

  9. #9
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    If you're in OpenGL then you're providing texture coordinates for the quad. Perspective correction is automatic. You provide coordinates between 0.0 and 1.0 for each of your vertices. To produce an image like you've posted you have to scale the texture coordinates in relation to your vertex coordinates, or in much older versions of GL you can use automatic texture coordinate generation which in 2D will produce the same result.

    The solution for 'perspective' in 2D as you desire is to simply leave your texture coordinates at each corner of the texture while altering the vertices of the quad.

    Input the vertex coordinates that would give you a quad like in the image you have provided and in counter-clockwise order (OpenGL defaults to counter-clockwise winding to determine front facing polygons) set your texture coordinates as (x:0,y:0) (x:0,y:1) (x:1,y:1) (x:1,x:0)

    As long as you keep your texture coordinates the same, you can draw your (convex) quad at any combination of vertices and openGL will 'skew' the texture automatically.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  10. #10
    Hi phibermon,

    with this code:
    Code:
    glBegin(GL_QUADS);
            
    glTexCoord2f(0, 0);
    
    glVertex2f  (500, 200);
    
    glTexCoord2f(0, 1);
    glVertex2f  (600,  200);
    
    glTexCoord2f(1, 1);
    glVertex2f  (1000,  700);
    
    glTexCoord2f(1, 0);
    glVertex2f  (50, 700);

    this is the rendering:



    Browsing the web i found the Opengl glTexCoord4f function, but it is not clear about use it.

    Thanks
    Sesilla
    Attached Images Attached Images

Page 1 of 2 12 LastLast

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
  •