I'm trying to figure out how to load an obj file into my program. I've been playing with this idea for a couple of hours now, and the only solution i have is to write custom routines to read the obj file and encapsulate the vertex data (v xval yval zval) and the normals (vn xnorm ynorm znorm) between a glBegin(); glEnd(); pair...

This doesnt even render correctly in GL_LINE_LOOP mode, so I have to perform another hack by reading 3 triplets of vertex coordinates(provided all mesh elements are triangles) and placing them between an glBegin(GL_LINE_LOOP); glEnd(); pair...

If this sounds right it isnt because i have to detatch ALL of the faces (triangles) of the whole model before exporting to obj... that way i can guarantee that the model will be drawn correctly using glBegin(GL_TRIANGLES);

this isn't what I want, it isn't covenient and its a big optimization issue as well...

How can I load an obj file without having to detatch the faces and perform hacks????

As far as I understand it won't work (using whole undetached mesh) with GL_TRIANGLE,GL_TRIANGLE_STRIP or other enumerated constants because normally a model is built (by an artist) in an order that doesnt have any relation to the order in which vertices are and should be connected.

e.g. an edge is added halfway between the two border edges (taking a quad plane for examplpe), so the two vertices of the new edge come last after the previous model state...

there must be a way of organizing vertices into a logical and sequential order. i just don't know enough about geometry to know how...

http://www.forumsigs.com/users/sys0p763//untitled.jpg

the left part is all messed up because the mesh had not been separated into individual triangles, unlike the two rightmost images which are rendered correctly... (please note the model is (c) mario ucci aka loganarts).

I hope someone can help me!!!! please!!! hehe!

cheers!!!

Mikkel Gjoel

07-11-2005, 05:46 AM

The easiest way to read obj to gl, is to read the .obj-file into an obj-specific datastructure, and later translate this to the format you need.

The fool-proof method is to just draw everything as GL_POLYGON, the way you do. I'm not really sure what you mean by detach, but when reading triangles from obj, they are ordered in an indexed faceset. This means that positions, normals and texture-coordinates are shared in a vertex - but only IF they are continuous across a vertex. So if, for example, you have hard edges (discontinuous normals), you need to take care of the split edges when drawing the object.

There is quite a nice .obj-specification at
http://astronomy.swin.edu.au/~pbourke/geomformats/obj/

kind regards,

richie

07-14-2005, 01:36 AM

hey!
thanks for the reply! i did try GL_POLYGON... maybe ill go home and recheck.

by detaching everything i meant i detached each individual triangle.... pretty silly, but anyway!