why can the PGraphics FrameBuffer be rendered when noLoop()
is given but fails to image when noLoop()
is not given?
as the following works for noLoop();
however it fails for looping draw() as the screen is always black
as in theory, in loop mode, this should give the exact same result as noLoop()
however it does not
however if i do this
(set noLoop() in setup, then set loop(); in draw)
boolean originallyLooping;
void setup() {
looping = false;
originallyLooping = looping;
}
void draw() {
if (!looping) looping = true;
if (originallyLooping) {
if (frameCount > 1) return;
} else {
if (frameCount > 2) return;
else if (frameCount == 2) try {
Thread.sleep(1000);
} catch (Throwable e) {
}
}
then i notice this on the second frame
why is this and how can i get the framebuffer to be drawn correctly on the second and subsequent frames?
it seems like the translation and other related things are not being reset upon drawing end, as if i do
DirectR g2;
void settings() {
// 23 FPS
//fullScreen(P3D);
// 60FPS
size(500, 500, P3D);
}
boolean originallyLooping;
void setup() {
background(0);
g2 = new DirectR(this, width, height);
// create a new FBO and set up a texture
g2.beginDraw_();
looping = false;
originallyLooping = looping;
}
void exit() {
// destroy the FBO and copy its texture to the PGraphic texture
g2.endDraw_();
super.exit();
}
int wrap(int count, int max) {
int remainder = count % (max+1);
if (count > max) return remainder;
else return count;
}
void drawBox() {
// draw a box onto the PGraphics object
g2.background(0);
int c = wrap(frameCount, 255);
g2.fill(0, c, c);
//g2.lights();
g2.noStroke();
//g2.translate(width/2, height/2);
//g2.rotateX(frameCount/100.0);
//g2.rotateY(frameCount/200.0);
g2.box(40);
}
void draw() {
if (!looping) looping = true;
if (originallyLooping) {
if (frameCount > 1) return;
} else {
//if (frameCount > 4) return;
//else if (frameCount == 2) try {
// Thread.sleep(1000);
//} catch (Throwable e) {
//}
}
println(frameCount);
background(0);
drawBox();
// render the PGraphic's FBO, note this fails in loop mode
g2.imageFrameBuffer();
int oldColor = getGraphics().fillColor;
fill(255);
textSize(16);
text("frameCount = " + frameCount + ", FPS: " + frameRate, 10, 20);
fill(oldColor);
}
then i see a box in the top left corner changing from black to turquoise (blue/green)
HOWEVER they ARE reset upon normal endDraw();
/endDraw_();
in which if i do
g2.beginDraw();
drawBox();
g2.endDraw();
image(g2, 0, 0);
then lights gets reset in the next and subsequent draws