我正在使用此函数加载512x512纹理(图集:包含许多图像),(尝试使用drawable和mipmap):
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];
}
我到处都搜索过,但似乎我是唯一一个遇到这个问题的人(另一个回答的问题有NPOT图像或没有GL_REPEAT)。
我怎样才能一次又一次地在脸上重复一部分地图集?是否可以在着色器中使用?