Skip to content

Commit 06700ef

Browse files
committed
Implement PApplet::loadPixels() -- was declared but missing definition
1 parent f134340 commit 06700ef

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

src/Processing.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,9 +1000,40 @@ void PApplet::arc(float cx, float cy, float w, float h, float startAngle, float
10001000
drawEllipseGeom(cx, cy, rx, ry, startAngle, endAngle);
10011001
}
10021002

1003-
void PApplet::arc(float cx, float cy, float w, float h, float startAngle, float endAngle, int /*mode*/) {
1004-
// mode = OPEN / CHORD / PIE -- basic implementation uses OPEN
1005-
arc(cx, cy, w, h, startAngle, endAngle);
1003+
void PApplet::arc(float cx, float cy, float w, float h, float startAngle, float endAngle, int mode) {
1004+
float rx = w, ry = h;
1005+
resolveEllipse(cx, cy, rx, ry);
1006+
int steps = 64;
1007+
float da = (endAngle - startAngle) / steps;
1008+
// Fill
1009+
if (doFill) {
1010+
applyFill();
1011+
glBegin(GL_TRIANGLE_FAN);
1012+
if (mode == PIE) glVertex2f(cx, cy); // PIE: fan from center
1013+
else glVertex2f(cx + rx * ::std::cos(startAngle) * 0.5f,
1014+
cy + ry * ::std::sin(startAngle) * 0.5f); // CHORD/OPEN: fan from first point
1015+
for (int i = 0; i <= steps; i++) {
1016+
float a = startAngle + i * da;
1017+
glVertex2f(cx + rx * ::std::cos(a), cy + ry * ::std::sin(a));
1018+
}
1019+
if (mode == PIE) glVertex2f(cx, cy);
1020+
glEnd();
1021+
}
1022+
// Stroke
1023+
if (doStroke) {
1024+
applyStroke();
1025+
glBegin(GL_LINE_STRIP);
1026+
if (mode == PIE) { glVertex2f(cx, cy); }
1027+
for (int i = 0; i <= steps; i++) {
1028+
float a = startAngle + i * da;
1029+
glVertex2f(cx + rx * ::std::cos(a), cy + ry * ::std::sin(a));
1030+
}
1031+
if (mode == PIE) { glVertex2f(cx, cy); }
1032+
else if (mode == CHORD) { // close the chord line
1033+
glVertex2f(cx + rx * ::std::cos(startAngle), cy + ry * ::std::sin(startAngle));
1034+
}
1035+
glEnd();
1036+
}
10061037
}
10071038
void PApplet::rect(float x, float y, float w, float h) {
10081039
resolveRect(x, y, w, h);
@@ -2807,6 +2838,22 @@ void PApplet::filter(int mode, float param) {
28072838
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
28082839
#endif
28092840
}
2841+
void PApplet::loadPixels() {
2842+
// Copy framebuffer into pixels[]
2843+
int total = winWidth * winHeight;
2844+
pixels.resize(total);
2845+
::std::vector<unsigned char> buf(total * 4);
2846+
glReadPixels(0, 0, winWidth, winHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf.data());
2847+
// Convert RGBA + flip Y (GL is bottom-up, Processing is top-down)
2848+
for (int y = 0; y < winHeight; y++) {
2849+
for (int x = 0; x < winWidth; x++) {
2850+
int si = (winHeight - 1 - y) * winWidth + x;
2851+
int di = y * winWidth + x;
2852+
unsigned char r=buf[si*4],g=buf[si*4+1],b=buf[si*4+2],a=buf[si*4+3];
2853+
pixels[di] = (a<<24)|(r<<16)|(g<<8)|b;
2854+
}
2855+
}
2856+
}
28102857
void PApplet::updatePixels() {
28112858
int total = winWidth * winHeight;
28122859
::std::vector<unsigned char> rgba(total * 4);

0 commit comments

Comments
 (0)