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 ;)))