Hello,
so, I am currently writing a Processing port for C++ which should be focused on Performance. So I use OpenGL and noticed something (for me atleast) interesting, let’s take a look at this example code I wrote for this (normal Processing):
class Button {
float x, y, w, h;
boolean isPressed;
Button(float x_, float y_, float w_, float h_) {
x = x_;
y = y_;
w = w_;
h = h_;
}
void display() {
rectMode(CORNER);
noStroke();
if (!isPressed) {
fill(0);
} else {
fill(245, 132, 62);
}
rect(x, y, w, h);
fill(235, 122, 52);
rect(x+h/10, y+h/10, w-h/5, (h*8)/10);
}
}
Button button;
void setup() {
size(600, 400);
button = new Button(width/2 - 100, height/2-20, 200, 50);
}
void draw() {
background(127);
button.display();
}
void mousePressed() {
button.isPressed = true;
}
void mouseReleased() {
button.isPressed = false;
}
In this case Performance doesn’t really matter, but if you have 1000 buttons, it might do. And the thing here is, why does Processing force me here to redraw all the time? That would every time open a vertex buffer, display it, and destroy it, or not? Or is there a special hidden class I didn’t know about, which allows me to hold a vertex buffer in my class? I am specifically asking, because that’s the way I implement the rect() function right now in my libary: It makes a vertex buffer, displays it, and destroys it.