P3D offscreen not full functional?
in
Programming Questions
•
2 years ago
Hi I'm doing simple visualization where I want to plot one molecular geometry over the other where. I want to render first both molecules into some image buffer independently, and than do some image composition to overplay it.
I expected that this code should do the same, but it does not. Looks like that some features does not work in P3D offscreen rendering (like background() , material definitions, lightning definitions ...... )
Without offscreen rendering
With offscreen rendering
I expected that this code should do the same, but it does not. Looks like that some features does not work in P3D offscreen rendering (like background() , material definitions, lightning definitions ...... )
Without offscreen rendering
- void setup()
{
smooth();
size(800, 800, P3D);
colorMode(RGB, 1);
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
}
void draw()
{
background(1.0,1.0,1.0);
pushMatrix();
lightSpecular(1.0, 1.0, 1.0 ); // color of specular light
specular(0.5, 0.5, 0.5); // color of specular material
ambientLight(0.5, 0.5, 0.5); // color of ambient light
directionalLight(1, 1, 1, -1, -1, -1); // color and position of directional light
shininess(50.0);
sphereDetail(20);
translate(400, 400, -30);
rotateX((400-mouseY)*0.01);
rotateZ(mouseX*0.01);
scale(20);
specular (0.0, 0.0, 0.0);
noStroke();
sphere(10);
stroke(0.5);
strokeWeight(4);
noLights();
translate(10,10,10);
sphere(10);
popMatrix();
}
With offscreen rendering
- PGraphics PG0,PG1;
void setPG(PGraphics PG) {
g.endDraw();
g = PG;
g.beginDraw();
}
void setup()
{
smooth();
size(800, 800, P2D);
size(800, 800, P2D);
PG0 = g;
PG1 = createGraphics(width,height, P3D);
PG1.smooth();
PG1.noStroke();
PG1.colorMode(RGB, 1);
PG1.ortho(-width/2, width/2, -height/2, height/2, -10, 10);
}
void draw()
{
setPG(PG1);
background(1.0,1.0,1.0);
pushMatrix();
lightSpecular(1.0, 1.0, 1.0 ); // color of specular light
specular(0.5, 0.5, 0.5); // color of specular material
ambientLight(0.5, 0.5, 0.5); // color of ambient light
directionalLight(1, 1, 1, -1, -1, -1); // color and position of directional light
shininess(50.0);
sphereDetail(20);
translate(400, 400, -30);
rotateX((400-mouseY)*0.01);
rotateZ(mouseX*0.01);
scale(20);
specular (0.0, 0.0, 0.0);
noStroke();
sphere(10);
stroke(0.5);
strokeWeight(4);
noLights();
translate(10,10,10);
sphere(10);
popMatrix();
setPG(PG0);
image(PG1, 0, 0);
}
1