[英]Java3D Canvas3D has paint cycle glitch in Win64 environment
我有一個Java / Swing / Java3D / JOGAMP JOGL /應用程序,其中一組XYZ滑塊控制3D查看器的位置。 它在MacOS(10.11)上運行良好。 但是,在Windows 10(64位)下運行時,屏幕的3DCanvas區域有時會被空白灰色覆蓋。
我為Canvas3D使用黑色背景,並使用默認的雙緩沖。
有人建議使用簡約的應用程序進行測試,然后我使用Java3D.org中的“ PyramidEample.java”代碼示例復制了相同的問題(如下所述)
這是我在Windows-10(64位)中看到的內容:
1)在將應用程序圖標化到擴展塢,然后重新整理窗口(去圖標化)時,會發生錯誤。 當應用程序窗口膨脹時,您會在Canvas3D區域中看到一秒鍾的正確圖像,然后將其覆蓋或替換為純灰色(與滑塊控件的背景顏色相同)。
如果拖動滑塊,Canvas3D將繼續顯示3D內容。 在Swing鼠標處理程序處理了其中一個應用程序滑塊之后,我從未見過灰色的封面。
2)當我將應用程序窗口橫向拖離屏幕,然后反轉並向后拖動時,Canvas3D部分在正常圖像和淺灰色之間閃爍。 拖動結束時(應用程序完全封閉在屏幕中),最終的Canvas3D區域是不可預測的。...在釋放鼠標時,可以將其繪制為普通灰色或純灰色。
3)睡眠-不睡眠。 如果我的應用程序位於前台並睡眠Win筆記本電腦,則當我將其喚醒后,我的應用程序將在Canvas3D繪制位置顯示為淺灰色。 演示錯誤外觀的視頻剪輯
我試過的
1)雙重緩沖問題? 我嘗試將Canvas3D設置為禁用雙緩沖,但沒有效果。
2)我將代碼放入應用程序的WindowListener的“ windowDeiconified(event)”方法中,該方法強制進行Canvas3D重繪,但是卻無濟於事。
3)由於該錯誤是與平台有關的,因此我嘗試了所有可能的“系統外觀”選項,但是並沒有解決問題。
由於一個非常簡單的測試應用程序會顯示3D圖形錯誤,因此如果您可以縮小到Java3D運行時環境變量的范圍,將有幫助:1)如果使用較舊的Oracle Java3D(JRE 1.8.0_22或更早版本)而不是JOGAMP 1.6.0替換堆棧,您看到vid中顯示的錯誤了嗎?
2)無論您運行什么Java3D堆棧,了解您是否可以看到此錯誤都是有幫助的。
Java編譯器:1.8 Java JDK-JRE:1.8.0_102 Java 3D:JOGAMP:3D [dev] 1.6.0-pre12-daily-experimental每日操作系統:Windows 10 Pro(64位)測試計算機:Dell筆記本電腦E6500 w / 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);
}
}
對不起,這個舊的重播。
將以下內容添加到您的主類中:
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.