Search code examples
rrgl

How to draw to the full window in rgl?


I am drawing 4 subfigures in rgl to a window, and I would like them to fill the available space:

library(rgl);
rgl::open3d(windowRect = c(0,50, 1200, 1200));
rgl::mfrow3d(2, 2);


rgl::next3d(reuse=FALSE);
rgl::bg3d("yellow");

rgl::next3d(reuse=FALSE);
rgl::bg3d("blue");

rgl::next3d(reuse=FALSE);
rgl::bg3d("red");

rgl::next3d(reuse=FALSE);
rgl::bg3d("green");

However, the result uses only a tiny potion of the window, it looks like this:

Result of the code given above

How can I make the 4 colored areas span the whole window, instead of only using the tiny part in the lower left corner?


Solution

  • It tools me hours, but I have finally managed to get this to work reliably by myself. It seems you have to call par3d() after open3d().

    Also note the call to Sys.sleep, as suggested by user20650 in the comments above. Without it, the window only gets drawn in full size after clicking on it (on my machine?).

    Full working code:

    rgloptions = list("windowRect"=c(50,50,1000,1000));
    
    rgl::open3d();
    do.call(rgl::par3d, rgloptions);
    Sys.sleep(1);
    rgl::mfrow3d(2, 2);
    
    rgl::next3d(reuse=FALSE);
    rgl::bg3d("yellow");
    
    rgl::next3d(reuse=FALSE);
    rgl::bg3d("blue");
    
    rgl::next3d(reuse=FALSE);
    rgl::bg3d("red");
    
    rgl::next3d(reuse=FALSE);
    rgl::bg3d("green");
    

    This gives the following output reliably:

    enter image description here