PDA

View Full Version : Loading and displaying raw triangle dump



trieder
07-06-2005, 07:09 PM
I decided to have a try at an OpenGL program. I used Dev-C++ to generate a Win32 shell for an OpenGL program and it compiled fine etc.

Next I took Blender (www.blender3d.org) and added a cone mesh to a blank scene, then I did File > Export > Raw Triangle. Now I have this Raw Triangle file that looks like so:

-0.000001 -0.000001 -1.414214 0.135953 0.027043 -1.407404 0.138616 0.000000 -1.407404

(this is one line of many).

Finally, I wrote some C++ code to parse the file. It takes each line and throws it into a vector<double>. I take the vector and use it like an array:

glColor3f(1.0, 0.0, 0.0);
glVertex3f(vf[0], vf[1], vf[2]);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(vf[3], vf[4], vf[5]);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(vf[6], vf[7], vf[8]);

When I render this I get tons of little triangles all over the screen. Any idea why it's not a cone? Also, how come the numbers are always very small?

jide
07-07-2005, 12:42 AM
If you use double inside your std::vector, then use double for gl function parameters (eg glVertex3d).

I cannot say more.

trieder
07-07-2005, 03:59 AM
I used double for everything because float wasn't precise enough for the numbers I was using.

I actually managed to somewhat fix it so it looks like an overhead of a cone (I changed GL_TRIANGLES to GL_POLYGON... GL_TRIANGLE_FAN and STRIP looked like they worked too), but when I rotate it, it still isn't quite right (it looks like a bunch of seperate triangles):

glPushMatrix();
glRotatef (theta, 1.0f, 0.0f, 0.0f);
glCallList(list);
glPopMatrix();

I would think you rotate and then display... is that wrong? I created my display list in a loop like so:

glColor3f(1.0, 0.0, 0.0);
glVertex3f(vf[0], vf[1], vf[2]);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(vf[3], vf[4], vf[5]);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(vf[6], vf[7], vf[8]);

Thanks for the reply.