Drawing an OBJ from structs - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Drawing an OBJ from structs (/thread-1059.html)
Drawing an OBJ from structs - mikey - Jul 4, 2009 06:07 AM
OK, I've been working on an .OBJ Loader for a while now for my game in C. I ended up using Kamran Paaji's code as a template. I can't see why It's not working.
There is no errors according to GDB or Xcode's debugger. Nothing is drawn.
Drawing an OBJ from structs - Oddity007 - Jul 4, 2009 09:22 AM
How is it not working? Is it not loading, not drawing, etc. Printing out the data structures after loading and other info can help point to the problem. Do that and share the info you get. This will allow us to understand what is happening, and help you in turn.
I remember that I used that example. I found that:
Drawing an OBJ from structs - unknown - Jul 4, 2009 11:03 AM
You should not write:
Instead lets define:
and then we may write:
EDIT: I would also suggest that you may rather set the values vert1, vert2 and vert3 to be one less than read in, that lets you have:
Drawing an OBJ from structs - mikey - Jul 5, 2009 04:02 AM
Hello unknown and Oditty007.
If I change the code to:
It prints line is 0 ten times. This is strange. cube.obj goes like this:
So where does the ten come from? I think my problem is in loading the OBJ, but my code checks if it is NULL, so it's loaded something.
Drawing an OBJ from structs - Oddity007 - Jul 5, 2009 05:24 AM
Its printing out "line is 0" because you have printf("line is 0");
It wont increment on itself!
As to the problem, your loader was made for triangulated obj's. Your cube is in quads.
Even if it did load, it wont draw correctly.
And, 'v' is the first char of "vt" "v" and "vn" all totaling 10 times. Then it gets to the sscanf, and after ignoring the first char it gets to the second, and exits with 0, not copying anything and acting as if it did, messing up the v counts, drawing blank. Thats why I said to use:
Then f %i %i %i is what your code is looking for, f %i/%*i/%*i %i/%*i/%*i %i/%*i/%*i is what you need, but make a way to find all 3 variations.
Drawing an OBJ from structs - unknown - Jul 5, 2009 11:56 AM
C (or at least scanf) is the wrong approach for this problem.
Drawing an OBJ from structs - mikey - Jul 5, 2009 12:35 PM
Quote:C (or at least scanf) is the wrong approach for this problem.
Better ideas? While you're thinkin' Ill crack on.
Drawing an OBJ from structs - mikey - Jul 6, 2009 12:58 PM
Drawing an OBJ from structs - AnotherJake - Jul 6, 2009 06:46 PM
C and scanf work fine for this. Oddity007 has some great input.
mikey, I deliberately posted that obj cube a while back with quad sides since that would help encourage you to think about how the faces are constructed, since you'll want to at least support quads (in addition to triangles). So in this case you'll have to split each quad into two triangles. Do note that with obj's you might also encounter faces with more than four sides. You can either attempt to detect those and return an error, or ignore them I suppose, but just keep in mind that obj files are notoriously inconsistent in terms of sides and other random issues.
You're getting closer to being able to load obj files (especially now that you can load textures too), so keep at it! Again, be sure to carefully read this page, since it pretty much has all the info you'll need right now, and it's short. Try to draw out the cube obj file on graph paper if you have to to understand how the obj file is structured.
Drawing an OBJ from structs - ThemsAllTook - Jul 6, 2009 08:41 PM
AnotherJake Wrote:You can either attempt to detect those and return an error, or ignore them I suppose
Or automatically triangulate them at load time.
Drawing an OBJ from structs - AnotherJake - Jul 6, 2009 11:30 PM
ThemsAllTook Wrote:Or automatically triangulate them at load time.
Oh ya, sure, except that I don't want to allude to the next chapter where we explain how to use glutess
Drawing an OBJ from structs - mikey - Jul 7, 2009 03:24 AM
OK, I've taken Oddity007 (Thanks, BTW) advice and constructed this:
Yet still nothing is drawn.
"Laser Carbine" is an OBJ I had kicking around (It's all in triangles) but it's 3,000 lines plus, is this a problem?
My main 3D modeller (Art of Illusion) exports it's OBJ's as triangles, so do I have to include support for other polygons?
PS. It doesn't print line is 0 anymore.
Drawing an OBJ from structs - monteboyd - Jul 7, 2009 04:42 AM
I haven't had a good look through your code but you're only checking if fp != NULL, but not giving yourself a warning if it is NULL. So it could be that you file is not loading properly in the first place.
Drawing an OBJ from structs - mikey - Jul 7, 2009 05:00 AM
I don't think it's NULL. In my if (fp != NULL) block, i added an else statement, which does not print Error. Thanks anyway though.
Drawing an OBJ from structs - unknown - Jul 7, 2009 08:15 AM
why have 75? maybe that's too small