We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, Im trying to use PGraphics to draw on a seperate "Layer". So far I understand the concept of using PGraphics as layers, but when I try to use a custom brush I can't get it to work on the layer ABOVE. In the example code I have here, the custom brush will only draw BELOW the layer that I want. I just started learning processing this week so im sure there are a few concepts that im not getting yet :P
Thanks allot guys.
//myPGraphics2
import processing.opengl.*;
ArrayList history = new ArrayList();
float distthresh = 60;
PGraphics pg;
void setup() {
size(200, 200, OPENGL);
pg = createGraphics(100, 100);//size of the layer
smooth();
hint(ENABLE_DEPTH_SORT);
}
void draw() {
pg.beginDraw();
pg.background(100);//background color AKA layer color
pg.stroke(255);
// pg.line(10, 10, mouseX, mouseY); //position of mouse VS line
pg.hint(DISABLE_DEPTH_TEST);
pg.hint(ENABLE_DEPTH_TEST);
pg.endDraw();
image(pg, 50, 50); //position of the layer
//image(pg, 51, 30);
}
//----------------FUNCTIONS------------------//
void mouseDragged() {
PVector d = new PVector(mouseX, mouseY, 0);
history.add(0, d);
for (int p=0; p<history.size (); p++) {
PVector v = (PVector) history.get(p);
float joinchance = p/history.size() + d.dist(v)/distthresh;
if (joinchance < random(0.4)) line(d.x, d.y, v.x, v.y);
}
}
void keyPressed() {
if (key == ' ') {
//background(255);
history.clear();
}
}
Answers
In order to affect a PGraphics, we gotta use its reference followed by the dot
.
operator:http://processing.org/reference/dot.html
Like this:
pg.line(d.x, d.y, v.x, v.y);
.When everything's finished, issue:
pg.endDraw();
.BtW, is there any particular reason to use OPENGL renderer in this case?
Anyways, I've done some tweaks, but no fix, to your code:
Thanks @GoToLoop, at least this gets me a step closer. No, theres no particular reason i'm using openGL, it just helps to render the brush. but if you know how to implement a simpler brush that would be much appreciated. Im just starting out so i'm just trying to build some basic functionality for what I need it to do. Which is basically using Processing to "draw over an image"
I've got this example below. Perhaps it might help ya:
An online example: http://studio.processingtogether.com/sp/pad/export/ro.9ZSvPnI4AVjwR/latest