Skip to main content
GameDev.net gamedev.net
🔒 Locked

Loading .OBJ files in OGL

Started by biovenger Aug 9, 2003 at 2:15 AM 2 replies 350+ views
Original Post
biovenger
biovenger
Yeah, the topic should lead you on the right path, now for the question: I''m loading a triangularized model from an OBJ file. So far I load in the all the vertex data (v) into an array, then go through the faces and link the correct face (f) with the correct 3 vertex data posts in the vector. I pay no heed to texture vertex data (vt) nor do I care about smoothing groups since my impression was that they are not needed (the model isn''t textured). Also, I don''t care about the vertex normals either (vn) since someone said they only have to do something with lightninng anyway. Now, when I render it, I go from the first face (triangle) to the last, without any rotations and the like and the model onscreen ends up garbled as if all the triangles were only drawn in the middle of the screen. Now my question is: Since I don''t pay heed to the normals in the OBJ file (vn) should I? Is their absence what is making the error? Or is it something else I''ve done wrong? Also, be gentle in your reply, this is my very first attempt to code in 3D and I''ve just finished making a very basic OOP wrapper for OGL so I wanted to be able to try loading files as models instead.
-----------------------------Final Frontier Trader
MelvinElvin
MelvinElvin
normals are only used for lighting and not loading them will not garble the image in anyway. Make sure you know the format of the file you''re reading in, step over it with the debugger to make sure the data you''re loading in as vertex data are the expected values, and are linking to the faces as expected. That''s all the advice i can offer without seeing any code or a more specific defintion of how the image is "garbled".
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
biovenger
biovenger
All code is read in correctly, I''ve done serious debugging and made sure that all 64 faces are loaded in with correct vertex data.

You said linking the faces correctly, what did you mean by that exactly? For as it is now, the OBJ files (as you might know) define a face like this

f n1/n2/n3 n21/n22/n23 n31/n32/n33

where n#1 is the number of the vertex in the vertex list (earlier in the file, a vertex is shown by "v x y z" and the first vertex in the list is nr 1, next is number 2... to number n)
n#2 is the vertex texture coordinate and n#3 is the vertex geometric normal.

So all faces are linked correctly, I am positive of this.
-----------------------------Final Frontier Trader
biovenger
biovenger
Hah! Now I have proof that it is bad to code when tired!

I made just one big mistake... I assumed that the number of faces is the number of vertices / 3. What an idiot I am! Har har!

It works perfectly now!
-----------------------------Final Frontier Trader

Topic Locked

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

Sign in to reply to this topic.