Day 1: I've created the most elegant and beautiful algorithm for the problem at hand. I am a genius.
Day 10: My elegance has been improved by fixing the corner cases while changing the least amount of code.
Day 24: I am off on new and exciting things, but I will always look upon this code with joy and a deep satisfaction.
Day 122: I am fighting a terrible bug, and some @%$#% @#$%^&& wrote this stupid... Oh wait. That's my code. WTF?!?!
vlj, it's not small. Problem with VSync is that you get either 60 FPS or 30 FPS (roughly speaking). While 60 FPS usually is fine, 30 FPS has unbearable input lag. I had to turn off VSync on Assassin's Creed Unity because of that (my FPS was roughly 50). Wouldn't even dare to play Action game with that kind of performance.
And that is 3 vertices in your vertex buffer. If you do same for 7 other vertices you'll have 24 unique vertex combinations. Adding color and texture coordinate won't increase number of vertices in this case.
So when you load file:
f 1/1/1 2/2/1 3/3/1
f 3/3/1 4/4/1 1/1/1
f 5/4/2 6/1/2 7/2/2
f 7/2/2 8/3/2 5/4/2
you need to track all unique combinations of faces, generate vertices from position, normal, texcoord indexes, and generate index buffer from these combinations.
Ex.: combination (1/1/1) will have index 0 ( vertices ), which mean you add to your index buffer value 0. If later on you encounter (1/1/1) again, you'll be adding value 0 again.
After trying to solve the problem for awhile, I can now see the mesh, however I see 2 triangles instead of a box (incomplete box)
I guess the problem is with the indices, I have 8 vertices, how do I calculate the indices for the box?
Inside ModelLoader.cpp you have:
// Read in the faces.
if(input == 'f')
if(input == ' ')
// Read the face data in backwards to convert it to a left hand system from right hand system.
fin >> faces[faceIndex].vIndex3 >> input2 >> faces[faceIndex].tIndex3 >> input2 >> faces[faceIndex].nIndex3
>> faces[faceIndex].vIndex2 >> input2 >> faces[faceIndex].tIndex2 >> input2 >> faces[faceIndex].nIndex2
>> faces[faceIndex].vIndex1 >> input2 >> faces[faceIndex].tIndex1 >> input2 >> faces[faceIndex].nIndex1;
Which assumes 3 vertices per face, aka. triangle, however in your .obj file:
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/4/2 6/1/2 7/2/2 8/3/2
f 1/4/3 4/1/3 6/2/3 5/3/3
f 4/4/4 3/1/4 7/2/4 6/3/4
f 3/4/5 2/1/5 8/2/5 7/3/5
f 2/4/6 1/1/6 5/2/6 8/3/6
# 6 polygons
each face (polygon) contains 4 vertices.
You have 2 choices here:
load correct number of vertices for each face / polygon and triangulate them;
when you export .obj file there should be an option to triangulate meshes / faces / polygons, use it to generate triangles instead of arbitrary polygons.