View Full Version : Convert from .X or .OBJ to openGL in C++

02-12-2009, 11:25 PM
i have a model in 3d max and a sample model from Maya, and i would like to convert it to opengl code in C++
is there a possiblity to do that or no way at all and what do i need or is there a guide to do that
thank you

Rosario Leonardi
02-13-2009, 01:31 AM
a- Study the .X format
b- Study the .obj format
c- write a loader for .x file
d- write a writer for .obj file
Job done.

If you want the base things (vertex, normal and faces) both format are trivial and you can find loader and writer easily.

02-13-2009, 03:24 AM
The situation with OBJ is more simple, but there are some quirks you will need to handle. For example there were parts of objects with inverted faces.

The X format is more complicated. The Maya XExporter() MEL script isn't writing D3D compliant X files, but it is possible to make an importer specifically for that exporter.

I have importers for both the Maya OBJ and X exported models written in Java here:
http://code.google.com/p/vlengine/source.../ObjLoader.java (http://code.google.com/p/vlengine/source/browse/trunk/vle_cleanup/src/com/vlengine/resource/obj/ObjLoader.java)
http://code.google.com/p/vlengine/source.../x/XLoader.java (http://code.google.com/p/vlengine/source/browse/trunk/vle_cleanup/src/com/vlengine/resource/x/XLoader.java)

02-16-2009, 08:43 PM
FWIW there are a lot of solutions out there for loading .3DS files.

Working with various formats over the years I have looked at this many times, and much as I hate the .3DS format virtually everything will export to it...

Most times if you look at the data you can see that all of it is there but often things like the rotation is wrong, or the UV coordinates are swapped in V when you put it through most import and export processes to get it to .3DS.

Luckily these things are generally easy to solve by swapping, rotating, or otherwise altering the data with a modified .3DS loader.

For this reason to date I have found the path of least resistance is to get things to .3DS and then import into projects from there with a small text header file which details the model to be loaded and any alterations to be made to it by your loader.

Just my 2c. :)

02-17-2009, 01:55 PM
Also the free Autodesk FBX SDK has tools for importing/exporting all their various formats in addition to Collada dae. You can use it to load and traverse a model's data, neatly and conveniently bypassing the rigmarole of proprietary format specifics.

Not much help with the 'X' format I'm afraid.

10-11-2011, 05:34 AM
Here is an online script to convert an OBJ text file to C++/OpenGL source code :

10-11-2011, 09:55 AM
Take a look at Open Asset Import Library (http://assimp.sourceforge.net/). It looks like supports the file formats (http://assimp.sourceforge.net/main_features_formats.html) you need.

12-22-2011, 09:08 AM
Hi Tazeg,

After convert opengl file. how to run the program. any example.

12-26-2011, 03:36 AM
Hi Tazeg,

I have to convert obj to c++/opengl used by jeffproc.com resources, how to run convert code through visuals studio. any example program.


01-19-2012, 06:15 AM
I did it.
Sample code for visual C++ available on :

NB : it is based on NeHe's lesson 06