1

I created a house in Blender and exported it as a .obj file. I then used 3DWin to convert that into a scene.cpp. Im confused as to how I can import this data into my code to render the house though.

I have a mesh array now with my coordinates that looks like the following

static float mesh01_coords[] = {
50, 0.1, 50,
-50, 0.1, 50,
-50, 0.1, -50,
50, 0.1, -50,
...

Do i just loop through each array index setting a vertex at each point? such as:

glVertex3f(50, 0.1, 50);
glVertex3f(-50, 0.1, 50);
glVertex3f(-50, 0.1, -50);
glVertex3f(50, 0.1, -50);
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
thesentyclimate413
  • 89
  • 3
  • 4
  • 11
  • I don't know 3DWin, so I'm not sure what kind of cpp it generates. But why not write a simple OBJ loader yourself, generating a mesh you can render. It's not all that hard and you don't need to go through some converter. – Bart Dec 06 '11 at 08:21

2 Answers2

5

I then used 3DWin to convert that into a scene.cpp

There's no point in doing this. It will just bloat up your executable and if you make any change to the model you'll have to recompile your program.

Just read the OBJ file directly. Writing a parser for it is rather easy http://www.royriggs.com/obj.html

Im confused as to how I can import this data into my code to render the house though.

You model consists of a indexed list of vertices, and a list of faces, where each face is a tuple of indices into the vertices list. You can be rather lazy, load the list of vertices into a vertex array, and feed the index list to glDrawElements then, which will draw the vertices according to the face list.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • +1 on the answer, but FYI the link you inserted results in a malware warning on my system when I follow it. – Bart Dec 06 '11 at 09:04
  • @Bart: No idea where that malware warning would come from. The site is plain HTML, no scripts, no CSS. Probably the result of some overenthusiastic URL classifier. – datenwolf Dec 06 '11 at 10:25
2

First of all - OBJ specification. Now, you can either implement it yourself or use a library that will provide this functionality for you.

There's a sample in DirectX SDK called MeshFromOBJ; it's C++ based and as far as I remember provides good learnining experience. Basically all you need to do is to convert Direct3D calls (there are not that many of them) into OpenGL ones. There's also a thread on gamedev.net that might help.

Alternatively, find a library that will do it for you. Give google a try. One result I found was GLM.

Bart
  • 19,692
  • 7
  • 68
  • 77
gwiazdorrr
  • 6,181
  • 2
  • 27
  • 36