Re: Canvas3D disappears when resizing JComponets on Windows10
Posted by philjord on Feb 09, 2016; 1:08pm
URL: https://forum.jogamp.org/Canvas3D-disappears-when-resizing-JComponets-on-Windows10-tp4036118p4036133.html
Tom,
Sorry my answer was just an old work around I happened to recal.
Good news I've just stumbled across the real answer that I put in place many years ago also.
Early in your main (first line) add
System.setProperty("sun.awt.noerasebackground", "true");
Just as I was removing System.setProperty("jogl.disable.opengles", "true"); from my main call I found that call next to it, and it suddenly came back to me.
When you add that simple behavior Java3d will go as fast as it can, and send instructions to the GPU very quickly, so they will both thrash. The behavior itself does nothing so takes effectively zero time, not slowing anything down.
In almost all cases you'll want to add a line like this after you create your canvas3d and add it to a Universe:
canvas.getView().setMinimumFrameCycleTime(20);
This will set the maximum frame rate to 50, and allow the CPU and GPU to relax a bit. Feel free to set it to anything that seems right.
Of course things may be different on the Mac regarding the property.
Phil.
import java.awt.Frame;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.swing.SwingUtilities;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Java3DSimpleTest
{
public static void createAndShowGUI()
{
BranchGroup root = new BranchGroup();
root.addChild(new ColorCube(0.5f));
Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(root);
////////////////////////////
canvas.getView().setMinimumFrameCycleTime(20);
Frame frame = new Frame("Java3DSimpleTest");
frame.add(canvas);
frame.setSize(400, 400);
frame.setVisible(true);
}
public static void main(String[] args)
{
///////////////////////////
System.setProperty("sun.awt.noerasebackground", "true");
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
createAndShowGUI();
}
});
}
}