hi-res pgraphics problem in v2.0.2. someone pls verify/confirm?
in
Programming Questions
•
1 month ago
hi forum
the following example is using a pgraphics to reproduce the screen drawing in a larger resolution (sphere in the middle of the screen).
since I've updated to processing 2.0.2 my code behaves completely different. so maybe i'm doing something fundamentally wrong or there's a glitch in 2.0.2. can someone look into the following example and let me know if it's me or processing that's doing it wrong?
to reproduce:
1. start the sketch
2. hit any key to dump the pgraphics into a tif-file
3. expected result: screen: sphere in the center / file: sphere in the center
4. result: screen: sphere is totally offset / file: sphere in the center
//toggle hires-pgraphics
boolean makehires = true;
int myWidth = 300;
int myHeight = 300;
int hires_scale = 3;
int myWidth_hires = myWidth * hires_scale;
int myHeight_hires = myHeight * hires_scale;
int myHeight = 300;
int hires_scale = 3;
int myWidth_hires = myWidth * hires_scale;
int myHeight_hires = myHeight * hires_scale;
PGraphics hires;
////////////////////////////////////////////////////////////////////////////////
void setup() {
// setup screen
size(myWidth, myHeight, P3D);
if (makehires){
hires = createGraphics(myWidth_hires, myHeight_hires, P3D);
}
}
hires = createGraphics(myWidth_hires, myHeight_hires, P3D);
}
}
void draw() {
// drawing a sphere ono the screen
background(0);
stroke(0);
fill(255);
camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);
translate(width/2, height/2, 0);
sphere(100);
// replicating the same sphere scaled in hires
if (makehires){
hires.beginDraw();
hires.background(0);
hires.stroke(0);
hires.fill(255);
hires.camera(hires.width/2.0, hires.height/2.0, (hires.height/2.0) / tan(PI*30.0 / 180.0), hires.width/2.0, hires.height/2.0, 0, 0, 1, 0);
hires.translate(hires.width/2, hires.height/2, 0);
hires.sphere(100);
hires.endDraw();
}
}
if (makehires){
hires.beginDraw();
hires.background(0);
hires.stroke(0);
hires.fill(255);
hires.camera(hires.width/2.0, hires.height/2.0, (hires.height/2.0) / tan(PI*30.0 / 180.0), hires.width/2.0, hires.height/2.0, 0, 0, 1, 0);
hires.translate(hires.width/2, hires.height/2, 0);
hires.sphere(100);
hires.endDraw();
}
}
void keyReleased() {
if (makehires){
String timestamp = year() + nf(month(),2) + nf(day(),2) + "-" + nf(hour(),2) + nf(minute(),2) + nf(second(),2);
hires.save(timestamp + ".tif"); // Saves a TIFF file named xxxx.tif
}
}
1