why does clip not behave as expected?
as my clip seems to be rotating the entire boarder instead of the contents inside of the border
clipping to GRAPHICS 400 400 200 200
clipping to WINDOW 3 20 194 177
clipping to WINDOW FINAL 403 420 594 577
even tho i have, for example
graphics.clip(x,y,width,height);
clearScreen();
drawBorders();
graphics.clip(x+window.x, y+window.y, x+window.width, y+window.height);
// this should ONLY be affecting the clipped region
graphics.lights();
graphics.background(0);
graphics.noStroke();
graphics.translate(width/2, height/2);
graphics.rotateX(frameCount/100.0);
graphics.rotateY(frameCount/200.0);
graphics.box(40);
this my expected display result
this expected result is achieved by using a single PGraphics object per window, unfortunately this produces scalable overhead: the FPS drops more as the number of windows increases due to beginDraw()
and endDraw()
being called 60 times per second for each window being displayed
for instance, with 5 windows i get 31 to 39 FPS, for 16 windows i get 11 FPS
this is my application
Compositor compositor;
void settings() {
fullScreen(P3D); // 60 fps
//size(400, 400, P3D); // 60 fps
}
class Applications_Cube extends Window {
@Override
void draw() {
graphics.lights();
graphics.background(0);
graphics.noStroke();
graphics.translate(width/2, height/2);
graphics.rotateX(frameCount/100.0);
graphics.rotateY(frameCount/200.0);
graphics.box(40);
}
}
void addApplications() {
compositor.add(new Applications_Cube(), 200, 200);
compositor.setLocation(0, 0);
compositor.add(new Applications_Cube(), 200, 200);
compositor.setLocation(0, 200);
compositor.add(new Applications_Cube(), 200, 200);
compositor.setLocation(200, 0);
compositor.add(new Applications_Cube(), 200, 200);
compositor.setLocation(200, 200);
compositor.add(new Applications_Cube(), 200, 200);
compositor.setLocation(400, 400);
}
void setup() {
compositor = new Compositor(width, height);
compositor.displayFPS = true;
addApplications();
compositor.setup();
}
void draw() {
compositor.draw();
}
class Compositor {
public PGraphics graphics;
ArrayList<WindowObject> windows = new ArrayList<WindowObject>();
WindowObject w;
int windowFocus = -1;
int lastWindowFocus = -1;
boolean displayFPS = false;
Compositor(int width, int height) {
graphics = createGraphics(width, height, P3D);
}
void add(Window window, int width, int height) {
w = new WindowObject(width, height);
windows.add(w);
w.attach(window);
}
void setLocation(int x, int y) {
w.x = x;
w.y = y;
}
void setup() {
graphics.beginDraw();
for (WindowObject window : windows) {
graphics.clip(0,0,width,height);
graphics.clip(window.x, window.y, window.width, window.height);
window.graphics = graphics;
window.setup();
graphics.clip(0,0,width,height);
}
if (displayFPS) {
int oldColor = graphics.fillColor;
graphics.fill(255);
graphics.textSize(16);
graphics.text("FPS: " + frameRate, 10, 20);
graphics.fill(oldColor);
}
graphics.endDraw();
image(graphics, 0, 0, width, height);
}
void draw() {
graphics.beginDraw();
graphics.background(0);
for (WindowObject window : windows) {
graphics.clip(0,0,width,height);
graphics.clip(window.x, window.y, window.width, window.height);
window.graphics = graphics;
window.draw();
graphics.clip(0,0,width,height);
}
if (displayFPS) {
int oldColor = graphics.fillColor;
graphics.fill(255);
graphics.textSize(16);
graphics.text("FPS: " + frameRate, 10, 20);
graphics.fill(oldColor);
}
graphics.endDraw();
image(graphics, 0, 0, width, height);
}
}
class Window {
public PGraphics graphics = null;
int height;
int width;
int x, y;
int mouseX, mouseY;
Window() {
} // implicit super constructor required
void onBeforeResize() {
}
String onRequestType() {
return P3D;
}
void onAfterResize() {
}
void setup() {
graphics.background(0);
}
void draw() {
graphics.background(0);
}
}
class WindowObject {
public PGraphics graphics;
Window window;
int height;
int width;
int x;
int y;
int borderTop = 20;
int borderLeft = 3;
int borderBottom = 3;
int borderRight = 3;
WindowObject() {
} // implicit super constructor required
WindowObject(int width, int height) {
this.width = width;
this.height = height;
}
void attach(Window window) {
this.window = window;
this.window.x = borderLeft;
this.window.width = width-borderLeft-borderRight;
this.window.y = borderTop;
this.window.height = height-borderTop-borderBottom;
}
void clearScreen() {
graphics.background(0);
}
void drawBordersWithFill(int fill__) {
graphics.rectMode(CORNER);
graphics.stroke(0);
graphics.fill(fill__);
graphics.rect(0, 0, width, height, 10);
}
void drawBorders() {
drawBordersWithFill(87);
}
void setup() {
graphics.clip(x,y,width,height);
clearScreen();
drawBorders();
graphics.clip(x+window.x, y+window.y, x+window.width, y+window.height);
window.graphics = graphics;
window.setup();
graphics.clip(x,y,width,height);
}
void draw() {
graphics.clip(x,y,width,height);
clearScreen();
drawBorders();
graphics.clip(x+window.x, y+window.y, x+window.width, y+window.height);
// this should ONLY be affecting the clipped region
graphics.lights();
graphics.background(0);
graphics.noStroke();
graphics.translate(width/2, height/2);
graphics.rotateX(frameCount/100.0);
graphics.rotateY(frameCount/200.0);
graphics.box(40);
}
}