xenomorph05 at October 23rd, 2009 23:47 — #1
I have been surfing the corners of the internet for code to load and view md2, 3ds, obj files in a simple OpenGL program but I have run into issues with all of them.
I have been trying to learn from the VideoTutorialRocks website but I find it doesn't teach everything I think I need to know. I don't like Nehe because they use glaux...
I want to learn from scratch how to build my own 3D model loader, texture loader and viewers but I do not know how I should attempt to do this. I do know that I need information about the file types I want to use but beyond that and trying to code it is puzzling me. I do think it is beyond my current c++ level but I need to learn somehow.
Also right now I am using VS C++ 2008 EE but I will be trying to do my programming on the new Ubuntu 9.10 so I want to keep my code multi-platform compatible as much as possible.
Thanks a lot for taking the time to read this and for any help you provide! I really want to develop FOSS but I need to get the skills first.
fireside at October 24th, 2009 00:10 — #2
A good one to start with is an object file: .obj. It's a text file so you can open it up and it's almost self explanatory showing faces and vertices, etc. Just download Blender and save a cube in obj format. It will be easy to tell whats going on since it's only a cube. Then texture it and work on applying the texture. BTW, don't try an md2 in Blender because it messes up the format. If you go to the bottom of the page on Nehe's tutorials there are examples saved in all kinds of formats, etc. There should be one without glaux. Anyway, you can just insert the opengl code in any of them. You could also look at the Irrlicht source code. It runs in opengl and has a lot of model loaders in it. Someone on the irrlicht site will probably help you locate it if you can't find it. For animated models there's also Cal3d. It's opensource and has a model viewer that comes with it. It's a huge amount of work doing a skeletal animated model loader so you might want to think about using someone else's code at that point like Cal3d or a DirectX loader or something. There are some md2 loader tutorials on the net for opengl, though, that aren't too bad.
poita at October 24th, 2009 00:39 — #3
If you're wondering how to parse a file, do a Google search for recursive decent parser, or packrat parsers. Those are fairly simply to use, and fairly standard too.
Is there any particular part of the problem where you are getting stuck?
v71 at October 24th, 2009 04:49 — #4
I think i can help you since i wrote such kind of application but posting the code in a forum would be useless, contact me if you want details or
source code fragments, i am also improving and adding details to my model loader / optimizer.
May i give you and advice ? first of all build a robust mesh data structure to hold the 'parsed' file data , then you can specialize ( sp ?? ) when you have to load different file formats, same story for textures, many models include bmp or jpg texturs, so you need to add different image loaders for every different model.
xenomorph05 at October 24th, 2009 13:53 — #5
Thanks for the replies and I will try to attempt the things you guys have suggested but it will take me a day or two to check it all out.
poita: The main issue I have had while trying to use any of the sample code for importing models and textures is - LNK2019.
error LNK2019: unresolved external symbol "int __cdecl LoadBitmap(char *)" (<?LoadBitmap@@YAHPAD@Z>) referenced in function "public: void __thiscall Game::init(void)" (<?init@Game@@QAEXXZ>) Game.obj
fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\Luke\Desktop\Class_openGL_3dsbmp\Debug\Class_openGL.exe 1
These errors happen with my obj, md2 and attempt to us 3ds. If you want to see my code I can try to send it to you in a bit.
vilem_otte at October 25th, 2009 10:59 — #6
Looks like you forgot to include some headers ...
poita at October 25th, 2009 11:25 — #7
Lack of header files doesn't cause linker errors. Linker errors are caused by lack of linking.
Is LoadBitmap a windows function? You'll need to link the windows PSDK if it isn't done automatically (which I know VC++ Express didn't do at some point).
fireside at October 25th, 2009 13:33 — #8
Probably the examples that you are using have a dependency to some type of image library that isn't linked. Go to wherever you downloaded and see if there are any dependencies listed.
xenomorph05 at October 27th, 2009 14:09 — #9
Thanks for the ideas and tips! I decided to rebuild the project and for what ever reason I didn't get the same problems. I guess I posted before I played with it enough. I'll make sure to have tried everything next time. The loading I have working is an obj and blender obj export works just fine with it.
xenomorph05 at November 2nd, 2009 22:08 — #10
I was working with Visual Studio 2008 on Windows but I am now switching to using NetBeans for my C++ openGL programming. I have tried all of the obj loaders I found but they have to much Windows dependent includes.
edit: I didn't realize I had to include memory.h lol so I now have my obj loader working with netbeans on Ubuntu. Does anyone know how animating works with c++ and obj files?
rogerdv at November 3rd, 2009 13:48 — #11
Animation does not "works" with C++. You have to study abot animation types (keyframe, skeletal) and see what method uses the file format you are loading. It takes some heavy maths.
reedbeta at November 3rd, 2009 14:30 — #12
The OBJ format doesn't support animations anyway.
xenomorph05 at November 3rd, 2009 21:25 — #13
is it similar to how md2 animates?
jarkkol at November 4th, 2009 02:28 — #14
Writing mesh loaders for various formats is quite a lot of work. I have written loaders for 3ds, lwo, obj and dae (Collada), which's around 3000 lines of code total using comprehensive infrastructure, and I don't claim they are complete either (: Generally the loading is split into two phases: 1) parsing the data to data structures which closely resemble the file format, and 2) generating the GPU friendly data from that data to platform agnostic data structure (mainly means triangulation, proper vertex duplication and normal/tangent/binormal generation for lighting). Once the data is loaded to the platform agnostic data structure, it's quite trivial to generate OpenGL/D3D version of it.
For loading skeletal animation data, it's also a lot of work. I'm in the finishing phases of writing a Collada animation loader and that's around 1000 lines of code alone. However, plain animation sequence loader is pretty poor system alone and you need few other components for comprehensive skeletal animation system.
xenomorph05 at November 4th, 2009 07:42 — #15
What should I do to animate my obj models? I read about cal3D in another thread on this site.
jarkkol at November 4th, 2009 08:02 — #16
You can't animate obj models like Reedbeta said. The format has no skinning or bone information.
Edit: Just for clarification, I mean obj format doesn't support skeletal animation for characters. You can of course animate rigid body objects with physics for example.
xenomorph05 at November 4th, 2009 09:15 — #17
I understand that the obj does not hold animation information so I was trying to ask how do I animate the obj model?
I can rig the model in a 3D program but how can I make use of that? Do I need to load the bones as parent/child 3D models inside the obj character model to make it animate?
jarkkol at November 4th, 2009 10:15 — #18
You don't (: OBJ format doesn't contain needed information to be animated, so you need to use a format that does (like Collada). What you need is the bone hierarchy (skeleton) stored into the mesh file and information about the bone influences to the mesh vertices. OBJ format doesn't support this information thus it's not suitable for character animation. Collada can hold both skinning info/skeleton and animations.
xenomorph05 at November 4th, 2009 10:36 — #19
I'm checking out Google results for Collada. I see it is compatible with Blender. I presume I use a Collada file rather then an obj.
What other model file formats support animations? or should I just Google that too? I want to make sure that this is all OpenGL and Blender compatible too.
xenomorph05 at November 4th, 2009 10:46 — #20
I found that Blender exports to Collada 1.4 .dae files. This is great if I can use this for animating, texture and my model.
I have a new issue. I have to get a new model loader for .dae now.
next page →