Filled ofPolyLine

I can’t seems to get an ofPolyLine instance drawn as a filled shape, what’s the correct or smartest way of doing it?

use ofPath instead, most of the times to draw a filled shape you need to tessellate it first, with ofPath the whole process is transparent and you can also get the tessellation as an ofMesh

thanks Arturo, as I found the getSmoothed() method of ofPolyline quite handy, I built a polyline from a vector of vertices, smoothed and then pass the smoothed vertices to an ofPath for tessellation and rendering. It sounds quite tricky and I’m sure it can be done in a wiser and more effective way, but it worked for me. thank you for the advice

mmh, yeah didn’t thought of that, ofPath is meant to be used also for vectorial information where smoothing or simplifying doesn’t really make sense but then when rendering to openGL (as opposed to for example PDF) it makes total sense to be able to smooth or simplify the shapes. Right now the way you are doing it is the only way, will look into how those methods could be accessible directly from ofPath

1 Like

Would using ofTesselate be a good option? It seems to work:

// #include "ofTessellator.h"

// create random test polyline
for(int i = 0; i < 20; i++) {
    float a = ofMap(i, 0, 20, 0, static_cast<float>(TWO_PI));
    float r = 100 + 50 * sin(a * 4);
        500 + r * cos(a),
        200 + r * sin(a));
// close it and smooth it
thePoly = thePoly.getResampledBySpacing(5);
thePoly = thePoly.getSmoothed(4);

ofMesh theMesh;
ofTessellator tess;

// **** convert poly to mesh ****
tess.tessellateToMesh(thePoly, ofPolyWindingMode::OF_POLY_WINDING_ODD, theMesh, true);


1 Like

yeah that’s pretty much what ofPath does internally, you can do that manually or just pass the vertices of the smoothed polyline into an ofPath