Best practice for libraries that can draw on off-screen surfaces
in
Library and Tool Development
•
1 year ago
If I write a regular processing sketch, and I want to draw to an off-screen surface, I do something like:
- PGraphics pg = createSurface(bla, bla, bla);
- pg.line(10, 10, 100, 100);
But if I am using a library, or want to write my own library, that also should be able to draw to off screen surfaces, how would you go about do that?
I am not making a subclass of PGraphics, that is beyond what I am trying to accomplish.
Is it a viable solution to, in the constructor of the library class, have:
I am not making a subclass of PGraphics, that is beyond what I am trying to accomplish.
Is it a viable solution to, in the constructor of the library class, have:
- Library(PApplet parent, PGraphics g);
and then have a private pointer in my own library to point to "g", so that when I in my sketch write something like:
- myLibInstance.wigglyLine(10, 10, 100, 100);
the code in the library is something like:
- void wigglyLine(float x1, float y1, float x2, float y2)
- {
- // Not exaclty wiggly
- this.g.line(x1, y1, x2, y2);
- }
Or are there better suggestions?
1