Skip to main content
gamedev.net
🔒 Locked

OBJ reader...

Started by dilapper May 11, 2004 at 1:07 PM 2 replies 1.9k views
Original Post
dilapper
dilapper
Hi all, first post Im making myself an OBJ reader to read a model from Max (that ive exported to obj) into an opengl programme... Its not working tho unfortunately. Any ideas where on the net i can find one to, primarily, compare it to mine? If i cant get mine working i might just use one i can download, so if anyone knows a link to one that would be great. Cheers Dave
_walrus
_walrus
nate robin has an obj loader in his smooth normal generator (check out the glm files):

http://www.xmission.com/~nate/smooth.html


There''s one on gametutorials too:

http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm
Daaark
Daaark
I wrote a small class that will load an obj file and then draw it for you. (Assuming you have an existing OpenGl rendering context active).

Real easy to use. eg:

DLMODEL dlmModel;

dlmModel.LoadObj("filename.obj");
glBegin(GL_TRIANGLES)
dlmModel.Draw();
glEnd();

That will draw the model with the currently bound texture, or in whatever color you set. And then the destructor will deallocate it.

It''s very limited though. It assumes the obj file has only 1 object, and that the object is made up of triangles. I''ve seen some obj files that it will not read correctly, like stuff I exported from Wings3d. It will load the veritces, normals, texture UVs and face information only. I made it simply to preview some objects quickly, and I was learning to use fstream at the same time.

I can post the source if you want it. I''ll watch this thread over the next little while, and if you ask for it, I''ll post it.
_walrus
_walrus
There is a nice OBJ loader in the Java3D api (if you dont mind looking at java code). You should be able to get the source from it from the sun site. from what i remember it actually uses a lexical scaner to tokenize the file. It''s a bit of an overkill since obj files are so simple, but its a nice approach for a heavier format. Oh yeah its really slow too. but it just shows a different approach of doing it. The nate robin glm obj loader works great though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.