I am loading a 512x512 texture (atlas: containing many images), (tried from both drawable and mipmap) using this function:
public static int loadTexture(final Context context, String textureName, final int resourceId, int textilesForWidth)
{
final int[] textureHandle = new int[1];
glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false; // do not scale the image
// Read in the resource
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
// Bind to the texture in OpenGL
glBindTexture(GL_TEXTURE_2D, textureHandle[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// Set filtering
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
// Recycle the bitmap, since its data has been loaded into OpenGL.
bitmap.recycle();
}
if (textureHandle[0] == 0) {
throw new RuntimeException("Error loading texture.");
}
textures.put(textureName, textureHandle[0]);
texture_length.put(textureName, textilesForWidth);
return textureHandle[0];
}
However the textures stretch as shown:
I have searched all over the place, but seems I am the only one getting this problem (The other answered questions had NPOT images or no GL_REPEAT).
How can I repeat one part of the atlas on a face again and again? is it possible from within the shaders?