code-section

[C++, DX9] Obj Loader Sample

March 24, 2014

This sample application loads an OBJ file and uses DirectX 9 to render it. The main focus is on reading OBJ meshes into an application, rather than rendering that mesh. Therefore, the important part in this sample is the obj loader, which is independent of directx, and resides in ObjLoader.h and ObjLoader.cpp files.

The sample (and consequently the obj loader) has been tested with many obj files exported from both Autodesk Maya and ZBrush, as well as obj files retrieved from the web. Unlike most other obj loaders you may find elsewhere, I'm pleased to say this loader has worked with all tested obj files!

The sample does not optimize the mesh for rendering; it does not use an index buffer. Instead, each triangle will get its own copy of any shared vertices. This is to simplify the code.

You are free to use this code however you want.

Download demo & src