[help] ofMesh and using indicies to define how it's drawn

Hi there,

I’m trying to draw to the screen a grid of vertices that are only connected horizontally with lines. I think that is something i would use indicies for, but I don’t exactly understand how they work in relation to defining the use of the primitives.

If some one could give me a quick and dirty run down on how index values work in ofMesh and maybe an example, that would really help me out.

Thanks!
~mike

You can actually render that just using myMesh.drawWireframe().

The indices setup which vertices are drawn in which order, which seems weird at first (or at least it did to me) but it’s actually not that hard to get when you understand that one of the things that 3D graphics programming does a lot is tries to reuse all the points as much as possible. So, you add some points to a mesh (which really just sit in an array) and then you need to tell the mesh what order you want those points drawn in and you do that by setting the indices, which are the indices of things in that array of vertices. A triangle is something like 0,1,2, (i.e. first, second, third vertices) and a square drawn with triangles is something like 0,1,2 and 2,1,3. This image might help: http://www.opengl-tutorial.org/wp-content/uploads/2011/05/indexing1.png

Anyways, long story short, just add your vertices, call mesh.setupIndicesAuto(), and then draw it with mesh.drawWireframe().

Thanks! That makes sense, I’ll try that.