Attached is a sample app (DirectRenderIssue.java) that demos a problem which *may* be related to what I'm seeing with the main application that we're developing. I wonder if anyone else can reproduce the symptoms I see? The application constructs a relatively simple TriangleFanArray and uses a TextureLoader to partially display an image (smile.png) draped over the fan. I've tried running this app with jdk 1.4.2_05 + J3D 1.3.1, and 1.5.0 beta2 + J3D 1.3.2, with identical results. Without DRI, the app works correctly, with DRI, the app works correctly without the texture, and incorrectly with the texture. After compiling the app, you can run it either as: java DirectRenderIssue t which displays the texture (you can see what this looks like in the attached smiley3d.jpg) or java DirectRenderIssue w which displays the wire-frame (see wireframe3d.jpg) Actually, the app works fine with or without DRI *to begin with*. If DRI is loaded, the problem occurs if you take focus away from the application window, then give the window focus once more. In this case, I see what is shown in the attached wrong3d.jpg). I have "focus follows mouse" set for Windows behaviour, but similar things occur for "click to focus". When the app starts, it looks correct. I move the mouse into another window - which removes focus from the app, and the app still looks ok. But when I move the mouse back into the app window, it immediately looks wrong, as shown. As stated, I don't know if this is the same issue that I'm seeing as reported earlier, but it certainly seems like a bad one. -- Russell Paul Byrne wrote:
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". |
import com.sun.j3d.utils.image.TextureLoader; import java.awt.*; import java.io.File; import javax.swing.*; import javax.media.j3d.*; import javax.vecmath.*;
public class DirectRenderIssue extends JFrame { private static boolean _useTexturedAppearance = true; public static void main(String args[]) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); setRendererType(args); DirectRenderIssue frame = new DirectRenderIssue(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle bounds = frame.getBounds(); frame.setLocation((screenSize.width - bounds.width) / 2, (screenSize.height - bounds.height) / 2); frame.setVisible(true); } catch (Exception e) { JOptionPane.showMessageDialog(null, e, "Error starting application", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); System.exit(0); } } private static void setRendererType(String args[]) { if (args.length > 0) { _useTexturedAppearance = (args[0].startsWith("T") || args[0].startsWith("t")); } } private static final int BACK_CLIP_POLICY = View.VIRTUAL_EYE; private static final int FRONT_CLIP_POLICY = View.VIRTUAL_EYE; private static final double INITIAL_BACK_CLIP_DISTANCE = 20.0; private static final double INITIAL_FRONT_CLIP_DISTANCE = 0.01; private static final Color3f White = new Color3f(1, 1, 1); private static final Point3d ORIGIN = new Point3d(0.0, 0.0, 0.0); private static final BoundingSphere LIGHT_BOUNDS = new BoundingSphere(ORIGIN, INITIAL_BACK_CLIP_DISTANCE); private Canvas3D canvas; private VirtualUniverse universe; private Locale locale; private BranchGroup viewGroup; private TransformGroup transformGroup; private Transform3D transform3d; private BranchGroup geomGroup; private ViewPlatform platform; private View view; private DirectionalLight headlight; private PhysicalBody body; private PhysicalEnvironment environment; public DirectRenderIssue() throws Exception { canvas = constructCanvas(); getContentPane().add(canvas, BorderLayout.CENTER); constructUniverse(); constructView(); constructShape(); makeLive(); } private Canvas3D constructCanvas() { GraphicsConfigTemplate3D tmpl = new GraphicsConfigTemplate3D(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getBestConfiguration(tmpl); return new Canvas3D(config); } private void constructUniverse() { universe = new VirtualUniverse(); locale = new Locale(universe); viewGroup = new BranchGroup(); viewGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); viewGroup.setCapability(Group.ALLOW_CHILDREN_READ); geomGroup = new BranchGroup(); geomGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); geomGroup.setCapability(Group.ALLOW_CHILDREN_READ); transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ); viewGroup.addChild(transformGroup); } private void constructView() { platform = new ViewPlatform(); transformGroup.addChild(platform); transform3d = constructTransform(); //new Transform3D(); //lookAtOrigin(6.0,45.0,45.0); transformGroup.setTransform(transform3d); headlight = new DirectionalLight(); headlight.setCapability(Light.ALLOW_STATE_WRITE); headlight.setColor(White); headlight.setInfluencingBounds(LIGHT_BOUNDS); headlight.setEnable(true); transformGroup.addChild(headlight); body = new PhysicalBody(); environment = new PhysicalEnvironment(); view = new View(); view.setBackClipPolicy(BACK_CLIP_POLICY); view.setBackClipDistance(INITIAL_BACK_CLIP_DISTANCE); view.setFrontClipPolicy(FRONT_CLIP_POLICY); view.setFrontClipDistance(INITIAL_FRONT_CLIP_DISTANCE); view.setPhysicalBody(body); view.setPhysicalEnvironment(environment); view.attachViewPlatform(platform); view.addCanvas3D(canvas); } private void constructShape() throws Exception { Fan fan = new Fan(); Shape3D shape = new Shape3D(fan); Appearance a = constructAppearance(); shape.setAppearance(a); geomGroup.addChild(shape); } private Appearance constructAppearance() throws Exception { return _useTexturedAppearance? constructTexturedAppearance(): constructWireframeAppearance(); } private Appearance constructWireframeAppearance() { Appearance wireframe = new Appearance(); PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_LINE); wireframe.setPolygonAttributes(polygonAttributes); return wireframe; } private Appearance constructTexturedAppearance() throws Exception { String workingDirectory = System.getProperty("user.dir"); File file = new File(workingDirectory,"smile.png"); JPanel observer = new JPanel(); TextureLoader loader = new TextureLoader(file.getAbsolutePath(),observer); Texture texture = loader.getTexture(); Appearance appearance = new Appearance( ); appearance.setTexture( texture ); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); appearance.setTextureAttributes(texAttr); return appearance; } private void makeLive() { viewGroup.compile(); locale.addBranchGraph(viewGroup); geomGroup.compile(); locale.addBranchGraph(geomGroup); } private Transform3D constructTransform() { double sqrt2 = Math.sqrt(2.0); double sqrt0point5 = 1.0/sqrt2; double matrix[] = { sqrt0point5, -0.5, 0.5, 3.0, 0.0, sqrt0point5, sqrt0point5, 3.0*sqrt2, -sqrt0point5, -0.5, 0.5, 3.0, 0.0, 0.0, 0.0, 1.0 }; return new Transform3D(matrix); } } class Fan extends TriangleFanArray { private static final int TotalVertexCount = 10; private static final int[] stripVertexCounts = {TotalVertexCount}; private static final int Flags = GeometryArray.BY_REFERENCE | TriangleFanArray.COORDINATES | TriangleFanArray.NORMALS | TriangleFanArray.TEXTURE_COORDINATE_2; private static final int[] TextureCoordinateSetupMap = {0}; private double[] coords = new double[3 * TotalVertexCount]; private float[] normals = new float[3 * TotalVertexCount]; private float[] tcoords = new float[2 * TotalVertexCount]; private int icoords = 0; private int inormals = 0; private int itcoords = 0; Fan() { super(TotalVertexCount, Flags, 1, TextureCoordinateSetupMap, stripVertexCounts); setCapability(GeometryArray.ALLOW_REF_DATA_READ); setCapability(GeometryArray.ALLOW_COORDINATE_READ); setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); setCapability(GeometryArray.ALLOW_NORMAL_READ); setCapability(GeometryArray.ALLOW_TEXCOORD_READ); constructVertices(); constructTextureCoordinates(); constructNormals(); setCoordRefDouble(coords); setNormalRefFloat(normals); setTexCoordRefFloat(0, tcoords); } private void constructVertices() { vertex(1.0,1.0,0.0); vertex(2.0,0.0,0.0); vertex(2.0,1.0,0.0); vertex(2.0,2.0,0.0); vertex(1.0,2.0,0.0); vertex(0.0,2.0,0.0); vertex(0.0,1.0,0.0); vertex(0.0,0.0,0.0); vertex(1.0,0.0,0.0); vertex(2.0,0.0,0.0); } private void constructTextureCoordinates() { texCoord(0.5,0.5); texCoord(0.75,0.25); texCoord(0.75,0.5); texCoord(0.75,0.75); texCoord(0.5,0.75); texCoord(0.25,0.75); texCoord(0.25,0.5); texCoord(0.25,0.25); texCoord(0.5,0.25); texCoord(0.75,0.25); } private final void constructNormals() { normal(1.0,1.0,1.0); normal(2.0,0.0,1.0); normal(2.0,1.0,1.0); normal(2.0,2.0,1.0); normal(1.0,2.0,1.0); normal(0.0,2.0,1.0); normal(0.0,1.0,1.0); normal(0.0,0.0,1.0); normal(1.0,0.0,1.0); normal(2.0,0.0,1.0); } private void vertex(double x, double y, double z) { coords[icoords++] = x; coords[icoords++] = y; coords[icoords++] = z; } private void normal(double x, double y, double z) { //System.out.println("normal("+x+","+y+","+z+");"); normals[inormals++] = (float) x; normals[inormals++] = (float) y; normals[inormals++] = (float) z; } private void texCoord(double s, double t) { tcoords[itcoords++] = (float) s; tcoords[itcoords++] = (float) t; } } =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
<<inline: smile.png>>
<<inline: smiley3d.jpg>>
<<inline: wireframe3d.jpg>>
<<inline: wrong3d.jpg>>