diff options
author | Kenneth Russel <[email protected]> | 2003-06-25 09:05:19 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2003-06-25 09:05:19 +0000 |
commit | 2b54833bb15d6cae356fa0c5777d11e152d774cb (patch) | |
tree | c180c083ef435183c353b8ed839df1ed581a7507 | |
parent | 5b0d8eb11f96d694a72b67c51650ee55757779c5 (diff) |
Split up net.java.games.util; moved GLUT and BufferUtils into
net.java.games.jogl.util, and moved demo-specific utility classes into
jogl-demos project under demos.util. Added nearly all JavaOne demos
into jogl-demos project; rewrote where necessary to use
ClassLoader.getResourceAsStream() instead of flat files, put into
packages and added to Makefile. Added gleem to jogl-demos project.
Added jogl.jar build rule.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@12 232f8b59-042b-4e1e-8c03-345bb8c30851
-rw-r--r-- | demos/gears/Gears.java | 308 | ||||
-rw-r--r-- | demos/vertexArrayRange/VertexArrayRange.java | 692 | ||||
-rw-r--r-- | make/Makefile2 | 27 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BitmapCharRec.java (renamed from src/net/java/games/util/BitmapCharRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BitmapFontRec.java (renamed from src/net/java/games/util/BitmapFontRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BufferUtils.java (renamed from src/net/java/games/util/BufferUtils.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/CoordRec.java (renamed from src/net/java/games/util/CoordRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUT.java (renamed from src/net/java/games/util/GLUT.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmap8x13.java (renamed from src/net/java/games/util/GLUTBitmap8x13.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmap9x15.java (renamed from src/net/java/games/util/GLUTBitmap9x15.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica10.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica12.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java (renamed from src/net/java/games/util/GLUTBitmapHelvetica18.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java (renamed from src/net/java/games/util/GLUTBitmapTimesRoman10.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java (renamed from src/net/java/games/util/GLUTBitmapTimesRoman24.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java (renamed from src/net/java/games/util/GLUTStrokeMonoRoman.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/GLUTStrokeRoman.java (renamed from src/net/java/games/util/GLUTStrokeRoman.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeCharRec.java (renamed from src/net/java/games/util/StrokeCharRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeFontRec.java (renamed from src/net/java/games/util/StrokeFontRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/StrokeRec.java (renamed from src/net/java/games/util/StrokeRec.java) | 2 | ||||
-rw-r--r-- | src/net/java/games/util/DDSReader.java | 413 | ||||
-rw-r--r-- | src/net/java/games/util/DurationTimer.java | 66 | ||||
-rw-r--r-- | src/net/java/games/util/DxTex.java | 375 | ||||
-rw-r--r-- | src/net/java/games/util/LEDataInputStream.java | 223 | ||||
-rw-r--r-- | src/net/java/games/util/TGAImage.java | 310 |
25 files changed, 33 insertions, 2415 deletions
diff --git a/demos/gears/Gears.java b/demos/gears/Gears.java deleted file mode 100644 index 678ac69b2..000000000 --- a/demos/gears/Gears.java +++ /dev/null @@ -1,308 +0,0 @@ -import java.awt.*; -import java.awt.event.*; - -import net.java.games.jogl.*; - -/** - * @(#) Gears.java - * @(#) author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) - * - * This version is equal to Brian Paul's version 1.2 1999/10/21 - */ - -public class Gears { - public static void main(String[] args) { - Frame frame = new Frame("Gear Demo"); - GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); - - // Use debug pipeline - // canvas.setGL(new DebugGL(canvas.getGL())); - System.err.println("CANVAS GL IS: " + canvas.getGL().getClass().getName()); - System.err.println("CANVAS GLU IS: " + canvas.getGLU().getClass().getName()); - - canvas.addGLEventListener(new GearRenderer()); - frame.add(canvas); - frame.setSize(300, 300); - final Animator animator = new Animator(canvas); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - animator.stop(); - System.exit(0); - } - }); - frame.show(); - animator.start(); - - } - - static class GearRenderer implements GLEventListener, MouseListener, MouseMotionListener { - private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; - private int gear1, gear2, gear3; - private float angle = 0.0f; - - private int prevMouseX, prevMouseY; - private boolean mouseRButtonDown = false; - - private GL gl; - private GLDrawable gldrawable; - - public void init(GLDrawable drawable) { - gl = drawable.getGL(); - this.gldrawable = drawable; - System.err.println("INIT GL IS: " + gl.getClass().getName()); - - float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; - float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; - float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; - float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; - - gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); - gl.glEnable(GL.GL_CULL_FACE); - gl.glEnable(GL.GL_LIGHTING); - gl.glEnable(GL.GL_LIGHT0); - gl.glEnable(GL.GL_DEPTH_TEST); - - /* make the gears */ - gear1 = gl.glGenLists(1); - gl.glNewList(gear1, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); - gear(1.0f, 4.0f, 1.0f, 20, 0.7f); - gl.glEndList(); - - gear2 = gl.glGenLists(1); - gl.glNewList(gear2, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); - gear(0.5f, 2.0f, 2.0f, 10, 0.7f); - gl.glEndList(); - - gear3 = gl.glGenLists(1); - gl.glNewList(gear3, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); - gear(1.3f, 2.0f, 0.5f, 10, 0.7f); - gl.glEndList(); - - gl.glEnable(GL.GL_NORMALIZE); - - drawable.addMouseListener(this); - drawable.addMouseMotionListener(this); - } - - public void reshape(GLDrawable drawable, int x, int y, int width, int height) { - float h = (float)height / (float)width; - - gl.glMatrixMode(GL.GL_PROJECTION); - - System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); - System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); - System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); - System.err.println(); - System.err.println("glLoadTransposeMatrixfARB() supported: " + - gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); - if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { - // --- not using extensions - gl.glLoadIdentity(); - } else { - // --- using extensions - final float[] identityTranspose = new float[] { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - }; - gl.glLoadTransposeMatrixfARB(identityTranspose); - } - gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); - gl.glMatrixMode(GL.GL_MODELVIEW); - gl.glLoadIdentity(); - gl.glTranslatef(0.0f, 0.0f, -40.0f); - } - - public void display(GLDrawable drawable) { - angle += 2.0f; - - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - gl.glPushMatrix(); - gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); - gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); - gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); - - gl.glPushMatrix(); - gl.glTranslatef(-3.0f, -2.0f, 0.0f); - gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear1); - gl.glPopMatrix(); - - gl.glPushMatrix(); - gl.glTranslatef(3.1f, -2.0f, 0.0f); - gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear2); - gl.glPopMatrix(); - - gl.glPushMatrix(); - gl.glTranslatef(-3.1f, 4.2f, 0.0f); - gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear3); - gl.glPopMatrix(); - - gl.glPopMatrix(); - // gl.glEnd(); // DELIBERATE ERROR! - } - - public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} - - private void gear(float inner_radius, - float outer_radius, - float width, - int teeth, - float tooth_depth) - { - int i; - float r0, r1, r2; - float angle, da; - float u, v, len; - - r0 = inner_radius; - r1 = outer_radius - tooth_depth / 2.0f; - r2 = outer_radius + tooth_depth / 2.0f; - - da = 2.0f * (float) Math.PI / teeth / 4.0f; - - gl.glShadeModel(GL.GL_FLAT); - - gl.glNormal3f(0.0f, 0.0f, 1.0f); - - /* draw front face */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - if(i < teeth) - { - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); - } - } - gl.glEnd(); - - /* draw front sides of teeth */ - gl.glBegin(GL.GL_QUADS); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); - } - gl.glEnd(); - - /* draw back face */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - } - gl.glEnd(); - - /* draw back sides of teeth */ - gl.glBegin(GL.GL_QUADS); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - } - gl.glEnd(); - - /* draw outward faces of teeth */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); - v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); - len = (float)Math.sqrt(u * u + v * v); - u /= len; - v /= len; - gl.glNormal3f(v, -u, 0.0f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); - gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); - u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); - v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); - gl.glNormal3f(v, -u, 0.0f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); - } - gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f); - gl.glEnd(); - - gl.glShadeModel(GL.GL_SMOOTH); - - /* draw inside radius cylinder */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - } - gl.glEnd(); - } - - // Methods required for the implementation of MouseListener - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) {} - - public void mousePressed(MouseEvent e) { - prevMouseX = e.getX(); - prevMouseY = e.getY(); - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = true; - } - } - - public void mouseReleased(MouseEvent e) { - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = false; - } - } - - public void mouseClicked(MouseEvent e) {} - - // Methods required for the implementation of MouseMotionListener - public void mouseDragged(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - Dimension size = e.getComponent().getSize(); - - float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); - float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); - - prevMouseX = x; - prevMouseY = y; - - view_rotx += thetaX; - view_roty += thetaY; - } - - public void mouseMoved(MouseEvent e) {} - } -} - diff --git a/demos/vertexArrayRange/VertexArrayRange.java b/demos/vertexArrayRange/VertexArrayRange.java deleted file mode 100644 index 2a57413f9..000000000 --- a/demos/vertexArrayRange/VertexArrayRange.java +++ /dev/null @@ -1,692 +0,0 @@ -import java.awt.*; -import java.awt.event.*; -import java.nio.*; -import java.util.*; - -import net.java.games.jogl.*; - -/** <P> A port of NVidia's [tm] Vertex Array Range demonstration to - OpenGL[tm] for Java[tm] and the Java programming language. The - current web site for the demo (which does not appear to contain - the original C++ source code for this demo) is <a href = - "http://developer.nvidia.com/view.asp?IO=Using_GL_NV_fence">here</a>. </P> - - <P> This demonstration requires the following: - - <ul> - <li> A JDK 1.4 implementation - <li> an NVidia GeForce-based card - <li> a recent set of drivers - </ul> - - </P> - - <P> This demonstration illustrates the effective use of the - java.nio direct buffer classes in JDK 1.4 to access memory outside - of the Java garbage-collected heap, in particular that returned - from the NVidia-specific routine wglAllocateMemoryNV. This memory - region is used in conjunction with glVertexArrayRangeNV. </P> - - <P> On a 750 MHz PIII with an SDRAM memory bus and a GeForce 256 - running the Java HotSpot[tm] Client VM and OpenGL for Java 2.8, - this demonstration attains 90% of the speed of the compiled C++ - code, with a frame rate of 27 FPS, compared to 30 FPS for the C++ - version. On higher-end hardware (a dual 667 MHz PIII with RDRAM - and a GeForce 2) the demo currently attains between 65% and 75% of - C++ speed with the HotSpot Client and Server compilers, - respectively. </P> */ - -public class VertexArrayRange { - private boolean[] b = new boolean[256]; - private static final int SIZEOF_FLOAT = 4; - private static final int STRIP_SIZE = 48; - private int tileSize = 9 * STRIP_SIZE; - private int numBuffers = 4; - private int bufferLength = 1000000; - private int bufferSize = bufferLength * SIZEOF_FLOAT; - private static final int SIN_ARRAY_SIZE = 1024; - - private FloatBuffer bigArrayVar; - private FloatBuffer bigArraySystem; - private FloatBuffer bigArray; - private int[][] elements; - private float[] xyArray; - - static class VarBuffer { - public FloatBuffer vertices; - public FloatBuffer normals; - public int fence; - } - private VarBuffer[] buffers; - - private float[] sinArray; - private float[] cosArray; - - // Primitive: GL_QUAD_STRIP, GL_LINE_STRIP, or GL_POINTS - private int primitive = GL.GL_QUAD_STRIP; - - // Animation parameters - private float hicoef = .06f; - private float locoef = .10f; - private float hifreq = 6.1f; - private float lofreq = 2.5f; - private float phaseRate = .02f; - private float phase2Rate = -0.12f; - private float phase = 0; - private float phase2 = 0; - - // Temporaries for computation - float[] ysinlo = new float[STRIP_SIZE]; - float[] ycoslo = new float[STRIP_SIZE]; - float[] ysinhi = new float[STRIP_SIZE]; - float[] ycoshi = new float[STRIP_SIZE]; - - // For thread-safety when dealing with keypresses - private volatile boolean toggleVAR = false; - private volatile boolean toggleLighting = false; - private volatile boolean toggleLightingModel = false; - private volatile boolean recomputeElements = false; - private volatile boolean quit = false; - - // Frames-per-second computation - private boolean firstProfiledFrame; - private int profiledFrameCount; - private int numDrawElementsCalls; - private long startTimeMillis; - - private GLCanvas canvas = null; - - static class PeriodicIterator { - public PeriodicIterator(int arraySize, - float period, - float initialOffset, - float delta) { - float arrayDelta = arraySize * (delta / period); // floating-point steps-per-increment - increment = (int)(arrayDelta * (1<<16)); // fixed-point steps-per-increment - - float offset = arraySize * (initialOffset / period); // floating-point initial index - initOffset = (int)(offset * (1<<16)); // fixed-point initial index - - arraySizeMask = 0; - int i = 20; // array should be reasonably sized... - while((arraySize & (1<<i)) == 0) { - i--; - } - arraySizeMask = (1<<i)-1; - index = initOffset; - } - - public PeriodicIterator(PeriodicIterator arg) { - this.arraySizeMask = arg.arraySizeMask; - this.increment = arg.increment; - this.initOffset = arg.initOffset; - this.index = arg.index; - } - - public int getIndex() { - return (index >> 16) & arraySizeMask; - } - - public void incr() { - index += increment; - } - - public void decr() { - index -= increment; - } - - public void reset() { - index = initOffset; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private int arraySizeMask; - // fraction bits == 16 - private int increment; - private int initOffset; - private int index; - } - - public static void usage(String className) { - System.out.println("usage: java " + className + " [-slow]"); - System.out.println("-slow flag starts up using data in the Java heap"); - System.exit(0); - } - - public static void main(String[] args) { - new VertexArrayRange().run(args); - } - - public void run(String[] args) { - boolean startSlow = false; - - if (args.length > 1) { - usage(getClass().getName()); - } - - if (args.length == 1) { - if (args[0].equals("-slow")) { - startSlow = true; - } else { - usage(getClass().getName()); - } - } - - if (!startSlow) { - setFlag('v', true); // VAR on - } - setFlag(' ', true); // animation on - setFlag('i', true); // infinite viewer and light - - canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); - // canvas.setGL(new TraceGL(canvas.getGL(), System.err)); - // canvas.setGL(new DebugGL(canvas.getGL())); - VARListener listener = new VARListener(); - canvas.addGLEventListener(listener); - - final Animator animator = new Animator(canvas); - - Frame frame = new Frame("Very Simple NV_vertex_array_range demo"); - frame.setLayout(new BorderLayout()); - canvas.setSize(800, 800); - frame.add(canvas, BorderLayout.CENTER); - frame.pack(); - frame.show(); - canvas.requestFocus(); - - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - animator.stop(); - System.exit(0); - } - }); - - animator.start(); - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private void setFlag(char key, boolean val) { - b[((int) key) & 0xFF] = val; - } - - private boolean getFlag(char key) { - return b[((int) key) & 0xFF]; - } - - private void ensurePresent(String function) { - if (!canvas.getGL().isFunctionAvailable(function)) { - throw new RuntimeException("OpenGL routine \"" + function + "\" not available"); - } - } - - class VARListener implements GLEventListener { - boolean exiting = false; - - public void init(GLDrawable drawable) { - GL gl = drawable.getGL(); - GLU glu = drawable.getGLU(); - - // Try and disable synch-to-retrace for fastest framerate - if (gl.isFunctionAvailable("wglSwapIntervalEXT")) { - System.err.println("wglSwapIntervalEXT available; disabling sync-to-refresh for best framerate"); - gl.wglSwapIntervalEXT(0); - } - else { - System.err.println("wglSwapIntervalEXT not available; cannot disable sync-to-refresh"); - } - - try { - ensurePresent("glVertexArrayRangeNV"); - ensurePresent("glGenFencesNV"); - ensurePresent("glSetFenceNV"); - ensurePresent("glTestFenceNV"); - ensurePresent("glFinishFenceNV"); - ensurePresent("glAllocateMemoryNV"); - } catch (RuntimeException e) { - runExit(); - throw (e); - } - - gl.glEnable(GL.GL_DEPTH_TEST); - - gl.glClearColor(0, 0, 0, 0); - - gl.glEnable(GL.GL_LIGHT0); - gl.glEnable(GL.GL_LIGHTING); - gl.glEnable(GL.GL_NORMALIZE); - gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, new float[] {.1f, .1f, 0, 1}); - gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, new float[] {.6f, .6f, .1f, 1}); - gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[] { 1, 1, .75f, 1}); - gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, 128.f); - - gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { .5f, 0, .5f, 0}); - gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 0); - - // NOTE: it looks like GLUT (or something else) sets up the - // projection matrix in the C version of this demo. - gl.glMatrixMode(GL.GL_PROJECTION); - gl.glLoadIdentity(); - glu.gluPerspective(60, 1.0, 0.1, 100); - gl.glMatrixMode(GL.GL_MODELVIEW); - - allocateBigArray(gl, true); - allocateBuffersAndFences(gl); - - sinArray = new float[SIN_ARRAY_SIZE]; - cosArray = new float[SIN_ARRAY_SIZE]; - - for (int i = 0; i < SIN_ARRAY_SIZE; i++) { - double step = i * 2 * Math.PI / SIN_ARRAY_SIZE; - sinArray[i] = (float) Math.sin(step); - cosArray[i] = (float) Math.cos(step); - } - - if (getFlag('v')) { - gl.glEnableClientState(GL.GL_VERTEX_ARRAY_RANGE_NV); - gl.glVertexArrayRangeNV(bufferSize, bigArrayVar); - bigArray = bigArrayVar; - } else { - bigArray = bigArraySystem; - } - setupBuffers(); - gl.glEnableClientState(GL.GL_VERTEX_ARRAY); - gl.glEnableClientState(GL.GL_NORMAL_ARRAY); - - computeElements(); - - drawable.addKeyListener(new KeyAdapter() { - public void keyTyped(KeyEvent e) { - dispatchKey(e.getKeyChar()); - } - }); - } - - private void allocateBuffersAndFences(GL gl) { - buffers = new VarBuffer[numBuffers]; - int[] fences = new int[1]; - for (int i = 0; i < numBuffers; i++) { - buffers[i] = new VarBuffer(); - gl.glGenFencesNV(1, fences); - buffers[i].fence = fences[0]; - } - } - - private void setupBuffers() { - int sliceSize = bufferLength / numBuffers; - for (int i = 0; i < numBuffers; i++) { - int startIndex = i * sliceSize; - buffers[i].vertices = sliceBuffer(bigArray, startIndex, sliceSize); - buffers[i].normals = sliceBuffer(buffers[i].vertices, 3, - buffers[i].vertices.limit() - 3); - } - } - - private void dispatchKey(char k) { - setFlag(k, !getFlag(k)); - // Quit on escape or 'q' - if ((k == (char) 27) || (k == 'q')) { - runExit(); - } - - if (k == 'r') { - if (getFlag(k)) { - profiledFrameCount = 0; - numDrawElementsCalls = 0; - firstProfiledFrame = true; - } - } - - if (k == 'w') { - if (getFlag(k)) { - primitive = GL.GL_LINE_STRIP; - } else { - primitive = GL.GL_QUAD_STRIP; - } - } - - if (k == 'p') { - if (getFlag(k)) { - primitive = GL.GL_POINTS; - } else { - primitive = GL.GL_QUAD_STRIP; - } - } - - if (k == 'v') { - toggleVAR = true; - } - - if (k == 'd') { - toggleLighting = true; - } - - if (k == 'i') { - toggleLightingModel = true; - } - - if('h'==k) - hicoef += .005; - if('H'==k) - hicoef -= .005; - if('l'==k) - locoef += .005; - if('L'==k) - locoef -= .005; - if('1'==k) - lofreq += .1f; - if('2'==k) - lofreq -= .1f; - if('3'==k) - hifreq += .1f; - if('4'==k) - hifreq -= .1f; - if('5'==k) - phaseRate += .01f; - if('6'==k) - phaseRate -= .01f; - if('7'==k) - phase2Rate += .01f; - if('8'==k) - phase2Rate -= .01f; - - if('t'==k) { - if(tileSize < 864) { - tileSize += STRIP_SIZE; - recomputeElements = true; - System.err.println("tileSize = " + tileSize); - } - } - - if('T'==k) { - if(tileSize > STRIP_SIZE) { - tileSize -= STRIP_SIZE; - recomputeElements = true; - System.err.println("tileSize = " + tileSize); - } - } - } - - public void display(GLDrawable drawable) { - // Don't try to do OpenGL operations if we're tearing things down - if (quit) { - return; - } - - GL gl = drawable.getGL(); - GLU glu = drawable.getGLU(); - - // Check to see whether to animate - if (getFlag(' ')) { - phase += phaseRate; - phase2 += phase2Rate; - - if (phase > (float) (20 * Math.PI)) { - phase = 0; - } - - if (phase2 < (float) (-20 * Math.PI)) { - phase2 = 0; - } - } - - PeriodicIterator loX = - new PeriodicIterator(SIN_ARRAY_SIZE, (float) (2 * Math.PI), phase, (float) ((1.f/tileSize)*lofreq*Math.PI)); - PeriodicIterator loY = new PeriodicIterator(loX); - PeriodicIterator hiX = - new PeriodicIterator(SIN_ARRAY_SIZE, (float) (2 * Math.PI), phase2, (float) ((1.f/tileSize)*hifreq*Math.PI)); - PeriodicIterator hiY = new PeriodicIterator(hiX); - - if (toggleVAR) { - if (getFlag('v')) { - gl.glEnableClientState(GL.GL_VERTEX_ARRAY_RANGE_NV); - gl.glVertexArrayRangeNV(bufferSize, bigArrayVar); - bigArray = bigArrayVar; - } else { - gl.glDisableClientState(GL.GL_VERTEX_ARRAY_RANGE_NV); - bigArray = bigArraySystem; - } - toggleVAR = false; - setupBuffers(); - } - - if (toggleLighting) { - if (getFlag('d')) { - gl.glDisable(GL.GL_LIGHTING); - } else { - gl.glEnable(GL.GL_LIGHTING); - } - toggleLighting = false; - } - - if (toggleLightingModel) { - if(getFlag('i')) { - // infinite light - gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { .5f, 0, .5f, 0 }); - gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 0); - } else { - gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { .5f, 0, -.5f,1 }); - gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 1); - } - toggleLightingModel = false; - } - - if (recomputeElements) { - computeElements(); - recomputeElements = false; - } - - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - gl.glPushMatrix(); - - final float[] modelViewMatrix = new float[] { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, -1, 1 - }; - gl.glLoadMatrixf(modelViewMatrix); - - // FIXME: add mouse interaction - // camera.apply_inverse_transform(); - // object.apply_transform(); - - int cur = 0; - int numSlabs = tileSize / STRIP_SIZE; - - for(int slab = numSlabs; --slab>=0; ) { - cur = slab % numBuffers; - if (slab >= numBuffers) { - if (!gl.glTestFenceNV(buffers[cur].fence)) { - gl.glFinishFenceNV(buffers[cur].fence); - } - } - - FloatBuffer v = buffers[cur].vertices; - int vertexIndex = 0; - - gl.glVertexPointer(3, GL.GL_FLOAT, 6 * SIZEOF_FLOAT, v); - gl.glNormalPointer(GL.GL_FLOAT, 6 * SIZEOF_FLOAT, buffers[cur].normals); - - for(int jj=STRIP_SIZE; --jj>=0; ) { - ysinlo[jj] = sinArray[loY.getIndex()]; - ycoslo[jj] = cosArray[loY.getIndex()]; loY.incr(); - ysinhi[jj] = sinArray[hiY.getIndex()]; - ycoshi[jj] = cosArray[hiY.getIndex()]; hiY.incr(); - } - loY.decr(); - hiY.decr(); - - for(int i = tileSize; --i>=0; ) { - float x = xyArray[i]; - int loXIndex = loX.getIndex(); - int hiXIndex = hiX.getIndex(); - - int jOffset = (STRIP_SIZE-1)*slab; - float nx = locoef * -cosArray[loXIndex] + hicoef * -cosArray[hiXIndex]; - - // Help the HotSpot Client Compiler by hoisting loop - // invariant variables into locals. Note that this may be - // good practice for innermost loops anyway since under - // the new memory model operations like accidental - // synchronization may force any compiler to reload these - // fields from memory, destroying their ability to - // optimize. - float locoef_tmp = locoef; - float hicoef_tmp = hicoef; - float[] ysinlo_tmp = ysinlo; - float[] ysinhi_tmp = ysinhi; - float[] ycoslo_tmp = ycoslo; - float[] ycoshi_tmp = ycoshi; - float[] sinArray_tmp = sinArray; - float[] xyArray_tmp = xyArray; - - for(int j = STRIP_SIZE; --j>=0; ) { - float y; - - y = xyArray_tmp[j + jOffset]; - - float ny; - - v.put(vertexIndex, x); - v.put(vertexIndex + 1, y); - v.put(vertexIndex + 2, (locoef_tmp * (sinArray_tmp[loXIndex] + ysinlo_tmp[j]) + - hicoef_tmp * (sinArray_tmp[hiXIndex] + ysinhi_tmp[j]))); - v.put(vertexIndex + 3, nx); - ny = locoef_tmp * -ycoslo_tmp[j] + hicoef_tmp * -ycoshi_tmp[j]; - v.put(vertexIndex + 4, ny); - v.put(vertexIndex + 5, .15f); //.15f * (1.f - sqrt(nx * nx + ny * ny)); - vertexIndex += 6; - } - loX.incr(); - hiX.incr(); - } - loX.reset(); - hiX.reset(); - - for (int i = 0; i < elements.length; i++) { - ++numDrawElementsCalls; - gl.glDrawElements(primitive, elements[i].length, GL.GL_UNSIGNED_INT, elements[i]); - if(getFlag('f')) { - gl.glFlush(); - } - } - - gl.glSetFenceNV(buffers[cur].fence, GL.GL_ALL_COMPLETED_NV); - } - - gl.glPopMatrix(); - - gl.glFinishFenceNV(buffers[cur].fence); - - if (getFlag('r')) { - if (!firstProfiledFrame) { - if (++profiledFrameCount == 30) { - long endTimeMillis = System.currentTimeMillis(); - double secs = (endTimeMillis - startTimeMillis) / 1000.0; - double fps = 30.0 / secs; - double ppf = tileSize * tileSize * 2; - double mpps = ppf * fps / 1000000.0; - System.err.println("fps: " + fps + " polys/frame: " + ppf + " million polys/sec: " + mpps + - " DrawElements calls/frame: " + (numDrawElementsCalls / 30)); - profiledFrameCount = 0; - numDrawElementsCalls = 0; - startTimeMillis = System.currentTimeMillis(); - } - } else { - startTimeMillis = System.currentTimeMillis(); - firstProfiledFrame = false; - - } - } - } - - public void reshape(GLDrawable drawable, int x, int y, int width, int height) {} - - // Unused routines - public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} - - private void runExit() { - quit = true; - // Note: calling System.exit() synchronously inside the draw, - // reshape or init callbacks can lead to deadlocks on certain - // platforms (in particular, X11) because the JAWT's locking - // routines cause a global AWT lock to be grabbed. Run the - // exit routine in another thread and cause this one to - // terminate by throwing an exception out of it. - new Thread(new Runnable() { - public void run() { - System.exit(0); - } - }).start(); - } - } // end class VARListener - - private void allocateBigArray(GL gl, boolean tryAgain) { - float priority = .5f; - - bigArraySystem = setupBuffer(ByteBuffer.allocateDirect(bufferSize)); - - float megabytes = (bufferSize / 1000000.f); - try { - bigArrayVar = setupBuffer(gl.glAllocateMemoryNV(bufferSize, 0, 0, priority)); - } - catch (OutOfMemoryError e1) { - // Try a higher priority - try { - bigArrayVar = setupBuffer(gl.glAllocateMemoryNV(bufferSize, 0, 0, 1.f)); - } - catch (OutOfMemoryError e2) { - if (!tryAgain) { - throw new RuntimeException("Unable to allocate " + megabytes + - " megabytes of fast memory. Giving up."); - } - - System.err.println("Unable to allocate " + megabytes + - " megabytes of fast memory. Trying less."); - bufferSize /= 2; - numBuffers /= 2; - allocateBigArray(gl, false); - return; - } - } - - System.err.println("Allocated " + megabytes + " megabytes of fast memory"); - } - - private FloatBuffer setupBuffer(ByteBuffer buf) { - buf.order(ByteOrder.nativeOrder()); - return buf.asFloatBuffer(); - } - - private FloatBuffer sliceBuffer(FloatBuffer array, - int sliceStartIndex, int sliceLength) { - array.position(sliceStartIndex); - FloatBuffer ret = array.slice(); - array.position(0); - ret.limit(sliceLength); - return ret; - } - - private void computeElements() { - xyArray = new float[tileSize]; - for (int i = 0; i < tileSize; i++) { - xyArray[i] = i / (tileSize - 1.0f) - 0.5f; - } - - elements = new int[tileSize - 1][]; - for (int i = 0; i < tileSize - 1; i++) { - elements[i] = new int[2 * STRIP_SIZE]; - for (int j = 0; j < 2 * STRIP_SIZE; j += 2) { - elements[i][j] = i * STRIP_SIZE + (j / 2); - elements[i][j+1] = (i + 1) * STRIP_SIZE + (j / 2); - } - } - } -} diff --git a/make/Makefile2 b/make/Makefile2 index e68cffa30..cc3ad9b4e 100644 --- a/make/Makefile2 +++ b/make/Makefile2 @@ -367,7 +367,7 @@ GENSRC_GL_NATIVE_DIR=$(GENSRC_NATIVE_DIR)/jogl JOGL_DIR=$(SRC_DIR)/net/java/games/jogl JOGL_IMPL_DIR=$(SRC_DIR)/net/java/games/jogl/impl -JOGL_UTIL_DIR=$(SRC_DIR)/net/java/games/util +JOGL_UTIL_DIR=$(SRC_DIR)/net/java/games/jogl/util GENSRC_JOGL_DIR=$(GENSRC_JAVA_DIR)/net/java/games/jogl GENSRC_JOGL_IMPL_DIR=$(GENSRC_JAVA_DIR)/net/java/games/jogl/impl @@ -381,6 +381,7 @@ JOGL_STUB_INCLUDES_DIR_OPENGL=$(JOGL_STUB_INCLUDES_DIR)/opengl JOGL_OBJ_DIR = $(OBJ_DIR)/jogl JOGL_DSO_DIR = $(DSO_DIR) JOGL_DSO=$(JOGL_DSO_DIR)/$(DSO_PREFIX_PD)jogl.$(DSO_EXTENSION_PD) +JOGL_JAR=$(BUILD_DIR)/jogl.jar JOGL_JAVAFILES_WINDOWS = \ $(JOGL_IMPL_DIR)/windows/WindowsGLContext.java \ @@ -583,9 +584,6 @@ JOGL_JAVAFILES_FIRST_PASS = \ $(JOGL_UTIL_DIR)/BitmapFontRec.java \ $(JOGL_UTIL_DIR)/BufferUtils.java \ $(JOGL_UTIL_DIR)/CoordRec.java \ - $(JOGL_UTIL_DIR)/DDSReader.java \ - $(JOGL_UTIL_DIR)/DurationTimer.java \ - $(JOGL_UTIL_DIR)/DxTex.java \ $(JOGL_UTIL_DIR)/GLUT.java \ $(JOGL_UTIL_DIR)/GLUTBitmap8x13.java \ $(JOGL_UTIL_DIR)/GLUTBitmap9x15.java \ @@ -596,11 +594,9 @@ JOGL_JAVAFILES_FIRST_PASS = \ $(JOGL_UTIL_DIR)/GLUTBitmapTimesRoman24.java \ $(JOGL_UTIL_DIR)/GLUTStrokeMonoRoman.java \ $(JOGL_UTIL_DIR)/GLUTStrokeRoman.java \ - $(JOGL_UTIL_DIR)/LEDataInputStream.java \ $(JOGL_UTIL_DIR)/StrokeCharRec.java \ $(JOGL_UTIL_DIR)/StrokeFontRec.java \ $(JOGL_UTIL_DIR)/StrokeRec.java \ - $(JOGL_UTIL_DIR)/TGAImage.java \ $(JOGL_JAVAFILES_PD) \ $(JOGL_GENERATED_JAVAFILES) @@ -654,7 +650,7 @@ doc: -public -sourcepath "$(SRC_DIR)$(CP_SEPARATOR)$(GENSRC_JAVA_DIR)" \ net.java.games.jogl \ net.java.games.gluegen.runtime \ - net.java.games.util + net.java.games.jogl.util devdoc: mkdir -p $(JAVADOC_DIR_DEVDOC) @@ -671,15 +667,15 @@ devdoc: net.java.games.gluegen.opengl \ net.java.games.gluegen.pcpp \ net.java.games.gluegen.runtime \ - net.java.games.util + net.java.games.jogl.util # (Iff we are not on macosx): print an error if the user has not set JAVA_HOME, since that will cause # builds to fail ifneq ($(JAVA_HOME),) -win32: WIN32_COMPILER_SPECIFIED $(OUTPUT_DIRS) $(JOGL_CLASSFILES) $(JOGL_DSO) -x11: $(OUTPUT_DIRS) $(JOGL_CLASSFILES) $(JOGL_DSO) -macosx: $(OUTPUT_DIRS) $(JOGL_CLASSFILES) $(JOGL_DSO) +win32: WIN32_COMPILER_SPECIFIED $(OUTPUT_DIRS) $(JOGL_JAR) $(JOGL_DSO) +x11: $(OUTPUT_DIRS) $(JOGL_JAR) $(JOGL_DSO) +macosx: $(OUTPUT_DIRS) $(JOGL_JAR) $(JOGL_DSO) gluegen: $(GG_CLASSFILES) else @@ -820,3 +816,12 @@ $(JOGL_OBJ_DIR)/%.$(OBJ_FILE_EXT) : $(GENSRC_GL_NATIVE_DIR)/%.c $(JOGL_DSO): $(JOGL_OBJ_FILES) $(GL_C_LINK_DSO_CMD) $(JOGL_OBJ_FILES) + +# +# jar build rule +# + +$(JOGL_JAR): $(JOGL_CLASSFILES) + rm -f $@ + cd $(CLASSES_DIR) ; \ + jar cvf ../jogl.jar * diff --git a/src/net/java/games/util/BitmapCharRec.java b/src/net/java/games/jogl/util/BitmapCharRec.java index 8a46c2be0..5705cf1ec 100644 --- a/src/net/java/games/util/BitmapCharRec.java +++ b/src/net/java/games/jogl/util/BitmapCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/BitmapFontRec.java b/src/net/java/games/jogl/util/BitmapFontRec.java index 924be1caf..bb2a40746 100644 --- a/src/net/java/games/util/BitmapFontRec.java +++ b/src/net/java/games/jogl/util/BitmapFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/BufferUtils.java b/src/net/java/games/jogl/util/BufferUtils.java index c6b234ba4..aa4653693 100644 --- a/src/net/java/games/util/BufferUtils.java +++ b/src/net/java/games/jogl/util/BufferUtils.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; import java.nio.*; diff --git a/src/net/java/games/util/CoordRec.java b/src/net/java/games/jogl/util/CoordRec.java index 5dc2ce3be..a99604a4e 100644 --- a/src/net/java/games/util/CoordRec.java +++ b/src/net/java/games/jogl/util/CoordRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/GLUT.java b/src/net/java/games/jogl/util/GLUT.java index cc8ba4fdc..de010e5be 100644 --- a/src/net/java/games/util/GLUT.java +++ b/src/net/java/games/jogl/util/GLUT.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; import net.java.games.jogl.*; diff --git a/src/net/java/games/util/GLUTBitmap8x13.java b/src/net/java/games/jogl/util/GLUTBitmap8x13.java index d5fa9c9ef..ee2bf0561 100644 --- a/src/net/java/games/util/GLUTBitmap8x13.java +++ b/src/net/java/games/jogl/util/GLUTBitmap8x13.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmap8x13 { diff --git a/src/net/java/games/util/GLUTBitmap9x15.java b/src/net/java/games/jogl/util/GLUTBitmap9x15.java index cd8ce8904..e2849193b 100644 --- a/src/net/java/games/util/GLUTBitmap9x15.java +++ b/src/net/java/games/jogl/util/GLUTBitmap9x15.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmap9x15 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica10.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java index d4c7b42d6..a831ad253 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica10.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica10 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica12.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java index 4b313003b..f4a0bebeb 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica12.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica12 { diff --git a/src/net/java/games/util/GLUTBitmapHelvetica18.java b/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java index 7b8e2d0e9..2d6ca178e 100644 --- a/src/net/java/games/util/GLUTBitmapHelvetica18.java +++ b/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapHelvetica18 { diff --git a/src/net/java/games/util/GLUTBitmapTimesRoman10.java b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java index cff580943..2d56cb899 100644 --- a/src/net/java/games/util/GLUTBitmapTimesRoman10.java +++ b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapTimesRoman10 { diff --git a/src/net/java/games/util/GLUTBitmapTimesRoman24.java b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java index 6ca1714c4..cf89907b3 100644 --- a/src/net/java/games/util/GLUTBitmapTimesRoman24.java +++ b/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTBitmapTimesRoman24 { diff --git a/src/net/java/games/util/GLUTStrokeMonoRoman.java b/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java index 0c17d22e7..a3aec0211 100644 --- a/src/net/java/games/util/GLUTStrokeMonoRoman.java +++ b/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTStrokeMonoRoman { diff --git a/src/net/java/games/util/GLUTStrokeRoman.java b/src/net/java/games/jogl/util/GLUTStrokeRoman.java index a8f2e576e..d5d8e9bf2 100644 --- a/src/net/java/games/util/GLUTStrokeRoman.java +++ b/src/net/java/games/jogl/util/GLUTStrokeRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; class GLUTStrokeRoman { diff --git a/src/net/java/games/util/StrokeCharRec.java b/src/net/java/games/jogl/util/StrokeCharRec.java index 3373c516a..742a305e3 100644 --- a/src/net/java/games/util/StrokeCharRec.java +++ b/src/net/java/games/jogl/util/StrokeCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/StrokeFontRec.java b/src/net/java/games/jogl/util/StrokeFontRec.java index eb516c409..82734a6dd 100644 --- a/src/net/java/games/util/StrokeFontRec.java +++ b/src/net/java/games/jogl/util/StrokeFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/StrokeRec.java b/src/net/java/games/jogl/util/StrokeRec.java index b0eea61dd..fa4837cb7 100644 --- a/src/net/java/games/util/StrokeRec.java +++ b/src/net/java/games/jogl/util/StrokeRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.util; +package net.java.games.jogl.util; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/util/DDSReader.java b/src/net/java/games/util/DDSReader.java deleted file mode 100644 index e3b49ec95..000000000 --- a/src/net/java/games/util/DDSReader.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import java.nio.*; -import java.nio.channels.*; - -/** A reader for DirectDraw Surface (.dds) files, which are used to - describe textures. These files can contain multiple mipmap levels - in one file. This reader is currently minimal and does not support - all of the possible file formats. */ - -public class DDSReader { - - /** Simple class describing images and data; does not encapsulate - image format information. User is responsible for transmitting - that information in another way. */ - - public static class ImageInfo { - private ByteBuffer data; - private int width; - private int height; - - public ImageInfo(ByteBuffer data, int width, int height) { - this.data = data; this.width = width; this.height = height; - } - public int getWidth() { return width; } - public int getHeight() { return height; } - public ByteBuffer getData() { return data; } - } - - private FileInputStream fis; - private FileChannel chan; - private ByteBuffer buf; - private Header header; - - // FourCC codes (compression formats) - public static final int DXT1 = 0x31545844; - public static final int DXT2 = 0x32545844; - public static final int DXT3 = 0x33545844; - public static final int DXT4 = 0x34545844; - public static final int DXT5 = 0x35545844; - - // - // Selected bits in header flags - // - - public static final int DDSD_CAPS = 0x00000001; // Capacities are valid - public static final int DDSD_HEIGHT = 0x00000002; // Height is valid - public static final int DDSD_WIDTH = 0x00000004; // Width is valid - public static final int DDSD_PITCH = 0x00000008; // Pitch is valid - public static final int DDSD_BACKBUFFERCOUNT = 0x00000020; // Back buffer count is valid - public static final int DDSD_ZBUFFERBITDEPTH = 0x00000040; // Z-buffer bit depth is valid (shouldn't be used in DDSURFACEDESC2) - public static final int DDSD_ALPHABITDEPTH = 0x00000080; // Alpha bit depth is valid - public static final int DDSD_LPSURFACE = 0x00000800; // lpSurface is valid - public static final int DDSD_PIXELFORMAT = 0x00001000; // ddpfPixelFormat is valid - public static final int DDSD_MIPMAPCOUNT = 0x00020000; // Mip map count is valid - public static final int DDSD_LINEARSIZE = 0x00080000; // dwLinearSize is valid - public static final int DDSD_DEPTH = 0x00800000; // dwDepth is valid - - public static final int DDPF_ALPHAPIXELS = 0x00000001; // Alpha channel is present - public static final int DDPF_ALPHA = 0x00000002; // Only contains alpha information - public static final int DDPF_RGB = 0x00000040; // RGB data is present - - // Selected bits in DDS capabilities flags - public static final int DDSCAPS_TEXTURE = 0x00001000; // Can be used as a texture - public static final int DDSCAPS_MIPMAP = 0x00400000; // Is one level of a mip-map - - // Known pixel formats - public static final int D3DFMT_UNKNOWN = 0; - public static final int D3DFMT_R8G8B8 = 20; - public static final int D3DFMT_A8R8G8B8 = 21; - public static final int D3DFMT_X8R8G8B8 = 22; - - public void loadFile(String filename) throws IOException { - File file = new File(filename); - fis = new FileInputStream(filename); - chan = fis.getChannel(); - buf = chan.map(FileChannel.MapMode.READ_ONLY, - 0, (int) file.length()); - buf.order(ByteOrder.LITTLE_ENDIAN); - header = new Header(); - header.read(buf); - } - - public void close() { - try { - chan.close(); - fis.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** Test for presence/absence of surface description flags (DDSD_*) */ - public boolean isSurfaceDescFlagSet(int flag) { - return ((header.flags & flag) != 0); - } - - /** Test for presence/absence of pixel format flags (DDPF_*) */ - public boolean isPixelFormatFlagSet(int flag) { - return ((header.pfFlags & flag) != 0); - } - - /** Gets the pixel format of this texture (D3DFMT_*) based on some - heuristics. Returns D3DFMT_UNKNOWN if could not recognize the - pixel format. */ - public int getPixelFormat() { - if (isPixelFormatFlagSet(DDPF_RGB)) { - if (isPixelFormatFlagSet(DDPF_ALPHAPIXELS)) { - if (getDepth() == 32 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF && - header.pfABitMask == 0xFF000000) { - return D3DFMT_A8R8G8B8; - } - } else { - if (getDepth() == 24 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF) { - return D3DFMT_R8G8B8; - } else if (getDepth() == 32 && - header.pfRBitMask == 0x00FF0000 && - header.pfGBitMask == 0x0000FF00 && - header.pfBBitMask == 0x000000FF) { - return D3DFMT_X8R8G8B8; - } - } - } - - return D3DFMT_UNKNOWN; - } - - /** Indicates whether this texture is compressed. */ - public boolean isCompressed() { - return (getCompressionFormat() != 0); - } - - /** If this surface is compressed, returns the kind of compression - used (DXT1..DXT5). */ - public int getCompressionFormat() { - return header.pfFourCC; - } - - /** Width of the texture (or the top-most mipmap if mipmaps are - present) */ - public int getWidth() { - return header.width; - } - - /** Height of the texture (or the top-most mipmap if mipmaps are - present) */ - public int getHeight() { - return header.height; - } - - /** Total number of bits per pixel. Only valid if DDPF_RGB is - present. For A8R8G8B8, would be 32. */ - public int getDepth() { - return header.pfRGBBitCount; - } - - /** Number of mip maps in the texture */ - public int getNumMipMaps() { - if (!isSurfaceDescFlagSet(DDSD_MIPMAPCOUNT)) { - return 0; - } - return header.mipMapCountOrAux; - } - - /** Gets the <i>i</i>th mipmap data (0..getNumMipMaps() - 1) */ - public ImageInfo getMipMap(int map) { - if (isCompressed()) { - throw new RuntimeException("Sorry, compressed textures not supported yet"); - } - // Figure out how far to seek - int seek = 4 + header.size; - for (int i = 0; i < map; i++) { - seek += mipMapSizeInBytes(i); - } - buf.limit(seek + mipMapSizeInBytes(map)); - buf.position(seek); - ByteBuffer next = buf.slice(); - buf.position(0); - buf.limit(buf.capacity()); - return new ImageInfo(next, mipMapWidth(map), mipMapHeight(map)); - } - - /** Returns an array of ImageInfos corresponding to all mipmap - levels of this DDS file. */ - public ImageInfo[] getAllMipMaps() { - int numLevels = getNumMipMaps(); - if (numLevels == 0) { - numLevels = 1; - } - ImageInfo[] result = new ImageInfo[numLevels]; - for (int i = 0; i < numLevels; i++) { - result[i] = getMipMap(i); - } - return result; - } - - public void debugPrint() { - PrintStream tty = System.err; - tty.println("Compressed texture: " + isCompressed()); - if (isCompressed()) { - int fmt = getCompressionFormat(); - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < 4; i++) { - char c = (char) (fmt & 0xFF); - buf.append(c); - fmt = fmt >> 8; - } - tty.println("Compression format: 0x" + Integer.toHexString(getCompressionFormat()) + " (" + buf + ")"); - } - tty.println("SurfaceDesc flags:"); - boolean recognizedAny = false; - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_CAPS, "DDSD_CAPS"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_HEIGHT, "DDSD_HEIGHT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_WIDTH, "DDSD_WIDTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PITCH, "DDSD_PITCH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_BACKBUFFERCOUNT, "DDSD_BACKBUFFERCOUNT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ZBUFFERBITDEPTH, "DDSD_ZBUFFERBITDEPTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_ALPHABITDEPTH, "DDSD_ALPHABITDEPTH"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LPSURFACE, "DDSD_LPSURFACE"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_PIXELFORMAT, "DDSD_PIXELFORMAT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_MIPMAPCOUNT, "DDSD_MIPMAPCOUNT"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_LINEARSIZE, "DDSD_LINEARSIZE"); - recognizedAny |= printIfRecognized(tty, header.flags, DDSD_DEPTH, "DDSD_DEPTH"); - if (!recognizedAny) { - tty.println("(none)"); - } - tty.println("Raw SurfaceDesc flags: 0x" + Integer.toHexString(header.flags)); - tty.println("Pixel format flags:"); - recognizedAny = false; - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_RGB, "DDPF_RGB"); - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHA, "DDPF_ALPHA"); - recognizedAny |= printIfRecognized(tty, header.pfFlags, DDPF_ALPHAPIXELS, "DDPF_ALPHAPIXELS"); - if (!recognizedAny) { - tty.println("(none)"); - } - tty.println("Raw pixel format flags: 0x" + Integer.toHexString(header.pfFlags)); - tty.println("Depth: " + getDepth()); - tty.println("Number of mip maps: " + getNumMipMaps()); - int fmt = getPixelFormat(); - tty.print("Pixel format: "); - switch (fmt) { - case D3DFMT_R8G8B8: tty.println("D3DFMT_R8G8B8"); break; - case D3DFMT_A8R8G8B8: tty.println("D3DFMT_A8R8G8B8"); break; - case D3DFMT_X8R8G8B8: tty.println("D3DFMT_X8R8G8B8"); break; - case D3DFMT_UNKNOWN: tty.println("D3DFMT_UNKNOWN"); break; - default: tty.println("(unknown pixel format " + fmt + ")"); break; - } - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private static final int MAGIC = 0x20534444; - - static class Header { - int size; // size of the DDSURFACEDESC structure - int flags; // determines what fields are valid - int height; // height of surface to be created - int width; // width of input surface - int pitchOrLinearSize; - int backBufferCountOrDepth; - int mipMapCountOrAux; // number of mip-map levels requested (in this context) - int alphaBitDepth; // depth of alpha buffer requested - int reserved1; // reserved - int surface; // pointer to the associated surface memory - // NOTE: following two entries are from DDCOLORKEY data structure - // Are overlaid with color for empty cubemap faces (unused in this reader) - int colorSpaceLowValue; - int colorSpaceHighValue; - int destBltColorSpaceLowValue; - int destBltColorSpaceHighValue; - int srcOverlayColorSpaceLowValue; - int srcOverlayColorSpaceHighValue; - int srcBltColorSpaceLowValue; - int srcBltColorSpaceHighValue; - // NOTE: following entries are from DDPIXELFORMAT data structure - // Are overlaid with flexible vertex format description of vertex - // buffers (unused in this reader) - int pfSize; // size of DDPIXELFORMAT structure - int pfFlags; // pixel format flags - int pfFourCC; // (FOURCC code) - // Following five entries have multiple interpretations, not just - // RGBA (but that's all we support right now) - int pfRGBBitCount; // how many bits per pixel - int pfRBitMask; // mask for red bits - int pfGBitMask; // mask for green bits - int pfBBitMask; // mask for blue bits - int pfABitMask; // mask for alpha channel - int ddsCaps1; // Texture and mip-map flags - int ddsCaps2; // Advanced capabilities, not yet used - int ddsCapsReserved1; - int ddsCapsReserved2; - int textureStage; // stage in multitexture cascade - - void read(ByteBuffer buf) throws IOException { - int magic = buf.getInt(); - if (magic != MAGIC) { - throw new IOException("Incorrect magic number 0x" + - Integer.toHexString(magic) + - " (expected " + MAGIC + ")"); - } - - size = buf.getInt(); - flags = buf.getInt(); - height = buf.getInt(); - width = buf.getInt(); - pitchOrLinearSize = buf.getInt(); - backBufferCountOrDepth = buf.getInt(); - mipMapCountOrAux = buf.getInt(); - alphaBitDepth = buf.getInt(); - reserved1 = buf.getInt(); - surface = buf.getInt(); - colorSpaceLowValue = buf.getInt(); - colorSpaceHighValue = buf.getInt(); - destBltColorSpaceLowValue = buf.getInt(); - destBltColorSpaceHighValue = buf.getInt(); - srcOverlayColorSpaceLowValue = buf.getInt(); - srcOverlayColorSpaceHighValue = buf.getInt(); - srcBltColorSpaceLowValue = buf.getInt(); - srcBltColorSpaceHighValue = buf.getInt(); - pfSize = buf.getInt(); - pfFlags = buf.getInt(); - pfFourCC = buf.getInt(); - pfRGBBitCount = buf.getInt(); - pfRBitMask = buf.getInt(); - pfGBitMask = buf.getInt(); - pfBBitMask = buf.getInt(); - pfABitMask = buf.getInt(); - ddsCaps1 = buf.getInt(); - ddsCaps2 = buf.getInt(); - ddsCapsReserved1 = buf.getInt(); - ddsCapsReserved2 = buf.getInt(); - textureStage = buf.getInt(); - } - } - - private int mipMapWidth(int map) { - int width = getWidth(); - for (int i = 0; i < map; i++) { - width >>= 1; - } - return width; - } - - private int mipMapHeight(int map) { - int height = getHeight(); - for (int i = 0; i < map; i++) { - height >>= 1; - } - return height; - } - - private int mipMapSizeInBytes(int map) { - int width = mipMapWidth(map); - int height = mipMapHeight(map); - return width * height * (getDepth() / 8); - } - - private boolean printIfRecognized(PrintStream tty, int flags, int flag, String what) { - if ((flags & flag) != 0) { - tty.println(what); - return true; - } - return false; - } -} diff --git a/src/net/java/games/util/DurationTimer.java b/src/net/java/games/util/DurationTimer.java deleted file mode 100644 index 8c7db686c..000000000 --- a/src/net/java/games/util/DurationTimer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -public class DurationTimer { - private long startTime; - private long accumulatedTime; - - public void reset() { - accumulatedTime = 0; - } - - public void start() { - startTime = System.currentTimeMillis(); - } - - public void stop() { - long curTime = System.currentTimeMillis(); - accumulatedTime += (curTime - startTime); - } - - public long getDuration() { - return accumulatedTime; - } - - public float getDurationAsSeconds() { - return (float) accumulatedTime / 1000.0f; - } -} diff --git a/src/net/java/games/util/DxTex.java b/src/net/java/games/util/DxTex.java deleted file mode 100644 index fc7410314..000000000 --- a/src/net/java/games/util/DxTex.java +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import java.nio.*; -import java.awt.image.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.filechooser.*; - -/** Simplified clone of DxTex tool from the DirectX SDK, written in - Java using the DDSReader; tests fetching of texture data */ - -public class DxTex { - private InternalFrameListener frameListener; - private File defaultDirectory; - private JDesktopPane desktop; - private static String endl = System.getProperty("line.separator"); - private JMenu mipMapMenu; - - public static void main(String[] args) { - new DxTex().run(args); - } - - private void run(String[] args) { - defaultDirectory = new File(System.getProperty("user.dir")); - JFrame frame = new JFrame("DirectX Texture Tool"); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - JMenuBar menuBar = new JMenuBar(); - JMenu menu = createMenu("File", 'F', 0); - JMenuItem item = - createMenuItem("Open...", - new ActionListener() { - public void actionPerformed(ActionEvent e) { - openFile(); - } - }, - KeyEvent.VK_O, InputEvent.CTRL_MASK, - 'O', 0); - menu.add(item); - item = - createMenuItem("Exit", - new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }, - KeyEvent.VK_Q, InputEvent.CTRL_MASK, - 'x', 1); - menu.add(item); - menuBar.add(menu); - - menu = createMenu("MipMap", 'M', 0); - menu.setEnabled(false); - mipMapMenu = menu; - menuBar.add(menu); - - frame.setJMenuBar(menuBar); - - desktop = new JDesktopPane(); - frame.getContentPane().add(desktop); - frame.setSize(640, 480); - frame.show(); - - frameListener = new InternalFrameAdapter() { - public void internalFrameActivated(InternalFrameEvent e) { - JInternalFrame ifr = e.getInternalFrame(); - if (ifr instanceof ImageFrame) { - // Recompute entries in mip map menu - final ImageFrame frame = (ImageFrame) ifr; - if (frame.getNumMipMaps() > 0) { - mipMapMenu.removeAll(); - // Add entries - for (int i = 0; i < frame.getNumMipMaps(); i++) { - final int map = i; - JMenuItem item; - String title = "Level " + (i + 1); - ActionListener listener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - frame.setMipMapLevel(map); - } - }); - } - }; - if (i < 9) { - char c = (char) ('0' + i + 1); - item = createMenuItem(title, listener, c, 6); - } else { - item = createMenuItem(title, listener); - } - mipMapMenu.add(item); - } - mipMapMenu.setEnabled(true); - } else { - mipMapMenu.setEnabled(false); - } - } else { - mipMapMenu.setEnabled(false); - } - } - - public void internalFrameClosing(InternalFrameEvent e) { - desktop.remove(e.getInternalFrame()); - desktop.invalidate(); - desktop.validate(); - desktop.repaint(); - // THIS SHOULD NOT BE NECESSARY - desktop.requestFocus(); - } - - public void internalFrameClosed(InternalFrameEvent e) { - JInternalFrame ifr = e.getInternalFrame(); - if (ifr instanceof ImageFrame) { - ((ImageFrame) ifr).close(); - } - } - }; - - for (int i = 0; i < args.length; i++) { - final File file = new File(args[i]); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - openFile(file); - } - }); - } - } - - //---------------------------------------------------------------------- - // Actions - // - - private void openFile() { - JFileChooser chooser = new JFileChooser(defaultDirectory); - chooser.setMultiSelectionEnabled(false); - chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() { - public boolean accept(File f) { - return (f.isDirectory() || - f.getName().endsWith(".dds")); - } - - public String getDescription() { - return "Texture files (*.dds)"; - } - }); - - int res = chooser.showOpenDialog(null); - if (res == JFileChooser.APPROVE_OPTION) { - final File file = chooser.getSelectedFile(); - defaultDirectory = file.getParentFile(); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - openFile(file); - } - }); - } - } - - private void openFile(File file) { - try { - DDSReader reader = new DDSReader(); - reader.loadFile(file.getAbsolutePath()); - showImage(file.getName(), reader, 0); - } catch (IOException e) { - showMessageDialog("Error while opening file:" + endl + - exceptionToString(e), - "Error opening file", - JOptionPane.WARNING_MESSAGE); - } - } - - //---------------------------------------------------------------------- - // Image display - // - - private void showImage(String filename, DDSReader reader, int mipMapLevel) { - try { - ImageFrame fr = new ImageFrame(filename, reader, mipMapLevel); - desktop.add(fr); - fr.show(); - } catch (Exception e) { - showMessageDialog("Error while loading file:" + endl + - exceptionToString(e), - "Error loading file", - JOptionPane.WARNING_MESSAGE); - } - } - - class ImageFrame extends JInternalFrame { - private String filename; - private DDSReader reader; - private int mipMapLevel; - private int curWidth; - private int curHeight; - private JLabel label; - - ImageFrame(String filename, DDSReader reader, int mipMapLevel) { - super(); - this.filename = filename; - this.reader = reader; - - addInternalFrameListener(frameListener); - label = new JLabel(); - JScrollPane scroller = new JScrollPane(label); - getContentPane().add(scroller); - setSize(400, 400); - setResizable(true); - setIconifiable(true); - setClosable(true); - setMipMapLevel(mipMapLevel); - } - - int getNumMipMaps() { - return reader.getNumMipMaps(); - } - - void setMipMapLevel(int level) { - mipMapLevel = level; - computeImage(); - resetTitle(); - } - - void close() { - System.err.println("Closing files"); - reader.close(); - } - - private void computeImage() { - // Get image data - reader.getNumMipMaps(); - DDSReader.ImageInfo info = reader.getMipMap(mipMapLevel); - int width = info.getWidth(); - int height = info.getHeight(); - curWidth = width; - curHeight = height; - ByteBuffer data = info.getData(); - - // Build ImageIcon out of image data - BufferedImage img = new BufferedImage(width, height, - BufferedImage.TYPE_3BYTE_BGR); - WritableRaster dst = img.getRaster(); - - int skipSize; - if (reader.getPixelFormat() == DDSReader.D3DFMT_A8R8G8B8) { - skipSize = 4; - } else if (reader.getPixelFormat() == DDSReader.D3DFMT_R8G8B8) { - skipSize = 3; - } else { - reader.close(); - throw new RuntimeException("Unsupported pixel format " + reader.getPixelFormat()); - } - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - // NOTE: highly suspicious that A comes fourth in - // A8R8G8B8...not really ARGB, but RGBA (like OpenGL) - dst.setSample(x, y, 0, data.get(skipSize * (width * y + x) + 2) & 0xFF); - dst.setSample(x, y, 1, data.get(skipSize * (width * y + x) + 1) & 0xFF); - dst.setSample(x, y, 2, data.get(skipSize * (width * y + x) + 0) & 0xFF); - } - } - - label.setIcon(new ImageIcon(img)); - } - - private void resetTitle() { - setTitle(filename + " (" + curWidth + "x" + curHeight + - ", mipmap " + (1 + mipMapLevel) + " of " + - reader.getNumMipMaps() + ")"); - } - } - - - //---------------------------------------------------------------------- - // Menu and menu item creation - // - - private static JMenu createMenu(String name, char mnemonic, int mnemonicPos) { - JMenu menu = new JMenu(name); - menu.setMnemonic(mnemonic); - menu.setDisplayedMnemonicIndex(mnemonicPos); - return menu; - } - - private static JMenuItem createMenuItem(String name, ActionListener l) { - JMenuItem item = new JMenuItem(name); - item.addActionListener(l); - return item; - } - - private static JMenuItem createMenuItemInternal(String name, ActionListener l, int accelerator, int modifiers) { - JMenuItem item = createMenuItem(name, l); - item.setAccelerator(KeyStroke.getKeyStroke(accelerator, modifiers)); - return item; - } - - private static JMenuItem createMenuItem(String name, ActionListener l, int accelerator) { - return createMenuItemInternal(name, l, accelerator, 0); - } - - private static JMenuItem createMenuItem(String name, ActionListener l, char mnemonic, int mnemonicPos) { - JMenuItem item = createMenuItem(name, l); - item.setMnemonic(mnemonic); - item.setDisplayedMnemonicIndex(mnemonicPos); - return item; - } - - private static JMenuItem createMenuItem(String name, - ActionListener l, - int accelerator, - int acceleratorMods, - char mnemonic, - int mnemonicPos) { - JMenuItem item = createMenuItemInternal(name, l, accelerator, acceleratorMods); - item.setMnemonic(mnemonic); - item.setDisplayedMnemonicIndex(mnemonicPos); - return item; - } - - private void showMessageDialog(final String message, final String title, final int jOptionPaneKind) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - JOptionPane.showInternalMessageDialog(desktop, message, title, jOptionPaneKind); - } - }); - } - - private static String exceptionToString(Exception e) { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - PrintStream s = new PrintStream(bos); - e.printStackTrace(s); - return bos.toString(); - } -} diff --git a/src/net/java/games/util/LEDataInputStream.java b/src/net/java/games/util/LEDataInputStream.java deleted file mode 100644 index f8fc90946..000000000 --- a/src/net/java/games/util/LEDataInputStream.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.FilterInputStream; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.EOFException; -import java.io.IOException; - -/** - * Little Endian Data Input Stream. - * - * This class implements an input stream filter to allow reading - * of java native datatypes from an input stream which has those - * native datatypes stored in a little endian byte order.<p> - * - * This is the sister class of the DataInputStream which allows - * for reading of java native datatypes from an input stream with - * the datatypes stored in big endian byte order.<p> - * - * This class implements the minimum required and calls DataInputStream - * for some of the required methods for DataInput.<p> - * - * Not all methods are implemented due to lack of immediatte requirement - * for that functionality. It is not clear if it is ever going to be - * functionally required to be able to read UTF data in a LittleEndianManner<p> - * - * @author Robin Luiten - * @version 1.1 15/Dec/1997 - */ -public class LEDataInputStream extends FilterInputStream implements DataInput -{ - /** - * To reuse some of the non endian dependent methods from - * DataInputStreams methods. - */ - DataInputStream dataIn; - - public LEDataInputStream(InputStream in) - { - super(in); - dataIn = new DataInputStream(in); - } - - public void close() throws IOException - { - dataIn.close(); // better close as we create it. - // this will close underlying as well. - } - - public synchronized final int read(byte b[]) throws IOException - { - return dataIn.read(b, 0, b.length); - } - - public synchronized final int read(byte b[], int off, int len) throws IOException - { - int rl = dataIn.read(b, off, len); - return rl; - } - - public final void readFully(byte b[]) throws IOException - { - dataIn.readFully(b, 0, b.length); - } - - public final void readFully(byte b[], int off, int len) throws IOException - { - dataIn.readFully(b, off, len); - } - - public final int skipBytes(int n) throws IOException - { - return dataIn.skipBytes(n); - } - - public final boolean readBoolean() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return (ch != 0); - } - - public final byte readByte() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return (byte)(ch); - } - - public final int readUnsignedByte() throws IOException - { - int ch = dataIn.read(); - if (ch < 0) - throw new EOFException(); - return ch; - } - - public final short readShort() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (short)((ch1 << 0) + (ch2 << 8)); - } - - public final int readUnsignedShort() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (ch1 << 0) + (ch2 << 8); - } - - public final char readChar() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - if ((ch1 | ch2) < 0) - throw new EOFException(); - return (char)((ch1 << 0) + (ch2 << 8)); - } - - public final int readInt() throws IOException - { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - int ch3 = dataIn.read(); - int ch4 = dataIn.read(); - if ((ch1 | ch2 | ch3 | ch4) < 0) - throw new EOFException(); - return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); - } - - public final long readLong() throws IOException - { - int i1 = readInt(); - int i2 = readInt(); - return ((long)(i1) & 0xFFFFFFFFL) + (i2 << 32); - } - - public final float readFloat() throws IOException - { - return Float.intBitsToFloat(readInt()); - } - - public final double readDouble() throws IOException - { - return Double.longBitsToDouble(readLong()); - } - - /** - * dont call this it is not implemented. - * @return empty new string - **/ - public final String readLine() throws IOException - { - return new String(); - } - - /** - * dont call this it is not implemented - * @return empty new string - **/ - public final String readUTF() throws IOException - { - return new String(); - } - - /** - * dont call this it is not implemented - * @return empty new string - **/ - public final static String readUTF(DataInput in) throws IOException - { - return new String(); - } -} - diff --git a/src/net/java/games/util/TGAImage.java b/src/net/java/games/util/TGAImage.java deleted file mode 100644 index 8963109d0..000000000 --- a/src/net/java/games/util/TGAImage.java +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package net.java.games.util; - -import java.io.*; -import net.java.games.jogl.*; - -/** - * Targa image reader adapted from sources of the <a href = - * "http://java.sun.com/products/jimi/">Jimi</a> image I/O class library. - * - * <P> - * - * Image decoder for image data stored in TGA file format. - * Currently only the original TGA file format is supported. This is - * because the new TGA format has data at the end of the file, getting - * to the end of a file in an InputStream orient environment presents - * several difficulties which are avoided at the moment. - * - * <P> - * - * This is a simple decoder and is only setup to load a single image - * from the input stream - * - * <P> - * - * @author Robin Luiten - * @author Kenneth Russell - * @version $Revision$ - */ - -public class TGAImage { - private Header header; - private int format; - private byte[] data; - - private TGAImage(Header header) { - this.header = header; - } - - /** - * This class reads in all of the TGA image header in addition it also - * reads in the imageID field as it is convenient to handle that here. - * - * @author Robin Luiten - * @version 1.1 - */ - public static class Header { - /** Set of possible file format TGA types */ - public final static int TYPE_NEW = 0; - public final static int TYPE_OLD = 1; - public final static int TYPE_UNK = 2; // cant rewind stream so unknown for now. - - /** Set of possible image types in TGA file */ - public final static int NO_IMAGE = 0; // no image data - public final static int UCOLORMAPPED = 1; // uncompressed color mapped image - public final static int UTRUECOLOR = 2; // uncompressed true color image - public final static int UBLACKWHITE = 3; // uncompressed black and white image - public final static int COLORMAPPED = 9; // compressed color mapped image - public final static int TRUECOLOR = 10; // compressed true color image - public final static int BLACKWHITE = 11; // compressed black and white image - - /** Field image descriptor bitfield values definitions */ - public final static int ID_ATTRIBPERPIXEL = 0xF; - public final static int ID_LEFTTORIGHT = 0x10; - public final static int ID_TOPTOBOTTOM = 0x20; - public final static int ID_INTERLEAVE = 0xC0; - - /** Field image descriptor / interleave values */ - public final static int I_NOTINTERLEAVED = 0; - public final static int I_TWOWAY = 1; - public final static int I_FOURWAY = 2; - - /** Type of this TGA file format */ - private int tgaType; - - /** initial TGA image data fields */ - private int idLength; // byte value - private int colorMapType; // byte value - private int imageType; // byte value - - /** TGA image colour map fields */ - private int firstEntryIndex; - private int colorMapLength; - private byte colorMapEntrySize; - - /** TGA image specification fields */ - private int xOrigin; - private int yOrigin; - private int width; - private int height; - private byte pixelDepth; - private byte imageDescriptor; - - /** bitfields in imageDescriptor */ - private byte attribPerPixel; // how many attribute bits per pixel - private boolean leftToRight; // order of data on scan line - private boolean topToBottom; // order scan lines stored - private byte interleave; // how rows are stored in image data - - private byte[] imageIDbuf; - private String imageID; - - public Header(LEDataInputStream in) throws IOException { - int ret; - - tgaType = TYPE_OLD; // dont try and get footer. - - // initial header fields - idLength = in.readUnsignedByte(); - colorMapType = in.readUnsignedByte(); - imageType = in.readUnsignedByte(); - - // color map header fields - firstEntryIndex = in.readUnsignedShort(); - colorMapLength = in.readUnsignedShort(); - colorMapEntrySize = in.readByte(); - - // TGA image specification fields - xOrigin = in.readUnsignedShort(); - yOrigin = in.readUnsignedShort(); - width = in.readUnsignedShort(); - height = in.readUnsignedShort(); - pixelDepth = in.readByte(); - imageDescriptor = in.readByte(); - - attribPerPixel = (byte)(imageDescriptor & ID_ATTRIBPERPIXEL); - leftToRight = (imageDescriptor & ID_LEFTTORIGHT) != 0; // not used ? - topToBottom = (imageDescriptor & ID_TOPTOBOTTOM) != 0; - interleave = (byte)((imageDescriptor & ID_INTERLEAVE) >> 6); - - if (idLength > 0) { - imageIDbuf = new byte[idLength]; - in.read(imageIDbuf, 0, idLength); - imageID = new String(imageIDbuf, "US-ASCII"); - } - } - - public int tgaType() { return tgaType; } - - /** initial TGA image data fields */ - public int idLength() { return idLength; } - public int colorMapType() { return colorMapType; } - public int imageType() { return imageType; } - - /** TGA image colour map fields */ - public int firstEntryIndex() { return firstEntryIndex; } - public int colorMapLength() { return colorMapLength; } - public byte colorMapEntrySize() { return colorMapEntrySize; } - - /** TGA image specification fields */ - public int xOrigin() { return xOrigin; } - public int yOrigin() { return yOrigin; } - public int width() { return width; } - public int height() { return height; } - public byte pixelDepth() { return pixelDepth; } - public byte imageDescriptor() { return imageDescriptor; } - - /** bitfields in imageDescriptor */ - public byte attribPerPixel() { return attribPerPixel; } - public boolean leftToRight() { return leftToRight; } - public boolean topToBottom() { return topToBottom; } - public byte interleave() { return interleave; } - - public byte[] imageIDbuf() { return imageIDbuf; } - public String imageID() { return imageID; } - - public String toString() { - return "TGA Header " + - " id length: " + idLength + - " color map type: "+ colorMapType + - " image type: "+ imageType + - " first entry index: " + firstEntryIndex + - " color map length: " + colorMapLength + - " color map entry size: " + colorMapEntrySize + - " x Origin: " + xOrigin + - " y Origin: " + yOrigin + - " width: "+ width + - " height: "+ height + - " pixel depth: "+ pixelDepth + - " image descriptor: "+ imageDescriptor + - (imageIDbuf == null ? "" : (" ID String: " + imageID)); - } - } - - - /** - * Identifies the image type of the tga image data and loads - * it into the JimiImage structure. This was taken from the - * prototype and modified for the new Jimi structure - */ - private void decodeImage(LEDataInputStream dIn) throws IOException { - switch (header.imageType()) { - case Header.UCOLORMAPPED: - throw new IOException("TGADecoder Uncompressed Colormapped images not supported"); - - case Header.UTRUECOLOR: // pixelDepth 15, 16, 24 and 32 - switch (header.pixelDepth) { - case 16: - throw new IOException("TGADecoder Compressed 16-bit True Color images not supported"); - - case 24: - case 32: - decodeRGBImageU24_32(dIn); - break; - } - break; - - case Header.UBLACKWHITE: - throw new IOException("TGADecoder Uncompressed Grayscale images not supported"); - - case Header.COLORMAPPED: - throw new IOException("TGADecoder Compressed Colormapped images not supported"); - - case Header.TRUECOLOR: - throw new IOException("TGADecoder Compressed True Color images not supported"); - - case Header.BLACKWHITE: - throw new IOException("TGADecoder Compressed Grayscale images not supported"); - } - } - - /** - * This assumes that the body is for a 24 bit or 32 bit for a - * RGB or ARGB image respectively. - */ - private void decodeRGBImageU24_32(LEDataInputStream dIn) throws IOException { - int i; // row index - int j; // column index - int y; // output row index - int raw; // index through the raw input buffer - int rawWidth = header.width() * (header.pixelDepth() / 8); - byte[] rawBuf = new byte[rawWidth]; - data = new byte[rawWidth * header.height()]; - - if (header.pixelDepth() == 24) { - format = GL.GL_BGR_EXT; - } else { - assert header.pixelDepth() == 32; - format = GL.GL_BGRA_EXT; - } - - for (i = 0; i < header.height(); ++i) { - dIn.readFully(rawBuf, 0, rawWidth); - - if (header.topToBottom) - y = header.height - i - 1; // range 0 to (header.height - 1) - else - y = i; - - System.arraycopy(rawBuf, 0, data, y * rawWidth, rawBuf.length); - } - } - - public int getWidth() { return header.width(); } - public int getHeight() { return header.height(); } - - /** Returns the OpenGL format for this texture; e.g. GL.GL_BGR_EXT or GL.GL_BGRA_EXT. */ - public int getGLFormat() { return format; } - - /** Returns the raw data for this texture in the correct - (bottom-to-top) order for calls to glTexImage2D. */ - public byte[] getData() { return data; } - - public static TGAImage read(String filename) throws IOException { - LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(new FileInputStream(filename))); - - Header header = new Header(dIn); - TGAImage res = new TGAImage(header); - res.decodeImage(dIn); - return res; - } -} |