jogl webstart - need to provide natives and jogl.jar

hello, i am trying to webstart my jogl app, but all that shows up is the application window and a white area where the gl context should be.

my ressources part looks like this:


<resources>
      <j2se href="http://java.sun.com/products/autodl/j2se" version="1.5+"/>
      <jar href="myjogljar.jar" />
      <extension name="jogl" href="http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jnlp" />
</resources>

if i got it right, then webstart should automatically get the necessary jogl.jar and its natives from the given location. or do i have to provide them myself?

what else could be the problem with the white area? the application runs fine as standalone.

Open the Java Control Panel, go to the Advanced tab, open the Java console node in the tree and enable it. An exception is probably being thrown from your app when it’s running in the sandbox.

thanks ken, yes there was an exception.

it seems it is a filepermission exception:


xception in thread "Thread-13" javax.media.opengl.GLException: java.security.AccessControlException: access denied (java.io.FilePermission data\a.tga read)
	at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:271)
	at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:263)
	at javax.media.opengl.GLCanvas.display(GLCanvas.java:130)
	at com.sun.opengl.util.Animator.display(Animator.java:144)
	at com.sun.opengl.util.Animator$MainLoop.run(Animator.java:181)
	at java.lang.Thread.run(Unknown Source)

that file is packed inside the jar, btw. how can i allow it to be read?

edit: i have set permissions to all-permissions, but the jar is not signed. is that the problem?

edit2: ok, i signed it but now i am getting a normal filenotfound exception. strange… ?

Look at the jogl-demos source code, in particular their use of ClassLoader.getResourceAsStream(). This is the best mechanism to use when bundling your data alongside your application in the jar file. You also don’t need to sign the jar file if you use this API.

thanks. ok i have changed all the loading of resources to the ClassLoader.getResourceAsStream() and it works locally as standalone jar, but when using webstart, the resources cant be found and null is returned. i have even added the path to the resources to the classpath. what could the problem be?

thanks!

I think you need to put the resources into the jar file and reference them with a relative path. Again, please see how the jogl-demos.jar and jogl-demos-data.jar files are organized.

ok, the problem was that the location of the file was not on the classpath.

now the application starts unfortunately the TGA image that is in the jar, seems to get scrambled somehow. the texture has “holes” in it.

are there any known problems about TGA-files stored in jars?

No, no known problems. If you’re using the TextureIO classes to load your TGA image, there’s a chance there’s a bug somewhere in the loader. If you can make a small test case that shows that loading the texture works when it’s on disk but not when it’s loaded as a resource from a jar file, please file a bug with the JOGL Issue Tracker.

ok, i have compiled a small test case.
attached is the jar which holds the tga inside. usually you should be able to just start this in a directory with jogl.jar and the jogl native libraries.
(NOTE: the jar is renamed to .txt cause the forum doesnt allow *.jar)
when running this from the jar, you should notice that the texture is cut off at the top.
while when running this regularly from command line the texture should be displayed correctly.

here is the source code:


import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;

import com.sun.opengl.util.Animator;

public class JarTest extends Frame implements GLEventListener {
	
	public static void main(String[] args) {
		new JarTest();
	}


	private static final long serialVersionUID = 1L;

	GLCanvas canvas;

	Animator animator;

	IntBuffer texId;

	public JarTest() {
		super("JarTest");
		canvas = new GLCanvas();
		canvas.addGLEventListener(this);
		animator = new Animator(canvas);
		animator.start();
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				new Thread(new Runnable() {
					public void run() {
						animator.stop();
						System.exit(0);
					}
				}).start();
			}
		});
		add(canvas);
		setVisible(true);
		setSize(200, 200);
	}


	public void display(GLAutoDrawable drawable) {
		GL gl = drawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		gl.glLoadIdentity();

		gl.glBindTexture(GL.GL_TEXTURE_2D, texId.get(0));
		
		gl.glBegin(GL.GL_QUADS);
		gl.glTexCoord2f(0,0);
		gl.glVertex3f(1.0f, 1, 0.0f);
		gl.glTexCoord2f(1,0);
		gl.glVertex3f( 160.0f, 1, 0.0f);
		gl.glTexCoord2f(1,1);
		gl.glVertex3f( 160.0f, 160, 0.0f);
		gl.glTexCoord2f(0,1);
		gl.glVertex3f(1.0f, 160,  0.0f);
		gl.glEnd();
	}

	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
	}

	public void init(GLAutoDrawable arg0) {
		GL gl = arg0.getGL();
		gl.glClearColor(0, 0, 0, 1);
		
	
		InputStream fis =  getClass().getClassLoader().getResourceAsStream("a.tga") ; 
		
		final int datasize = 128*128*4;
		
		byte [] b = new byte[datasize];
		ByteBuffer buffer = ByteBuffer.allocate(datasize);//null;
		
		try {
			fis.skip(18);
			fis.read( b );
			buffer = ByteBuffer.wrap(b);
			fis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		for (int i = 0; i < datasize; i += 4) {
			byte temp = buffer.get(i);
			buffer.put(i, buffer.get(i + 2));
			buffer.put(i + 2, temp);
		}
				
		texId = IntBuffer.allocate(1);
		gl.glGenTextures(1, texId);		
		gl.glBindTexture(GL.GL_TEXTURE_2D, texId.get(0));
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
		gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
		gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 128, 128, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer);
	
		gl.glEnable(GL.GL_ALPHA_TEST);
		gl.glEnable(GL.GL_TEXTURE_2D);
		gl.glEnable(GL.GL_BLEND);
		gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
		gl.glDisable(GL.GL_CULL_FACE);

	}

	public void reshape(GLAutoDrawable drawable, int x, int y, int width,
			int height) {
		GL gl = drawable.getGL();
		gl.glViewport(0, 0, width, height);
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
		gl.glOrtho(0, width, 0, height, -1, 1);
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glLoadIdentity();
	}
}

(sorry for the bad example and terrible source, it is very late over here ;)))

Sorry, but your attachment is corrupted. Can you place it on another web server, or just file a bug with the JOGL Issue Tracker and attach it there?

ok, that must have happened when renaming it to *.txt. sorry!

right now i am at work, but tonight i will reupload it and post an issue to the tracker.

ok, here is the issue:
https://jogl.dev.java.net/issues/show_bug.cgi?id=266

and here the jar:
http://www.embege.com/misc/Test.jar

thanks!