Instead of mesh.draw()
, you can use the following functions:
mesh.drawWireframe()
function draws only surface edges without the interiors of the triangles. Such a mode of drawing is called wireframe drawing; it is very useful for debugging, and of course, can be used as an effect.mesh.drawVertices()
function draws only vertices of the mesh. It is useful for debugging and also as an effect.Also, to represent not only triangular surfaces but also objects consisting of line segments or points, use the mesh.setMode( mode )
function, where mode
has type ofPrimitiveMode
enumeration. To see all the possible values for mode
, check its definition. We will mention only three values:
Let's consider the last two modes in detail.
Calling mesh.setMode( OF_PRIMITIVE_LINES )
switches mesh
to a mode in which it draws line segments. After calling this function, add all vertices of segments using mesh.addVertex( p )
, and for each segment, it adds the indices of the vertices using the following code:
mesh.addIndex( i1 ); //Index of segment's first vertex mesh.addIndex( i2 ); //Index of segment's second vertex
For example, to draw a tripod, create the mesh using the following code:
mesh.setMode( OF_PRIMITIVE_LINES ); mesh.addVertex( ofPoint( 0, 0, 0 ) ); //Vertex 0 mesh.addVertex( ofPoint( -100, -100, 0 ) ); //Vertex 1 mesh.addVertex( ofPoint( 100, -100, 0 ) ); //Vertex 2 mesh.addVertex( ofPoint( 0, 100, 0 ) ); //Vertex 3 mesh.addIndex( 0 ); mesh.addIndex( 1 ); //Segment 0 mesh.addIndex( 0 ); mesh.addIndex( 2 ); //Segment 1 mesh.addIndex( 0 ); mesh.addIndex( 3 ); //Segment 2
Note that for correct lighting you need to specify normals, which normally cannot be defined for lines. So the best idea is to disable lighting using the ofDisableLighting()
function before drawing and then enabling it again using the ofEnableLighting()
function:
ofDisableLighting(); //Disable lighting mesh.draw(); //Draw lines ofEnableLighting(); //Enable lighting
Calling mesh.setMode( OF_PRIMITIVE_POINTS )
switches mesh
to a mode in which it draws its vertices as points.
Additionally, call glPointSize( size )
to specify point size in pixels, and call glEnable( GL_POINT_SMOOTH )
to draw circular points (instead of square points as on some graphics cards). For example, add the following lines after specifying tripod vertices in the previous example:
mesh.setMode( OF_PRIMITIVE_POINTS ); glPointSize( 10 ); glEnable( GL_POINT_SMOOTH );
Once you run the code, you will see four circles, corresponding to the tripod's vertices.