OBJ Loader

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

OBJ Loader

Post by like80ninjas »

Okay, I'm looking for someone to help me write a simple obj loader in c++. I have been scouring the interwebs searching for something, but I have either had errors compiling or the ones I did get to work correctly just had too many features I didn't need. ( For example GLM had a bunch of error handling that would shut down the program at the mere sight of a screw up ). So I went on to attempt to write my own, which failed miserably. All I want to be able to do is load .obj models, while being able to load their textures and materials into a model class, where each instance of the model class would account for a mesh and material/texture.
User avatar
cypher1554R
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1124
Joined: Sun Jun 22, 2008 5:06 pm

Re: OBJ Loader

Post by cypher1554R »

What are you using to render them with?

If you're using DirectX, there is a good example in the SDK examples folder.
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: OBJ Loader

Post by like80ninjas »

Sorry, it's c++ and opengl.
User avatar
Boogy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Sun Mar 06, 2011 3:59 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Breda, The Netherlands
Contact:

Re: OBJ Loader

Post by Boogy »

Have you checked Wikipedia?
The OBJ format isn't that hard to understand.

If you want I can make a small tutorial on how to easily load an .obj file.
Student @ IGAD
Image
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: OBJ Loader

Post by like80ninjas »

Yes, I have. As I mentioned in the original post, I attempted to create my own by parsing the file but it failed. I think it failed somewhere near the actual putting together of the polygons(triangles). Yes it would help to have a tutorial.
User avatar
Boogy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Sun Mar 06, 2011 3:59 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Breda, The Netherlands
Contact:

Re: OBJ Loader

Post by Boogy »

like80ninjas wrote:Yes, I have. As I mentioned in the original post, I attempted to create my own by parsing the file but it failed. I think it failed somewhere near the actual putting together of the polygons(triangles). Yes it would help to have a tutorial.
If I have some spare time tomorrow I might put together a small tutorial. :)

The faces are defined with index numbers

Code: Select all

f 4 2 6
The first vertex of the polygon points to the fourth element in the vertex list. (these start with v)
The second vertex points to the second index in the vertex list and the third vertex points to the sixth element in the vertex list.

Note: OBJ starts counting arrays from 1 and not 0 so in c++ you have to subtract one from the index numbers.
Student @ IGAD
Image
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: OBJ Loader

Post by like80ninjas »

I knew about the way f v v v works, but I didn't know that it starts from 1 instead of 0. A tutorial would be great help!
User avatar
gamenovice
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 78
Joined: Fri Nov 12, 2010 7:49 pm
Current Project: wii u dev, sdl, and some unity 3D
Favorite Gaming Platforms: PC, GAMEBOY, GAMECUBE, WII, 3DS,PS2
Programming Language of Choice: C#,C++,Java
Location: Tampa,FL
Contact:

Re: OBJ Loader

Post by gamenovice »

I would also likea tutorial on obj :D
without code, we wouldnt have life as we know it...
User avatar
Boogy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Sun Mar 06, 2011 3:59 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Breda, The Netherlands
Contact:

Re: OBJ Loader

Post by Boogy »

gamenovice wrote:I would also likea tutorial on obj :D
I'll get started then :P
Student @ IGAD
Image
User avatar
Boogy
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Sun Mar 06, 2011 3:59 pm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: Breda, The Netherlands
Contact:

Re: OBJ Loader

Post by Boogy »

Boogy wrote:
gamenovice wrote:I would also likea tutorial on obj :D
I'll get started then :P
I have finished writing a small obj loader in c++ together with OpenGL. :)
Now I only need to explain how it works :roll:
Student @ IGAD
Image
User avatar
Zer0XoL
ES Beta Backer
ES Beta Backer
Posts: 54
Joined: Fri Apr 24, 2009 1:18 pm
Current Project: Zelda untitled multiplayer game
Favorite Gaming Platforms: PC, GBA, N64
Programming Language of Choice: C++, Lua
Location: Sweden
Contact:

Re: OBJ Loader

Post by Zer0XoL »

Image
Im Blue
like80ninjas
Chaos Rift Regular
Chaos Rift Regular
Posts: 101
Joined: Thu Dec 09, 2010 2:13 am

Re: OBJ Loader

Post by like80ninjas »

Thanks for the link, but like I said in the main post, I'm not interested in the amount overhead GLM uses. It was really annoying.
Post Reply