OpenGL Graphic Formats and Conversion

By Judy Hartley (Intel) (12 posts) on August 18, 2009 at 10:49 am

I’m back again to share with you some of the things I am working on currently. If you’ve been following, you know that I have started a project to convert a DirectX interactive demo over to OpenGL. My first blog about this subject is Threaded Graphics to MID - a New Journey. This blog talks about the project plan and the different phases I expect to go through. The second blog, From DirectX to OpenGL - Wheels up, talks about the differences between DirectX and OpenGL and the compromises I’ve had to make so far. It also mentions some of the OpenGL tools and libraries I’ve found.

At this point I have a menu bar that works fairly well and I’m able to load the background sky and parts of the terrain. The way I’ve been doing this is to take the DirectX object files (.x files) and use my own Perl script to convert them into .obj files. I am able to get this to work, but some of the files I have converted have issues when they are drawn in the window. If I load the .obj file into a mesh processing program (such as Blender or MeshLab ) it displays just fine. Take a look at this bug object in MeshLab:

Bug object in MeshLab

Bug Object in MeshLab

Now, after loading it into the OpenGL window, take a look at the object. Yes, the texture shown is not actually for this bug object. Try to look beyond the texture. See the incorrect rendering?

Object Rendered in OpenGL Window

Object Rendered in OpenGL Window

Yes, the legs on one side of the bug do not connect the way they should. This is the same .obj file, but for some odd reason, it has trouble rendering correctly in the OpenGL window. I have the correct object for the material, by the way. It loads just fine in MeshLab and, with the debugger attached, it displays fine in the window as well. Pretty gruesome bug, isn't it?:

A Different Bug Object in MeshLab

A Different Bug Object in MeshLab

Second Bug Rendered in OpenGL Window

Bug Rendered in OpenGL Window

But if you run the application without debugging (staying with the debug configuration), the application won’t display at all. So, is it my conversion script? Or something I am doing when I draw the objects? I’m not sure yet. If you have an idea, let me know.

I don’t know if this is standard practice with .x files or not, but the .x files I have include a few or many different objects in each one. For instance, I have a castle.x file which has 493 different objects included in that one file. I modified my conversion script to put each object into its own file, just so I could see each item individually. Found some interesting surprises during this process. Check out object number 263 below:

Surprise Object in .X File

Surprise Object in .X File

Just recently I talked with another engineer here who had done a lot of work with OpenGL just last winter. He suggested that rather than going to .obj files, I should create Collada files. Blender will import a .x file and you can export that object into a .dae file, which is the extension for Collada files. If you download Collada, there are several examples included along with both a dll producing project and a static library producing project. One of the samples is a "rubber ducky" complete with texture file. I can load this file into MeshLab and it adds the texture to the object. So now I'm trying to figure out how to insert a material into a Collada file so that it will load the texture as well. There are two different Collada based c++ APIs for loading and saving Collada files; Collada DOM and FCollada. I chose the Collada DOM API. If you want to use the Collada DOM, you have to pay special attention to the instructions on the site about compiling and setting up your links in the project properties and don't do what I unintentionally did at first and try to connect both the static library and the dll library. After a great deal of work, I was able to get one of the samples to load successfully. I haven’t managed to actually display it in the window yet, but I’m working on it now.

The same engineer who suggested Collada files also thought that eventually I would need to use VBOs (Vertex Buffer Objects) to hold all of the objects I will be drawing in the window. I can see already that my code is going to need to load lots of different objects to make up the castle, all of its blocks, the bugs, the cannon and finally the cannonballs. I’m not sure how that’s all going to come together, but I’m certain that I’ll figure out a way. Well, that’s all for right now. I’ll write again in a couple of weeks and let you know what progress I’ve made.

Categories: Gaming, Open Source, Software Engineering, Uncategorized, Visual Computing

Comments (1)

August 19, 2009 4:07 AM PDT


Sebastian
there is native (not Python based) support for COLLADA files available in the upcoming Blender 2.50 branch. Take a look at http://www.graphicall.org/builds/ for the latest builds and http://sf.net/projects/opencollada for another SAX based parser for COLLADA files.

Happy coding,
Sebastian

Trackbacks (12)


Leave a comment  

To obtain technical support, please go to Software Support.
Name (required)*

Email (required; will not be displayed on this page)*

Your URL (optional)


Comment*