drawSubsection as circle?

Hi everyone,

I am using drawSubsection to draw a piece of an image into a fbo. Does anyone know if it’s possible to use a circle instead of a rect (h,w) with drawSubsection?

Cheers.

I don’t think there is a function like that.
but I would suggest to make use of a mask to blend your image into the fbo as a circle. have a look at the blending example. there you will see how to draw an image as a circle. you can probably do something similar to your fbo.

you can also create a circle in an ofMesh for example creating the circle with an ofPath and then using ofPath::getTessellation(). Then add texture coordinates to the mesh and draw it in between bind() / unbind() of the image like:

img.bind();
circleMesh.draw();
img.unbind();

for the texture coordinates you can just copy the x,y from each vertex

1 Like

Hi Arturo

I had the same quesion and tried your solution.
I think I have done all the steps correctly, except adding the texture coordinates to the mesh.
Since the mesh is a circle I’m not sure how to do that.

here’s my code:

path.clear();
path.setColor(ofColor(0,0,0));
path.setFilled(true);
path.setStrokeWidth(1);
path.setCircleResolution(100);
path.circle(mouseX,mouseY,60);
path.close();

mesh=path.getTessellation();
ofSetColor(255,255,255);

image.bind();

//This is the part where I get stuck
mesh.addTexCoord( ...

mesh.draw();
image.unbind();

My confusion is how to get a circular texture coords from the image and feed it to the mesh.
Could you guide me?
Thanks

you can just copy x,y from each vertex as texture coordinates, then if you want to translate them just add the translation to each coordinate and if you want to scale them multiply by the scale factor

2 Likes

I finally managed to do it successfully! :blush:
I put my code here for anyone else looking for the same thing (it draws a circular subsection of the image centered at the mouse position) :

    int radius=100;
    ofMesh mesh;
    ofPath path;

    path.setCircleResolution(100);
    path.circle(mouseX,mouseY,radius);
    path.close();

    mesh=path.getTessellation();

    for (int i=0;i<mesh.getNumVertices();i++)
         mesh.addTexCoord(mesh.getVertex(i));
        
    image.bind();
    mesh.draw();
    image.unbind();
2 Likes