Java3D绘制空白窗口(不在applet中) [英] Java3D drawing empty white window (not in applet)
问题描述
我正在尝试使用Java 3D做一些有趣的事情,我正在通过官方教程学习。
我的问题是:有时它显示没有任何问题,但有时窗口是白色的,没有任何显示,直到我调整窗口大小。
如何克服此绘图更新问题?
I'm trying to do something interesting using Java 3D, and i'm learning by official tutorials. My problem is: sometimes it shows well without any problem but sometimes window is white and nothing shows until i resize the window. How can i overcome this drawing-update problem?
这是所有代码
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();
}
}
推荐答案
这是重量级渲染组件的常见问题,例如内部用于Java3D的 Canvas3D
。
This is a common problem with heavyweight rendering components, like the Canvas3D
that is used internally for Java3D.
你可以避免这可以通过调用
You can avoid this by calling
System.setProperty("sun.awt.noerasebackground", "true");
作为cour main方法的第一行,或者用
as the first line of cour main method, or by starting your program with
java YourProgram -Dsun.awt.noerasebackground=true
(Web搜索 noerasebackground
提供有关详细信息的更多信息,但此标志应解决白色背景问题)
(Websearches for noerasebackground
bring further information about the details, but this flag should solve the issue of the white background)
这篇关于Java3D绘制空白窗口(不在applet中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!