libgdx, how to make opengl stretch the image correctly?

Viewed 233

So I am trying to create a simple methode for stretching images when rendering them. But because opengl works with these triangles instead of rectangles it sort of screws up.

enter image description here

as you can see the 2 parts of the triangle are stretched differently. the code I have for this is the following:

public static void drawTexture(Texture texture, float x, float y, float x2, float y2, float x3, float y3, float x4, float y4){
    if(cantRender()) return;
    polyBatch.begin();
    float[] vertices = new float[20];

    float color = Color.WHITE.toFloatBits();
    int idx = 0;
    vertices[idx++] = x;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = 0;
    vertices[idx++] = 1;

    vertices[idx++] = x2;
    vertices[idx++] = y2;
    vertices[idx++] = color;
    vertices[idx++] = 1;
    vertices[idx++] = 1;

    vertices[idx++] = x3;
    vertices[idx++] = y3;
    vertices[idx++] = color;
    vertices[idx++] = 1;
    vertices[idx++] = 0;

    vertices[idx++] = x4;
    vertices[idx++] = y4;
    vertices[idx++] = color;
    vertices[idx++] = 0;
    vertices[idx++] = 0;
    polyBatch.draw(texture, vertices, 0, 20);


    polyBatch.end();
}

Renderer.drawTexture(testTexture, 100, 100, 500, 100, 400, 500, 200, 500);

I have found a fix on the internet, but I don't know how i can make it work in combination with libgdx. this is the article i found: http://www.xyzw.us/~cass/qcoord/. The problem is that it doesn't seem like libgdx supports all 4 of these variables like described in the article.

0 Answers
Related