Blender Models and OpenGL

Started by
2 comments, last by Matei 19 years, 8 months ago
I'm writing a game in OpenGL (Win32, C++) and I want to include some models that have been constructed in Blender. I have essentially no experience in this area. I have tried to find a good tutorial on this subject but have failed. Does anyone know of some Web site somewhere that would explain how this is done?
Advertisement
Hi!

You can create a plugin for blender using its python API. It's simple, and you can create an exporter for your model format very quickly.
You can also search in Google for an exporter for some format in particular. There are exporters for almost all formats.

Gretz,
Thanks, I had thought about using the Python API for that, but I didn't think it was actually possible. I also need something to show me how to load and draw a model in OpenGL.
There are exporters from Blender to various formats, including a few simple text formats. If you have Blender 2.34, you'll see a lot of these in the Export menu (they weren't bundled with earlier versions). You can download a few others on www.blender3d.com.

You can find tutorials on loading and displaying certain formats here.

Personally, though, I just ended up writing my own exporter in Python, to a very simple text format. I stared by modifying the AC3D script and the Wavefront OBJ script. My script is about 150 lines long and exports locations, normals, texture coordinates and bone names for each vertex, and materials and texture names for each face. The Python language is very simple, so it isn't hard at all to create your own script.

As for actually drawing the object, at the most basic level you just draw each triangle using glBegin(GL_TRIANGLE), glVertex3f, glNormal3f, etc. For a bit more speed, you can put your vertices into a vertex array, and the indices of the corners of each triangle in an index array, and then use glDrawElements. Also, if you have multiple materials and textures, group together vertices with the same material and texture so you switch states as little as possible.

This topic is closed to new replies.

Advertisement