I’m trying to render something like the attached picture with OpenGL using GLUT instead of using Matlab. I have all the vertices in a float array, but I’m not sure what’s the best way of rendering the mesh. I’m thinking of using triangles or tetrahedrons for the elements in the cube, and a line for the blue line. Your opinions would be much appreciated. Thanks.
Tetrahedra aren’t OpenGL primitives, so you can’t use those. Triangles or triangle strips are probably the best way to go, depending on how you have the data. Lines would be good for the outline and the blue line.
My data looks something like this:
[x1 y1 z1 x2 y2 z2 … xn yn zn] for the box, and [a1 b1 c1 … am bm cm] for the blue line.
I’m sorry I wasn’t clear there, so I’ll take another go at it:
Each 3 elements specify a vertex, but triangles and triangle strips take the vertices in a different order and use them slightly differently.
Triangles take data (v1, v2, v3, v4, v5, v6, …) and makes a triangle out of v1,v2,v3, and v4,v5,v6, and so on, where vn is all three components of vertex n. Triangle strips would make a triangle with v1,v2,v3, then v2,v3,v4, and so on. (If you’re going to use those, check the order. I’m not sure that’s exactly right, and it makes sure that all the triangles face the same way.)
Depending on how your vertices are ordered in your array, it may be easier to use triangles or triangle strips.
Compiled display lists would be an efficient and simple way to render your data if it is static. The best way is to use vertex buffer objects or at least vertex arrays. You can find here a nice tutorial on vbos.