Search code examples
c++openglsdl

OpenGL - Texture coordinates on quad


I have no idea what's wrong. Everything seems to be fine. Here's code (texture is loaded, just drawing) :

glBegin( GL_QUADS );
    float TX1,TX2,TY1,TY2;

    TX1=some_numbers_check_below_code;
    TX2=some_numbers_check_below_code;
    TY1=some_numbers_check_below_code;
    TY2=some_numbers_check_below_code;

    glTexCoord2f(TX1,TY2);
    glVertex3f( float(RectOutput.x), float(RectOutput.y), 0.0f );

    glTexCoord2f(TX2,TY2);
    glVertex3f( float(RectOutput.x+InputWidth), float(RectOutput.y), 0.0f );

    glTexCoord2i(TX2,TY1);
    glVertex3f( float(RectOutput.x+InputWidth), float(RectOutput.y+InputHeight), 0.0f );(InputY)/float(Input.H)) );

    glTexCoord2f(TX1,TY1);
    glVertex3f( float(RectOutput.x), float(RectOutput.y+InputHeight), 0.0f );

glEnd();

It's okay with :

TX1=0.0;
TX2=1.0;
TY1=1.0;
TY2=0.0;

(Good : https://i.sstatic.net/2Bj8i.png)

But gets broken with (eg.) :

TX1=0.0;
TX2=0.5;
TY1=1.0;
TY2=0.5;

(Like this : https://i.sstatic.net/Xem99.png)

Really, it annoys me. Probably problem isn't in this code. Everything should be fine ... but it's not.

Any ideas?


Solution

  • "I have no idea what's wrong. Everything seems to be fine". Great then, no need to answer!

    You should first explain what do you expect to get in second case. I am not an OpenGL expert, but your second set of coordinates seem broken.

    The first one: 0,0 -> 1,0 -> 1,1 -> 0,1:

      0     1
    0 x---->x
      |     |
      |     |
      |     v
    1 x<----x
    

    The second one: 0,.5 -> .5,.5 -> .5,1 -> 0,1:

      0     1
    0 +-----+
      |     |
      x->x  |
      |  v  |
    1 +--x->x
    

    If you want to scale the texture (but I don't know as you haven't written what is supposed to be the result) then this is obviously wrong.