我有一个Java / Swing / Java3D / JOGAMP JOGL / app,其中一组X-Y-Z滑块控制3D查看器位置。它在MacOS上运行良好(10.11)。但是,在Windows 10(64位)下运行时,屏幕的3DCanvas区域有时会被空白灰色覆盖。
我使用Canvas3D的黑色背景和默认的双缓冲。
有人建议使用极简主义应用进行测试,然后我复制了 同样的问题使用" PyramidEample.java" Java3D.org的代码示例(发布在下面)
这是我在Windows-10(64位)中看到的内容:
1)将应用程序图标化到扩展坞,然后重新设置窗口(去图标化)时会出现错误。随着应用程序窗口膨胀,您可以在Canvas3D区域中看到正确的图像,只需几分之一秒,然后将其覆盖或替换为平坦的灰色(与滑块控件的背景颜色相同)。
如果我拖动滑块,Canvas3D将继续显示3D内容。在Swing鼠标处理程序处理其中一个应用程序滑块后,我从未见过灰色封面。
2)当我将应用程序窗口侧向拖离屏幕,然后反向并向后拖动时,Canvas3D部分在正常图像和平面灰色之间闪烁。在拖动结束时(应用程序完全封闭在屏幕中),最终的Canvas3D区域是不可预测的....它可以在窗口栏的鼠标释放时绘制为正常灰色和平坦灰色。
3)睡觉 - 睡不着觉。如果我把我的应用程序放在前台并睡觉Win笔记本电脑,当我将其唤醒时,我的应用程序显示Canvas3D应绘制的平坦灰色。 Video Clip demonstrating what bug looks like
我尝试过的事情:
1)双缓冲问题?我尝试将Canvas3D设置为禁用双缓冲,但它没有效果。
2)我把代码放在app的WindowListener" windowDeiconified(event)"强制Canvas3D重绘的方法,但没有做任何事。
3)由于这个bug是平台依赖的,我尝试了所有可能的系统外观和感觉"选项,但这并没有解决问题。
由于一个非常简单的测试应用程序会出现3D图形错误,如果您可以将其缩小到Java3D运行时环境变量,这将有所帮助:
1)如果使用较旧的Oracle Java3D(JRE 1.8.0_22或更早版本)运行,而不是JOGAMP 1.6.0替换堆栈,您是否看到了vid中显示的错误?
2)无论你运行什么Java3D堆栈,知道你是否能看到这个bug都会很有帮助。
Java编译器:1.8 Java JDK-JRE:1.8.0_102 Java 3D:JOGAMP:3D [dev] 1.6.0-pre12-daily-experimental daily 操作系统:Windows 10 Pro(64位) 测试电脑:戴尔笔记本电脑E6500配NVIDIA Quadro NVS 160M卡(驱动程序9.18.13.4192)
import java.awt.Color;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.vecmath.*;
// An Egyptian pyramid
// Base divided into two triangles
public class PyramidExample {
public static void main(String[] args) {
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
Point3f e = new Point3f(1.0f, 0.0f, 0.0f); // east
Point3f s = new Point3f(0.0f, 0.0f, 1.0f); // south
Point3f w = new Point3f(-1.0f, 0.0f, 0.0f); // west
Point3f n = new Point3f(0.0f, 0.0f, -1.0f); // north
Point3f t = new Point3f(0.0f, 0.721f, 0.0f); // top
TriangleArray pyramidGeometry = new TriangleArray(18,
TriangleArray.COORDINATES);
pyramidGeometry.setCoordinate(0, e);
pyramidGeometry.setCoordinate(1, t);
pyramidGeometry.setCoordinate(2, s);
pyramidGeometry.setCoordinate(3, s);
pyramidGeometry.setCoordinate(4, t);
pyramidGeometry.setCoordinate(5, w);
pyramidGeometry.setCoordinate(6, w);
pyramidGeometry.setCoordinate(7, t);
pyramidGeometry.setCoordinate(8, n);
pyramidGeometry.setCoordinate(9, n);
pyramidGeometry.setCoordinate(10, t);
pyramidGeometry.setCoordinate(11, e);
pyramidGeometry.setCoordinate(12, e);
pyramidGeometry.setCoordinate(13, s);
pyramidGeometry.setCoordinate(14, w);
pyramidGeometry.setCoordinate(15, w);
pyramidGeometry.setCoordinate(16, n);
pyramidGeometry.setCoordinate(17, e);
GeometryInfo geometryInfo = new GeometryInfo(pyramidGeometry);
NormalGenerator ng = new NormalGenerator();
ng.generateNormals(geometryInfo);
GeometryArray result = geometryInfo.getGeometryArray();
// yellow appearance
Appearance appearance = new Appearance();
Color3f color = new Color3f(Color.yellow);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Texture texture = new Texture2D();
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
Material mat = new Material(color, black, color, white, 70f);
appearance.setTextureAttributes(texAttr);
appearance.setMaterial(mat);
appearance.setTexture(texture);
Shape3D shape = new Shape3D(result, appearance);
group.addChild(shape);
// above pyramid
Vector3f viewTranslation = new Vector3f();
viewTranslation.z = 3;
viewTranslation.x = 0f;
viewTranslation.y = .3f;
Transform3D viewTransform = new Transform3D();
viewTransform.setTranslation(viewTranslation);
Transform3D rotation = new Transform3D();
rotation.rotX(-Math.PI / 12.0d);
rotation.mul(viewTransform);
universe.getViewingPlatform().getViewPlatformTransform().setTransform(
rotation);
universe.getViewingPlatform().getViewPlatformTransform().getTransform(
viewTransform);
// lights
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
1000.0);
Color3f light1Color = new Color3f(.7f, .7f, .7f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1 = new DirectionalLight(light1Color,
light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
Color3f ambientColor = new Color3f(.4f, .4f, .4f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
group.addChild(ambientLightNode);
universe.addBranchGraph(group);
}
}
答案 0 :(得分:0)
对不起,这次重播。
将以下内容添加到您的主类中:
static {
// in JRE 7 from causing redraw problems (i.e. the Java 3D canvas is sometimes
// drawn as a blank gray rectangle).
System.setProperty("sun.awt.noerasebackground", "true");
}
您的完整代码,这次使用JFrame和Canvas,而不是默认的SimpleUniverse的内部框架:
package test;
import java.awt.*;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.swing.*;
import javax.vecmath.*;
// An Egyptian pyramid
// Base divided into two triangles
public class PyramidExample {
static {
// in JRE 7 from causing redraw problems (i.e. the Java 3D canvas is sometimes
// drawn as a blank gray rectangle).
System.setProperty("sun.awt.noerasebackground", "true");
}
/**
* Main method
* @param args
*/
public static void main(String[] args) {
JFrame frame = new JFrame("Pyramid Example");
frame.setSize(800, 600);
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.setLayout(new BorderLayout());
// get default configuration for 3D
GraphicsConfiguration conf = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(conf);
// create simpleUniverse
SimpleUniverse universe = new SimpleUniverse(canvas);
BranchGroup scene = createScene(universe);
universe.addBranchGraph(scene);
mainPanel.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
}
/**
* Create Scene graph
* @param universe
* @return
*/
private static BranchGroup createScene(SimpleUniverse universe) {
BranchGroup group = new BranchGroup();
Point3f e = new Point3f(1.0f, 0.0f, 0.0f); // east
Point3f s = new Point3f(0.0f, 0.0f, 1.0f); // south
Point3f w = new Point3f(-1.0f, 0.0f, 0.0f); // west
Point3f n = new Point3f(0.0f, 0.0f, -1.0f); // north
Point3f t = new Point3f(0.0f, 0.721f, 0.0f); // top
TriangleArray pyramidGeometry = new TriangleArray(18,
TriangleArray.COORDINATES);
pyramidGeometry.setCoordinate(0, e);
pyramidGeometry.setCoordinate(1, t);
pyramidGeometry.setCoordinate(2, s);
pyramidGeometry.setCoordinate(3, s);
pyramidGeometry.setCoordinate(4, t);
pyramidGeometry.setCoordinate(5, w);
pyramidGeometry.setCoordinate(6, w);
pyramidGeometry.setCoordinate(7, t);
pyramidGeometry.setCoordinate(8, n);
pyramidGeometry.setCoordinate(9, n);
pyramidGeometry.setCoordinate(10, t);
pyramidGeometry.setCoordinate(11, e);
pyramidGeometry.setCoordinate(12, e);
pyramidGeometry.setCoordinate(13, s);
pyramidGeometry.setCoordinate(14, w);
pyramidGeometry.setCoordinate(15, w);
pyramidGeometry.setCoordinate(16, n);
pyramidGeometry.setCoordinate(17, e);
GeometryInfo geometryInfo = new GeometryInfo(pyramidGeometry);
NormalGenerator ng = new NormalGenerator();
ng.generateNormals(geometryInfo);
GeometryArray result = geometryInfo.getGeometryArray();
// yellow appearance
Appearance appearance = new Appearance();
Color3f color = new Color3f(Color.yellow);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Texture texture = new Texture2D();
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
Material mat = new Material(color, black, color, white, 70f);
appearance.setTextureAttributes(texAttr);
appearance.setMaterial(mat);
appearance.setTexture(texture);
Shape3D shape = new Shape3D(result, appearance);
group.addChild(shape);
// above pyramid
Vector3f viewTranslation = new Vector3f();
viewTranslation.z = 3;
viewTranslation.x = 0f;
viewTranslation.y = .3f;
Transform3D viewTransform = new Transform3D();
viewTransform.setTranslation(viewTranslation);
Transform3D rotation = new Transform3D();
rotation.rotX(-Math.PI / 12.0d);
rotation.mul(viewTransform);
universe.getViewingPlatform().getViewPlatformTransform().setTransform(
rotation);
universe.getViewingPlatform().getViewPlatformTransform().getTransform(
viewTransform);
// lights
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
1000.0);
Color3f light1Color = new Color3f(.7f, .7f, .7f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1 = new DirectionalLight(light1Color,
light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
Color3f ambientColor = new Color3f(.4f, .4f, .4f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
group.addChild(ambientLightNode);
return group;
}
}