Search code examples
java3djava-3d

Java 3d display window "flashing"


i have recently began my quest into the realm of 3d graphics for java and after many hours of searching through 3d APIs i came to what i have decided is the right API for me, Java 3d. After reading the first tutorial i figured i would copy the code and give it a go,

import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;

public class Hello3d 
{
    public Hello3d()
    {
       SimpleUniverse universe = new SimpleUniverse();
       BranchGroup group = new BranchGroup();
       group.addChild(new ColorCube(0.3));
       universe.getViewingPlatform().setNominalViewingTransform();
       universe.addBranchGraph(group);
    }

    public static void main(String[] args ) {
       new Hello3d();  
    }
}

The program is quite simple, it is just supposed to output a red cube facing the camera giving it the appearance of a red square.

I put this into the following file structure:

java3d/
├── ext/
│   ├── jd3core.jar
│   ├── jd3utils.jar
│   └── vecmath.jar
│ 
└── Hello3d.java

then i compiled on command line like so

javac -cp "ext/*"; Hello3d.java

and ran it quite the same way

java -cp "ext/*"; Hello3d

This is where i run into the problem. The display screen is occasionally the expected output and occasionally just completely blank. screen caps of the window in both states

When resizing the window the display screen will vigorously flash between the correct output and the blank screen. Is there any way to fix the fact that half the time my display window will strait up not work?

Other information that might help:

I am running Windows 10
Using Java 3d 1.5.1 (Atemped to use 1.5.2 and experimental 1.6.0, same problem)
I am using Java 7

I think This question might have something to do with my problem, but dont really understand what it is i can do to fix it.


Solution

  • Ah after further research i have found the answer here

    all you need to do is put System.setProperty("sun.awt.noerasebackground", "true"); as the first line in main, hope this helps out anyone else with this issue.