I need help with setting a texture to a .MD2 model in java/android
According to wikipedia, I came up with the following: ( MD2 (file_format) )
Loading texCoords:
int idx = 0;
for(int i = 0; i < this.pHeader.num_st; i++) //num_st = Number of texture coordinates
{
this.fTexCoords[i][0] = (float)is.readShort(); //S
this.fTexCoords[i][1] = (float)is.readShort(); //T
}
and computing them:
int idx2 = 0;
int idx = 0;
for(int i = 0; i < this.pHeader.num_tris; i++) //num_tris = Number of triangles
{
this.fIndices[idx+0] = is.readUnsignedShort();
this.fIndices[idx+1] = is.readUnsignedShort();
this.fIndices[idx+2] = is.readUnsignedShort();
int uvID0 = is.readUnsignedShort();
int uvID1 = is.readUnsignedShort();
int uvID2 = is.readUnsignedShort();
this.fTEXTURE[idx2+0] = (float)(this.fTexCoords[uvID0][0] / (float)this.pHeader.skinwidth); //s
this.fTEXTURE[idx2+1] = (float)(this.fTexCoords[uvID0][1] / (float)this.pHeader.skinheight); //t
this.fTEXTURE[idx2+2] = (float)(this.fTexCoords[uvID1][0] / (float)this.pHeader.skinwidth); //s
this.fTEXTURE[idx2+3] = (float)(this.fTexCoords[uvID1][1] / (float)this.pHeader.skinheight); //t
this.fTEXTURE[idx2+4] = (float)(this.fTexCoords[uvID2][0] / (float)this.pHeader.skinwidth); //s
this.fTEXTURE[idx2+5] = (float)(this.fTexCoords[uvID2][1] / (float)this.pHeader.skinheight); //t
idx += 3;
idx2 += 6;
}
Converting everything into buffers and drawing it:
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, this.TextureBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0, this.NormalBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.VertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, (this.max_indices*3), GL10.GL_UNSIGNED_SHORT, this.IndexBuffer);
This is the result ( model is rendering fine with animations etc. but colors/texture is messed up - it should just color the feet )
How it should look( blender ): http://img6.imagebanana.com/img/rh6l4awq/blender.png and how it actually looks on my phone: http://img6.imagebanana.com/img/wud654s9/SC20120806172956.png
I saved the blender texture file as png ( View -> Pack as PNG -> save as )
Thanks for any help