Wednesday, May 2, 2018

Object Model Loader in C++ using OpenGL

There was demand from some students to have an object model loader in C++ and I was trying it since so many days.

The one I am posting is incomplete. It has some issues such as elephant and teddy not loaded properly.

As you can see when I plot each vertex in the object model it seems fine:




But when I draw the triangles It comes with holes.

As shown here:




The model must be incomplete or the program has some bugs, I am not sure what is going on. If anyone could point out the flaw its hugely welcome. On further probing I found that the error seems to be while parsing the input .OBJ file. Certain files have two white spaces between f and the vertex index and some files have an extra blank at the end of each line. I have worked with same files in JAVA and there because of robust string handling functions these minor hiccups do not arise.

Here is the code in C++.

2 comments:

  1. Hi There
    I am also working on the same code but with different obj file. Have you found the solution?

    ReplyDelete
    Replies
    1. Yes not the solution but the reason for the problem as mentioned above. When you are reading the obj file neglect the extra white spaces such as \0(end of string), \t(tab), \n(newline) or \b(blank) ... Try to solve it ...its possible. Everything cannot be spoon fed.

      Delete