Java3D draws a blank white window (not in the applet)

I am trying to do something interesting using Java 3D, and I am studying official tutorials. My problem: sometimes it shows well without any problems, but sometimes the window is white and shows nothing until I resize the window. How can I solve this problem with updating a drawing?

Here is the whole code

import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

public class Main {
public Main()
{
    SimpleUniverse simpleUniverse = new SimpleUniverse();
    BranchGroup group = new BranchGroup();
    Sphere sphere = new Sphere(0.5f);

    Color3f light1Color = new Color3f(0.7f,0.7f,5f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0),100);
    Vector3f light1Direction = new Vector3f(4.0f,-7.0f,-12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color,light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);

    Transform3D transform = new Transform3D();
    TransformGroup tg = new TransformGroup();
    Vector3f pos = new Vector3f(0,0,-5);
    transform.setTranslation(pos);
    tg.setTransform(transform);
    tg.addChild(sphere);
    group.addChild(tg);
    simpleUniverse.getViewingPlatform().setNominalViewingTransform();
    simpleUniverse.addBranchGraph(group);
}

public static void main(String[] args) {
    new Main();
}
}
+4
source share
1 answer

This is a common problem with heavy weight rendering components, such as Canvas3Dthose used inside Java3D.

You can avoid this by calling

System.setProperty("sun.awt.noerasebackground", "true");

as the first line of the main cour method or by running your program with

java YourProgram -Dsun.awt.noerasebackground=true

(Websearches noerasebackground , )

+3

Source: https://habr.com/ru/post/1570024/


All Articles