Search code examples
opengltexturesscale

scale texture opengl 2


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?


Solution

  • 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);