scale texture opengl 2

386 Views Asked by At

I have a rectangle in opengl 2 and I'm using a texture for it. It Works, but the texture is repeated over the rectangle, and what I want is to adapt to the size of the rectangle.

I have read in this tutorial about the different parameters you can set to achieve this: https://open.gl/textures

In my App I am using this:

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

According to the tutorial this should adapt the size of the texture to fill the rectangle, isn' it? Any clues about why isn't working that way?

1

There are 1 best solutions below

3
On BEST ANSWER

Actually stretching a texture over a rectangle works with the texture coordinates. But if you want to repeat it you have to set:

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);