I made a picture of the model. As you can see the texture cliches and that one misplaced vertex on the right hand. Error is not in the .obj file, and the reader works correctly also. So the problem is probably in prepareVBO method. But i dont understand, where can this kind of error come in. When i use the VBO i used at the beginning the one that works with drawArrays, the model comes out fine, no errors no nothing, i just cant multitexture it. Now i remade the code to support drawElements, and im getting this bug.
Maybe someone else can spot the error in my code.
I have a question about the .OBJ file. I did some calculation and i found out that the total amount of vt lines is less than total amount of v lines or vn lines. I investigated bit more and found out that the amount of v lines equals to the amount of vn lines. And since the .OBJ is separated into 3 objects: Cape, hair, body, i looked into the amount of lines in each individual object. in Cape amount of v equals the amount of vt equals the amount of vn. In hair there are 22 more vt lines than there are v or vn. In body there is 1105 vt lines less than there is v or nv. Is this ok, or is something wrong with the exporting? Or do i need to make the shading stuff also before i can fully get the texture working?
Edited: Fixed the finger. In the array creation i had put one index wrongly. Texture still messed up.
public void prepareVBO(){
vboIndeciesID = glGenBuffers();
vboVertexID = glGenBuffers();
int x = 0;
int e = 11;
for(int i = 0; i < faces.size(); i++){
total += faces.get(i).size();
}
float[] buffer = new float[33 * total];
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(33* total);
IntBuffer indeciesBuffer = BufferUtils.createIntBuffer(33*total);
for(int i = 2; i < faces.size(); i++){
for(Face face : faces.get(i)){
Material material = face.material;
indeciesBuffer.put((int) (face.vertex.x - 1)).put((int) (face.vertex.y - 1)).put((int) (face.vertex.z - 1));
x = (int) face.vertex.x - 1;
Vector3f v1 = vertices.get((int) face.vertex.x - 1);
Vector3f n1 = normals.get((int) face.normal.x - 1);
Vector2f t1 = texture.get((int) face.texture.x - 1);
buffer[e*x] = v1.x;
buffer[e*x+1] = v1.y;
buffer[e*x+2] = v1.z;
buffer[e*x+3] = n1.x;
buffer[e*x+4] = n1.y;
buffer[e*x+5] = n1.z;
buffer[e*x+6] = material.getDiffuse().x;
buffer[e*x+7] = material.getDiffuse().y;
buffer[e*x+8] = material.getDiffuse().z;
buffer[e*x+9] = t1.x;
buffer[e*x+10] = 1-t1.y;
x = (int) face.vertex.y - 1;
Vector3f v2 = vertices.get((int) face.vertex.y - 1);
Vector3f n2 = normals.get((int) face.normal.y - 1);
Vector2f t2 = texture.get((int) face.texture.y - 1);
buffer[e*x] = v2.x;
buffer[e*x+1] = v2.y;
buffer[e*x+2] = v2.z;
buffer[e*x+3] = n2.x;
buffer[e*x+4] = n2.y;
buffer[e*x+5] = n2.z;
buffer[e*x+6] = material.getDiffuse().x;
buffer[e*x+7] = material.getDiffuse().y;
buffer[e*x+8] = material.getDiffuse().z;
buffer[e*x+9] = t2.x;
buffer[e*x+10] = 1 - t2.y;
x = (int) face.vertex.z -1;
Vector3f v3 = vertices.get((int) face.vertex.z - 1);
Vector3f n3 = normals.get((int) face.normal.z - 1);
Vector2f t3 = texture.get((int) face.texture.z - 1);
buffer[e*x] = v3.x;
buffer[e*x+1] = v3.y;
buffer[e*x+2] = v3.z;
buffer[e*x+3] = n3.x;
buffer[e*x+4] = n3.y;
buffer[e*x+5] = n3.z;
buffer[e*x+6] = material.getDiffuse().x;
buffer[e*x+7] = material.getDiffuse().y;
buffer[e*x+8] = material.getDiffuse().z;
buffer[e*x+9] = t3.x;
buffer[e*x+10] = 1 - t3.y;
}
koht.add(indeciesBuffer.position());
}
vertexBuffer.put(buffer);
indeciesBuffer.rewind();
vertexBuffer.rewind();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndeciesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indeciesBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexID);
glBufferData(GL_ARRAY_BUFFER, vertexBuffer , GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}