Results 1 to 5 of 5

Thread: OpenGL - 2D - Skewing/distorting texture vertically along a line

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    OpenGL - 2D - Skewing/distorting texture vertically along a line


    I've currently been wrestling with an issue involving texture coordinates.

    Basically the issue I'm having is faking a projection (Orthagonal? Affine Tranformation? [I'm not sure]) with the walls.

    My "walls" are defined as 4 points:
    top-Left is point 0
    top-right is point 1
    bottom-left is point 2
    bottom-right is point 3

    The lines 0,1 and 2,3 are always parallel (and 0,2 and 1,3 as well)
    The vertical difference between the lines is a constant called cGridsize
    The horizontal length of the lines are always divisible by cGridsize
    Also the texture's width and height is also cGridsize.
    cGridsize is always a Power of Two.

    I split the wall-quad into 2 tris:
    tri1 is Point1 to Point0 to Point3
    tri2 is Point2 to Point3 to Point0

    What I want to do is distort a texture so that the bottom of the texture runs along the bottom/top of the wall like so:

    Here's one with a rough triangle overlay:

    I have gotten it to work when the one of the base lines go across one and up one or across two and up one but it doesn't work when I go across two and up two (the texture angle is slightly off) or if I go up two across one (It has the same angle as up one across one).

    The current way I slope the texture is as follows (We'll just work with one triangle):

    Here's the generic way I do it:
    TexCoord[0].x := Tri[0].x/cGridsize;
    TexCoord[0].y := Tri[0].y/cGridsize;

    TexCoord[1].x := Tri[1].x/cGridsize;
    TexCoord[1].y :=(Tri[0].y+(Tri[1].y-Tri[2].y))/cGridsize;

    TexCoord[2].x := Tri[2].x/cGridsize;
    TexCoord[2].y := Tri[2].y/cGridsize;

    In the above example the triangle array index refernces the points the way they are ordered on the above image.

    I've tried many other ways to do it but so far this one works the best, the other methods limited the angles of the line.
    Does anybody know how to do it or what I'm doing wrong?

    Rotation is not what I'm looking for, I don't want any distortion horizontally!

    Also I'm using ZenGL for working with OpenGL, but it doesn't seem to mess with the co-ord system.
    Attached Images Attached Images
    Last edited by Draghi; 30-12-2012 at 01:46 PM. Reason: Fixing Typo, Clarifing Example

Tags for this Thread


Posting Permissions

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