Vector of vector < ofPoint > and other begginer stuff

Hello guys,
I come from Processing and I have some questions about openframeworks.
(any answer is welcome)

  1. Is there any alternative to set stroke weight for ofLine() with rounded corners ? I’ve read something about Glut hints but it was an old post.

  2. A simple circle doesn’t look very smooth when using ofCircle(), is that the default renderer? I’ve tried with ofEnableSmoothing() but it didn’t change…

  3. I’m trying to do an array of Arraylists < ofPoints >, I’ve read I should use the “vector” class.
    Maybe something like this?

vector < vector < ofPoint> > name(10);

My Processing code is like this, just in case,

int frames = 10;
ArrayList<PVector>[] a = (ArrayList<PVector>[])new ArrayList[frames]; //pmouse
ArrayList<PVector>[] b = (ArrayList<PVector>[])new ArrayList[frames]; //mouse

for (int i=0; i < frames; i++) {
      a[i] = new ArrayList<PVector>();
      b[i] = new ArrayList<PVector>();

void save(int frame, float x, float y, float px, float py) {
    a[frame].add( new PVector(px, py) );
    b[frame].add( new PVector(x, y) );
  1. look into the documentation for ofSetLineWidth() that might help you out there. You can set the line with there to a float pretty easily

  2. look into the documentation for ofSetCircleResolution(). OF doesn’t really draw circles as much as it draws triangles in a circular shape. This method tells it how any triangles to draw to make a circle the higher the number the smoother your circle. I find that setting it to 40 usually makes a circle look fine any circle with a radius 50 px or less.

  3. you can use an Array in OF if you have a set number of items in the array that will never change

in your .h file:

int numPoints = 10;
ofPoint points[numPoints];

in your .cpp

for (int i = 0; i<numPoints; i++){
    points[i] = ofPoint(x, y);

But using a vector will give you more flexibility this tutorial is basically amazing for helping you understand vectors

long story short

in your .h file

vector<ofPoint> points;

in your .cpp

points.push_back(ofPoint(x, y));

but you should really peep that tutorial. It cleared a lot of things up from me being a someone moving to OF from processing also.


a big thx !!
i’m reading that tutorial. it also mentions how to erase elements.

your example is very clear, although I particullary was thinking about an array of vectors< ofPoint >.

in .h

vector<vector<ofPoint>> indexes(10);

in .cpp

indexes[2].push_back(ofPoint(x, y)); //for example


in .h

vector<ofPoint> indexes[num];

in .cpp

indexes[2].push_back(ofPoint(x, y)); //for example

sure sure that should work. arrays are great for simple structures but honestly I have yet to build an app where using an array’s basic structure was that much faster than a vector’s more complex and more useful structure so its probably better to use a vector if u have the choice.

But if the array of vectors won’t change you might be able to get away with mixing the 2 like you did in your second example.

1 Like