View Full Version : rendering triangles, tetrahedrons, and/or lines
03-07-2009, 07:01 PM
I'm trying to render something like the attached picture (http://imagebin.org/index.php?mode=image&id=40486) 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.
03-07-2009, 08:35 PM
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.
03-08-2009, 12:31 AM
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.
03-08-2009, 08:27 AM
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.
03-08-2009, 10:28 AM
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 (http://www.songho.ca/opengl/gl_vbo.html) a nice tutorial on vbos.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.