It has to be something that I'm doing wrong.  All of the transparency demos in the Java3D demo directory display fine on this card with the OpenGL runtime.
 
I can cut & paste the TransparencyAttributes code out of a working demo and copy it into my app, and the object still disappears completely.
 
I could really use a 3rd or 4th or even 5th pair of eyes looking at this code.  All I can think of is that something I've set somewhere else is affecting the display.
 
I've a jar illustrating the problem at http://www.users.qwest.net/~kduling/Milkshape/Demo.jar  In the console, you'll see "Transparency attributes for Crystal were set to 0.77"  There are also two screenshots, http://www.users.qwest.net/~kduling/Milkshape/ogl.jpg and http://www.users.qwest.net/~kduling/Milkshape/dx.jpg that show how this works fine in DirectX, but not in OpenGL.
 
The loader is currently doing all the work here in MS3DLoader.loadModel().
 
 
  /** Load the model from the input stream
   * @param is an InputStream object
   * @return the loaded Scene
   */
  private Scene loadModel(final InputStream is)
  {
    final float[] texCoord = new float[2];
    final SceneBase scene = new SceneBase();
    final BranchGroup objGroup = new BranchGroup();
    try
    {
      ledis = new LEDataInputStream(is);
      final MS3DHeader header = loadHeader();
      final MS3DVertex vertList[] = loadVertexList();
      final MS3DTriangle triList[] = loadTriangleList();
      final MS3DGroup groupList[] = loadGroupList();
      final MS3DMaterial materialList[] = loadMaterialList();
      final float animationFPS = this.ledis.readFloat();
      final float currentTime = this.ledis.readFloat();
      final int totalFrames = this.ledis.readInt();
      final MS3DJoint jointList[] = loadJointList();
 
      for (int i = 0; i < groupList.length; i++)
      {
        Texture texture = null;
        Texture alphamap = null;
        int vertexCount = 0;
        MS3DGroup mesh = groupList[i];
        TriangleArray triangles;
        Shape3D shape = new Shape3D();
        Material mat = new Material();
        Appearance app = new Appearance();
        final int matIndex = mesh.getMaterialIndex();
        if (matIndex > -1)
        {
          final MS3DMaterial material = materialList[matIndex];
          Color4f color4 = material.getAmbient();
          mat.setAmbientColor(color4.x, color4.y, color4.z);
 
          color4 = material.getDiffuse();
          mat.setDiffuseColor(color4.x, color4.y, color4.z);
 
          color4 = material.getEmissive();
          mat.setEmissiveColor(color4.x, color4.y, color4.z);
          color4 = material.getSpecular();
          mat.setSpecularColor(color4.x, color4.y, color4.z);
 
          final float trans = 1.0f - material.getTransparency();
          if (trans > 0.0f)
          {
            TransparencyAttributes transparency = new TransparencyAttributes();
            transparency.setTransparency(trans);
            transparency.setTransparencyMode(TransparencyAttributes.BLENDED); // if this is set to SCREEN_DOOR, it works
            app.setTransparencyAttributes(transparency);
System.out.println("Transparency attributes for " + mesh.getName() + " were set to " + trans);
          }
 
          mat.setShininess(material.getShininess());
 
          String texFileName = material.getTexture();
          if (texFileName.length() > 0)
          {
            switch (source)
            {
              case FROM_FILE:
                  if (this.getBasePath() != null)
                    texFileName = this.getBasePath() + texFileName;
                  texture = new TextureLoader(texFileName, observer).getTexture();
                break;
              case FROM_URL:
                {
                  final byte temp[] = texFileName.getBytes();
                  for (int x = 0; x < temp.length; x++)  // search for a backslash and replace
                    if (temp[x] == '\\')
                      temp[x] = '/';
                  texFileName = new String(temp);
                  texture = new TextureLoader(new URL(getBaseUrl(), texFileName), observer).getTexture();
                }
                break;
            }
          }
         
          if (texture != null)
          {
            app.setTexture(texture);
 
            TextureAttributes ta = new TextureAttributes();
            ta.setTextureMode(TextureAttributes.MODULATE);
            app.setTextureAttributes(ta);
 
            // TODO: Still need to load the 2nd texture
          }
          app.setMaterial(mat);
          if (texture != null)
            triangles  = new TriangleArray(mesh.getTriangleCount() * 3, GeometryArray.COORDINATES |
                                                                        GeometryArray.NORMALS |
                                                                        GeometryArray.TEXTURE_COORDINATE_2 |
                                                                        GeometryArray.COLOR_3);
          else
            triangles  = new TriangleArray(mesh.getTriangleCount() * 3, GeometryArray.COORDINATES |
                                                                        GeometryArray.NORMALS |
                                                                        GeometryArray.COLOR_3);
        }
        else
          triangles  = new TriangleArray(mesh.getTriangleCount() * 3, GeometryArray.COORDINATES |
                                                                      GeometryArray.NORMALS);
 
        for (int j = 0; j < mesh.getTriangleCount(); j++)
        {
          final int triangleIndex = mesh.getTriangleIndicies()[j];
          final MS3DTriangle triangle = triList[triangleIndex];
          final float s[] = triangle.getS();
          final float t[] = triangle.getT();
          for (int k = 0; k < 3; k++)
          {
            final int index = triangle.getVertexIndicies()[k];
            final Vector3f normals[] = triangle.getVertexNormals();
            final MS3DVertex vertex = vertList[index];
            triangles.setCoordinate(vertexCount, vertex.getLocation());
            if (texture != null)
            {
              texCoord[0] = s[k];
              texCoord[1] = t[k];
              triangles.setTextureCoordinate(0, vertexCount, texCoord);
            }
            triangles.setNormal(vertexCount++, normals[k]);
          }
        }
        shape.setGeometry(triangles);
        shape.setAppearance(app);
        objGroup.addChild(shape);
        scene.addNamedObject(mesh.getName(), shape);
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    scene.setSceneGroup(objGroup);
    return scene;
  }

Reply via email to