Start a new topic

Cannot load 3d object from obj format

Cannot load 3d object from obj format


Hi,

I am trying to load a 3d object from an obj file. I use tiny obj (https://github.com/syoyo/tinyobjloader) for obj file parsing, I only added the c++ header and call its methods. The data seems to be fine, but for some reason I don't get anything loaded inside opengl. I was able to load the cube that I have inside the source file but no success with a parsed obj file. I atached a link to the project. https://www.dropbox.com/s/5iu7p7isrkx16s5/vr.zip?dl=0

Any help would be apreciated.

Thanks,

Emil

Having a quick look at your renderer I found some flaws regarding the data types and the buffers you pass to OpenGL:

Replace

    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * shapes.mesh.positions.size(), (shapes.mesh.positions.data()), GL_STATIC_DRAW);

by

    glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned int) * shapes.mesh.positions.size(), (shapes.mesh.positions.data()), GL_STATIC_DRAW);

and

 

    glDrawElements(GL_TRIANGLES, (int)shapes.mesh.positions.size() / 3, GL_UNSIGNED_BYTE, 0);

by

 

    glDrawElements(GL_TRIANGLES, (int)shapes.mesh.positions.size() / 3, GL_UNSIGNED_INT, 0);

 

Since you are using an external renderer, the OpenGL rendering is basically up to you.
For further questions on rendering I would recommend an OpenGL forum or http://stackoverflow.com/  

Thank you very much! :)

I didn't know exactly if it was a wrong use of opengl or something else. 
Login or Signup to post a comment