i have to 3d obj files in android. i have searched and find many forums and now im able to load obj+mtl files successfully. but i got problem with that obj and mtl files having many texture files . in may case ,in mtl every face it has a texture (.png). how to load this type of obj files in GLES? is it possible to load multi-texture obj in android opegl Gles? i have min3d, 3dmodelviewer and arjpct libs but no use. please help if it is possile to load multi-texture obj in GLES
for multi_texture i have done like this
mTextureHandle = setTexture(obj, textureId,GLES20.GL_TEXTURE1);
ByteArrayInputStream textureIs0 = new ByteArrayInputStream(obj.getTextureData().get(0));
int textureId0 = GLUtil.loadTexture(textureIs0);
mTextureHandle = setTexture(obj, textureId0, GLES20.GL_TEXTURE0);
ByteArrayInputStream textureIs2 = new ByteArrayInputStream(obj.getTextureData().get(2));
int textureId2 = GLUtil.loadTexture(textureIs2);
mTextureHandle = setTexture(obj, textureId2, GLES20.GL_TEXTURE2);
ByteArrayInputStream textureIs3 = new ByteArrayInputStream(obj.getTextureData().get(3));
int textureId3 = GLUtil.loadTexture(textureIs3);
mTextureHandle = setTexture(obj, textureId3, GLES20.GL_TEXTURE3);
ByteArrayInputStream textureIs4 = new ByteArrayInputStream(obj.getTextureData().get(4));
int textureId4 = GLUtil.loadTexture(textureIs4);
mTextureHandle = setTexture(obj, textureId2, GLES20.GL_TEXTURE4);
ByteArrayInputStream textureIs5 = new ByteArrayInputStream(obj.getTextureData().get(5));
int textureId5 = GLUtil.loadTexture(textureIs5);
mTextureHandle = setTexture(obj, textureId5, GLES20.GL_TEXTURE5);
ByteArrayInputStream textureIs6 = new ByteArrayInputStream(obj.getTextureData().get(6));
int textureId6 = GLUtil.loadTexture(textureIs6);
mTextureHandle = setTexture(obj, textureId6, GLES20.GL_TEXTURE6);
ByteArrayInputStream textureIs7 = new ByteArrayInputStream(obj.getTextureData().get(7));
int textureId7 = GLUtil.loadTexture(textureIs7);
mTextureHandle = setTexture(obj, textureId7, GLES20.GL_TEXTURE7);
ByteArrayInputStream textureIs8 = new ByteArrayInputStream(obj.getTextureData().get(8));
int textureId8 = GLUtil.loadTexture(textureIs8);
mTextureHandle = setTexture(obj, textureId8, GLES20.GL_TEXTURE8);
ByteArrayInputStream textureIs9 = new ByteArrayInputStream(obj.getTextureData().get(9));
int textureId9 = GLUtil.loadTexture(textureIs9);
mTextureHandle = setTexture(obj, textureId9, GLES20.GL_TEXTURE9);
public static int loadTexture(final InputStream is) {
Log.v("GLUtil", "Loading texture from stream...");
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);
GLUtil.checkGlError("glGenTextures");
if (textureHandle[0] == 0) {
throw new RuntimeException("Error loading texture.");
}
Log.v("GLUtil", "Handler: " + textureHandle[0]);
final BitmapFactory.Options options = new BitmapFactory.Options();
// By default, Android applies pre-scaling to bitmaps depending on the resolution of your device and which
// resource folder you placed the image in. We don’t want Android to scale our bitmap at all, so to be sure,
// we set inScaled to false.
options.inScaled = false;
// Read in the resource
final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
if (bitmap == null) {
throw new RuntimeException("couldnt load bitmap");
}
// Bind to the texture in OpenGL
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
GLUtil.checkGlError("glBindTexture");
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
GLUtil.checkGlError("texImage2D");
bitmap.recycle();
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
Log.v("GLUtil", "Loaded texture ok");
return textureHandle[0];
}