diff --git a/src/java/org/lwjgl/Audio.java b/src/java/org/lwjgl/Audio.java new file mode 100644 index 00000000..faf62a81 --- /dev/null +++ b/src/java/org/lwjgl/Audio.java @@ -0,0 +1,30 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Audio.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Audio.java Created on Aug 1, 2002 by foo + */ +/** + * The audio system. + * + * @author foo + */ +public final class Audio { + + static { + System.loadLibrary(Sys.LIBRARY_NAME); + } + + /** + * No constructor for Audio. + */ + private Audio() { + } + +} diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java new file mode 100644 index 00000000..aac1cfc1 --- /dev/null +++ b/src/java/org/lwjgl/Display.java @@ -0,0 +1,155 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Display.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Display.java Created on Aug 1, 2002 by foo + */ +/** + * Encapsulates everything you need for game display. + * The game display has NO mouse cursor or any other window decorations. + * It must be created before any input devices are created. + * + * @author foo + */ +public final class Display { + + static { + System.loadLibrary(Sys.LIBRARY_NAME); + } + + /** Has the display been created? */ + private static boolean created; + + /** The current display mode, if created */ + private static DisplayMode mode; + + /** A pointer to the native display window */ + private static int handle; + + /** + * No construction allowed. + */ + private Display() { + super(); + } + + /** + * Returns the entire list of display modes as an array, in no + * particular order. Any given mode is not guaranteed to be available and + * the only certain way to check is to call create() and make sure it works. + * Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). + * + * @return an array of all display modes the system reckons it can handle. + */ + public static native DisplayMode[] getAvailableDisplayModes(); + + /** + * Create a display with the specified display mode. If the display is + * already created then no action is taken - the display must first be + * destroyed. + * + * @param displayMode a display mode to choose + * @param fullscreen whether to create the display fullscreen + * @throws Exception if the display mode could not be set + * @see destroy() + */ + public static void setDisplayMode(DisplayMode displayMode, boolean fullscreen) + throws Exception { + + if (created) + return; + + if (!nCreate(displayMode.width, displayMode.height, displayMode.bpp, + displayMode.freq, fullscreen)) + throw new Exception("Failed to set display mode to "+displayMode); + + created = true; + mode = displayMode; + } + + /** + * Native method to create the display. This will set the handle if it is + * successful. + * @return true if the display was successfully created + * @see create() + */ + private static native boolean nCreate( + int width, + int height, + int bpp, + int freq, + boolean fullscreen); + + /** + * Destroy the display and return it to normal. If the display has not yet + * been created no action is taken. + */ + public static void destroy() { + if (!created) + return; + nDestroy(); + created = false; + mode = null; + } + + /** + * Native method to destroy the display. This will reset the handle. + */ + private static native void nDestroy(); + + /** + * @return the current display width. + */ + public static int getWidth() { + return mode.width; + } + + /** + * @return the current display height. + */ + public static int getHeight() { + return mode.height; + } + + /** + * @return the current display depth. + */ + public static int getDepth() { + return mode.bpp; + } + + /** + * @return the current display frequency. + */ + public static int getFrequency() { + return mode.freq; + } + + /** + * @return the current display mode, or null if the display is not yet created + */ + public static DisplayMode getDisplayMode() { + return mode; + } + + /** + * @return the native handle + */ + public static int getHandle() { + return handle; + } + + /** + * @return true if the display has been created + */ + public static boolean isCreated() { + return created; + } + +} diff --git a/src/java/org/lwjgl/DisplayMode.java b/src/java/org/lwjgl/DisplayMode.java new file mode 100644 index 00000000..ae4c1a6b --- /dev/null +++ b/src/java/org/lwjgl/DisplayMode.java @@ -0,0 +1,72 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * DisplayMode.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * DisplayMode.java Created on Aug 1, 2002 by foo + */ +/** + * Describes a display mode. + * + * @author foo + */ +public final class DisplayMode { + + public final int width, height, freq, bpp; + + /** + * Construct a display mode. + * + * @see Display + */ + public DisplayMode(int width, int height, int freq, int bpp) { + this.width = width; + this.height = height; + this.freq = freq; + this.bpp = bpp; + } + + + /* (non-Javadoc) + * @see java.lang.Object#equals(Object) + */ + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof DisplayMode)) + return false; + + DisplayMode dm = (DisplayMode) obj; + return dm.width == width + && dm.height == dm.height + && dm.bpp == bpp + && dm.freq == freq; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return width ^ height ^ freq ^ bpp; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(width); + sb.append(" x "); + sb.append(height); + sb.append(" x "); + sb.append(bpp); + sb.append(" @"); + sb.append(freq); + sb.append("Hz"); + return sb.toString(); + } + +} diff --git a/src/java/org/lwjgl/Math.java b/src/java/org/lwjgl/Math.java new file mode 100644 index 00000000..97c150ca --- /dev/null +++ b/src/java/org/lwjgl/Math.java @@ -0,0 +1,215 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Math.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Math.java Created on Aug 1, 2002 by foo + */ +/** + * A floating point math library, with vector processing capabilities. + * This class differs significantly from its java.lang.Math counterpart + * in that it a) makes no claims about strict accuracy and b) uses degrees + * rather than radians for its functions which are more friendly to use. + * + * @author foo + */ +public final class Math { + + static { + System.loadLibrary(Sys.LIBRARY_NAME); + } + + /** Floating point version of pi */ + public static final float PI = (float)java.lang.Math.PI; + + /* + * Unary matrix operations + */ + /** Perform no operation (except possibly transposition) */ + public static final int MATRIXOP_NOOP = 0; + + /** Negate the vector */ + public static final int MATRIXOP_NEGATE = 1; + + /** Normalise the vector (set to length 1) */ + public static final int MATRIXOP_NORMALIZE = 2; + + /** Compute the inverse matrix */ + public static final int MATRIXOP_INVERT = 3; + + /* + * Binary matrix operations + */ + + /** Multiply left source by right source */ + public static final int MATRIXOP_MULTIPLY = 4; + + /** Add right source to left source */ + public static final int MATRIXOP_ADD = 5; + + /** Subtract right source from left source */ + public static final int MATRIXOP_SUBTRACT = 6; + + /** + * No constructor for Math. + */ + private Math() { + super(); + } + + /** + * @return a random float between 0 and 1. + */ + public static native float random(); + + /** + * Return the sine of theta + * + * @param theta angle in degrees + * @return sin(theta) + */ + public static native float sin(float theta); + + /** + * Return the cosine of theta + * + * @param theta angle in degrees + * @return cos(theta) + */ + public static native float cos(float theta); + + /** + * Return the tangent of theta + * + * @param theta angle in degrees + * @return tan(theta) + */ + public static native float tan(float theta); + + /** + * Return the inverse sine of theta + * + * @param theta angle in degrees + * @return asin(theta) + */ + public static native float asin(float theta); + + /** + * Return the inverse cosine of theta + * + * @param theta angle in degrees + * @return acos(theta) + */ + public static native float acos(float theta); + + /** + * Return the inverse tangent of theta + * + * @param theta angle in degrees + * @return atan(theta) + */ + public static native float atan(float theta); + + /** + * Return the square root of a value + * @param n the number for which you want the square root + * @return sqrt(n) + */ + public static native float sqrt(float n); + + /** + * Apply a unary matrix operation to an array of matrices. + * @param operation A unary vector operation which must be one of + * MATRIXOP_NOOP, + * MATRIXOP_NEGATE, + * MATRIXOP_NORMALIZE, etc. + * @param sourceAddress The address of the source matrices + * @param sourceStride The distance between source matrices, in bytes; if 0, + * it is assumed that the matrices are tightly packed. This is equivalent to + * sourceStride == sourceWidth * sourceHeight * 4 + * @param numElements The number of matrices + * @param sourceWidth The width of the source matrix. Must be > 0. + * @param sourceHeight The height of the source matrix. Must be > 0. + * @param transposeSource The source can be transposed automatically before + * the operation is performed on it + * @param destAddress The results are placed here. This may overlap the + * source and can even be the same, which performs the unary operation + * in-situ + * @param destStride The distance between destination matrices, in bytes, + * similar to sourceStride. Note that if the source and destination address + * overlap and the strides are different then the result is undefined. + * @param transposeDest The destination can be transposed before being + * written + */ + public static native void matrixOp( + int operation, + int sourceAddress, + int sourceStride, + int numElements, + int sourceWidth, + int sourceHeight, + boolean transposeSource, + int destAddress, + int destStride, + boolean transposeDest + ); + + /** + * Apply a binary matrix operation to two arrays of matrices. The results + * are computed by applying the first right element to each of the left + * elements in turn; then the second right element to each left element; + * and so on. + * @param operation A binary vector operation which must be one of + * MATRIXOP_MUTLIPLY, + * MATRIXOP_ADD, + * MATRIXOP_SUBTRACT, etc. + * @param leftSourceAddress The address of the source matrices + * @param leftSourceStride The distance between source matrices, in bytes; if 0, + * it is assumed that the matrices are tightly packed. This is equivalent to + * sourceStride == sourceWidth * sourceHeight * 4 + * @param leftElements The number of left-hand-side matrices + * @param leftSourceWidth The width of the left source matrix. Must be > 0. + * @param leftSourceHeight The height of the left source matrix. Must be > 0. + * @param transposeLeftSource The left source can be transposed automatically before + * the operation is performed on it + * @param rightSourceAddress The address of the right source matrices + * @param rightSourceStride The distance between right source matrices, in bytes; if 0, + * it is assumed that the matrices are tightly packed. This is equivalent to + * sourceStride == sourceWidth * sourceHeight * 4 + * @param rightElements The number of right-hand-side matrices + * @param rightSourceWidth The width of the right source matrix. Must be > 0. + * @param rightSourceHeight The height of the right source matrix. Must be > 0. + * @param transposeRightSource The right source can be transposed automatically before + * the operation is performed on it + * @param destAddress The results are placed here. This may overlap the + * sources and can even be the same, which performs the binary operation + * in-situ + * @param destStride The distance between destination matrices, in bytes, + * similar to sourceStride. Note that if the source and destination address + * overlap and the strides are different then the result is undefined. + * @param transposeDest The destination can be transposed before being + * written + */ + public static native void matrixOp( + int operation, + int leftSourceAddress, + int leftSourceStride, + int leftSourceWidth, + int leftSourceHeight, + boolean transposeLeftSource, + int rightSourceAddress, + int rightSourceStride, + int rightSourceWidth, + int rightSourceHeight, + boolean transposeRightSource, + int destAddress, + int destStride, + boolean transposeDest + ); + +} diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java new file mode 100644 index 00000000..e28627dc --- /dev/null +++ b/src/java/org/lwjgl/Sys.java @@ -0,0 +1,130 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Sys.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Sys.java Created on Aug 1, 2002 by foo + */ +/** + * System class (named Sys so as not to conflict with java.lang.Sys) + * + * @author foo + */ +public final class Sys { + + static { + initialize(); + } + + /** The native library name */ + public static final String LIBRARY_NAME = "lwjgl"; + + /** + * No constructor for Sys. + */ + private Sys() { + } + + /** + * Initialization. + */ + private static void initialize() { + System.loadLibrary(LIBRARY_NAME); + setTime(0.0f); + } + + /** + * Gets the address of a buffer. If the address cannot be obtained for any reason + * then this method returns 0. + * + * @param buffer The buffer for which you want the + * @return the address of the direct buffer passed in + */ + public static native int getDirectBufferAddress(Buffer buffer); + + /** + * Create a direct byte buffer at the specified address with the specified + * capacity. Note that no actual memory allocation is performed. The returned + * direct byte buffer is in native endian order. + * + * @param address The address of the buffer + * @param length The length in bytes that the buffer should have + * @return a direct ByteBuffer + * @throws IllegalArgumentException if address <1 or length <1 + */ + public static native ByteBuffer createDirectBuffer(int address, int length) + throws IllegalArgumentException; + + /** + * Obtains the order of resolution of the hires system timer. The returned resolution + * n describes the worst-case resolution in fractions of a second 1/10^n. + * For example, a system timer which ticks every 1/5000th of a second will return 3 + * to indicate that the resolution is at least as good as 1/1000th of a second. + * The reason for this simplistic measurement of resolution is to cut down on + * the temptation to code to too many specific timer resolutions arbitrarily. + * If no hires timer is available then this method returns -1. Any system incapable of + * a resolution of at least 3 is deemed not to have a hires timer and so this method will + * never return 0, 1, or 2. Furthermore this method will never advertise a + * resolution which cannot be accurately measured by a float. + * + * @return the order of resolution or -1 if no timer is present. + */ + public static native int getTimerResolution(); + + /** + * Gets the current value of the hires timer, in seconds. When the Sys class is first loaded + * the hires timer is reset to 0.0f. If no hires timer is present then this method will always + * return whatever value the timer was last set to. + * + * Because the time is returned as a float, after a certain length of time the + * hires timer can no longer represent time to the accuracy claimed by getTimerResolution(). + * Therefore the time is guaranteed only to be accurate for up to 100 seconds. + * After 100 seconds has elapsed it is advisable to reset the timer. In reality + * you should reset the timer every iteration of your game loop and simply use the + * elapsed time for the iteration to increment your own, possibly more accurate + * timers. + * + * @return the current hires time, in seconds. + */ + public static native float getTime(); + + /** + * Sets the hires timer to a new time. This time may be rounded by the available + * hires timer resolution; if the hires timer resolution is 3, and you specify + * a time of 0.0002f then the time will in fact be set to 0.0f. + * @param time the new time, in seconds + * @see #getTime() + * @see #getTimerResolution() + */ + public static native void setTime(float time); + + /** + * Set the process priority in a system independent way. Because of the various + * differences in operating systems this might or might not have any effect or + * the correct effect. + * + * The default process priority is NORMAL_PRIORITY. + * + * REALTIME_PRIORITY processes should theoretically be the maximum priority of + * any process on the system and may have side effects on I/O and other fundamental + * operating system functions - use with caution. + * + * It is unlikely that any games will want to change the priority of the Java + * process; but there are some other applications for this library which require + * process priority adjustments, such as in soft-realtime graphics rendering + * for broadcast television. + * + * @param priority a priority class, which will be one of REALTIME_PRIORITY, + * HIGH_PRIORITY, NORMAL_PRIORITY, or LOW_PRIORITY. + */ + public static native void setProcessPriority(int priority); + +} diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java new file mode 100644 index 00000000..7f23c49f --- /dev/null +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -0,0 +1,148 @@ +package org.lwjgl.input; + +import java.nio.ByteBuffer; + +import org.lwjgl.Display; +import org.lwjgl.Sys; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Keyboard Created on Aug 1, 2002 by foo + */ +/** + * A raw Keyboard interface. This can be used to poll the current state of the + * keys, or read all the keyboard presses / releases since the last read. + * Buffering must be explicitly enabled; the size of the buffer is determined + * by the native implementation at its discretion. + * + * @author foo + */ +public class Keyboard { + + static { + initialize(); + } + + /** Has the keyboard been created? */ + private static boolean created; + + /** The keys status from the last poll */ + private static final ByteBuffer keyDownBuffer = ByteBuffer.allocateDirect(256); + + /** Address of the keyDown buffer */ + private static final int keyDownAddress = Sys.getDirectBufferAddress(keyDownBuffer); + + /** + * The key events from the last read: a sequence of pairs of key number, + * followed by state. + */ + private static ByteBuffer readBuffer; + + /** Address of the read buffer */ + private static int readBufferAddress; + + /** + * Mouse cannot be constructed. + */ + private Keyboard() { + } + + /** + * Static initialization + */ + private static void initialize() { + System.loadLibrary(Sys.LIBRARY_NAME); + initIDs(); + } + + /** + * Register fields with the native library + */ + private static native void initIDs(); + + /** + * "Create" the keyboard. The display must first have been created. + * @throw Exception if the keyboard could not be created for any reason + */ + public static void create() throws Exception { + if (created) + return; + if (!Display.isCreated()) + throw new Exception("The display has not yet been created."); + if (!nCreate()) + throw new Exception("The keyboard could not be created."); + created = true; + } + + /** + * Native method to create the keyboard + * + * @return true if the keyboard was created + */ + private static native boolean nCreate(); + + /** + * "Destroy" the keyboard + */ + public static void destroy() { + if (!created) + return; + created = false; + nDestroy(); + } + + /** + * Native method the destroy the keyboard + */ + private static native void nDestroy(); + + /** + * Polls the keyboard. + */ + public static void poll() { + assert created : "The keyboard has not been created."; + nPoll(keyDownAddress); + } + + /** + * Native method to poll the keyboard. + * + * @param keyDownBufferAddress the address of a 256-byte buffer to place + * key states in. + */ + private static native void nPoll(int keyDownBufferAddress); + + /** + * Reads the keyboard + */ + public static void read() { + assert created : "The keyboard has not been created."; + nRead(readBufferAddress); + } + + /** + * Native method to read the keyboard buffer + * + * @param readBufferAddress the address of the keyboard buffer + */ + private static native void nRead(int readBufferAddress); + + /** + * Enable keyboard buffering. Must be called after the keyboard is created. + * @return the size of the keyboard buffer in events, or 0 if no buffering + * can be enabled for any reason + */ + public static int enableBuffer() { + assert created : "The keyboard has not been created."; + return nEnableBuffer(); + } + + /** + * Native method to enable the buffer + * @return the size of the buffer allocated, in events (1 event is 2 bytes), + * or 0 if no buffer can be allocated + */ + private static native int nEnableBuffer(); + +} diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java new file mode 100644 index 00000000..2a91dfc9 --- /dev/null +++ b/src/java/org/lwjgl/input/Mouse.java @@ -0,0 +1,109 @@ +package org.lwjgl.input; + +import org.lwjgl.Display; +import org.lwjgl.Sys; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * Mouse.java Created on Aug 1, 2002 by foo + */ +/** + * A raw Mouse interface. This can be used to poll the current state of the + * mouse buttons, and determine the mouse movement delta since the last poll. + * No buffering is available. + * + * Up to 8 buttons are available. The scrolly wheel, if present, is the z + * value. + * + * @author foo + */ +public class Mouse { + + static { + initialize(); + } + + /** Has the mouse been created? */ + private static boolean created; + + /** The mouse buttons status from the last poll */ + private static boolean[] button = new boolean[8]; + + /** Delta X */ + public static int dx; + + /** Delta Y */ + public static int dy; + + /** Delta Z */ + public static int dz; + + /** + * Mouse cannot be constructed. + */ + private Mouse() { + } + + /** + * Static initialization + */ + private static void initialize() { + System.loadLibrary(Sys.LIBRARY_NAME); + initIDs(); + } + + /** + * Register fields with the native library + */ + private static native void initIDs(); + + /** + * "Create" the mouse. The display must first have been created. + * @throw Exception if the mouse could not be created for any reason + */ + public static void create() throws Exception { + if (created) + return; + if (!Display.isCreated()) + throw new Exception("The display has not yet been created."); + if (!nCreate()) + throw new Exception("The mouse could not be created."); + created = true; + } + + /** + * Native method to create the mouse + * + * @return true if the mouse was created + */ + private static native boolean nCreate(); + + /** + * "Destroy" the mouse + */ + public static void destroy() { + if (!created) + return; + created = false; + nDestroy(); + } + + /** + * Native method the destroy the mouse + */ + private static native void nDestroy(); + + /** + * Polls the mouse. + */ + public static void poll() { + assert created : "The mouse has not been created."; + nPoll(); + } + + /** + * Native method to poll the mouse + */ + private static native void nPoll(); +} diff --git a/src/java/org/lwjgl/opengl/BaseGL.java b/src/java/org/lwjgl/opengl/BaseGL.java new file mode 100644 index 00000000..2848df49 --- /dev/null +++ b/src/java/org/lwjgl/opengl/BaseGL.java @@ -0,0 +1,162 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * BaseGL.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +import org.lwjgl.Sys; + +/** + * The base GL functionality (no actual GL methods). + * + * Each instance of GL is only valid in the thread that creates it. + * In addition, only one instance may be the current GL context in any one + * thread. To make a GL instance the current context, use makeCurrent(). + * + * This has been provided as a base class that we can use for either the + * full GL1.4 specification or as a cut-down OpenGL embedded spec. (aka + * a mini-driver). + * + * @author foo + */ +abstract class BaseGL { + + static { + System.loadLibrary(Sys.LIBRARY_NAME); + } + + /** The current rendering context */ + private static BaseGL currentContext; + + /** Has the GL been created yet? */ + private boolean created; + + /** Handle to the native context */ + protected int handle; + + /** This GL will be valid for use in only one thread */ + protected Thread renderThread; + + /** The number of color bits */ + protected final int colorBits; + + /** The number of alpha bits */ + protected final int alphaBits; + + /** The number of depth bits */ + protected final int depthBits; + + /** The number of stencil bits */ + protected final int stencilBits; + + /** + * Constructor for BaseGL. The context is not created at this point; + * to create the GL you must call create(). + * + * @param colorBits the number of color bits (eg. 16, 24, 32) + * @param alphaBits the number of alpha bits (eg. 0 or 8) + * @param depthBits the number of depth bits (eg. 16 or 24) + * @param stencilBits the number of stencil bits (eg. 0 or 8) + * @see create() + */ + public BaseGL(int colorBits, int alphaBits, int depthBits, int stencilBits) { + this.colorBits = colorBits; + this.alphaBits = alphaBits; + this.depthBits = depthBits; + this.stencilBits = stencilBits; + } + + /** + * Creates the GL, with the best match it can get for the specified + * parameters. The display must first have been created. + * + * @throws Exception if the GL could not be created for some reason + */ + public final void create() throws Exception{ + if (created) + return; + if (!nCreate(colorBits, alphaBits, depthBits, stencilBits)) + throw new Exception("GL could not be created."); + created = true; + makeCurrent(); + init(); + } + + /** + * Override to provide any initialization code after creation. + */ + protected void init() { + } + + /** + * Native method to create the GL. If successful then the native handle will + * be set. The GL is created on the current display, which must have been + * created by calling its setDisplayMode() method. + * + * @return true if the GL was created successfully + * @see org.lwjgl.Display#create() + */ + private native boolean nCreate(int colorBits, int alphaBits, int depthBits, int stencilBits); + + /** + * Destroy the GL context. Does nothing if the GL has not yet been created. + */ + public void destroy() { + if (!created) + return; + cleanup(); + created = false; + renderThread = null; + nDestroy(); + } + + /** + * Native method to destroy the GL context + */ + private native void nDestroy(); + + /** + * Provide any cleanup in derived classes here. This method is called + * just before the native context is destroyed. + */ + public void cleanup() { + } + + /** + * Finalizer, marked final. To perform specialized cleanup override the + * cleanup() method. + * + * @see cleanup() + */ + public final void finalize() throws Throwable { + super.finalize(); + + destroy(); + } + + /** + * Make this the current context for the current thread. + */ + public final void makeCurrent() { + assert created : "GL has not been created yet."; + renderThread = Thread.currentThread(); + currentContext = this; + nMakeCurrent(); + } + + /** + * Native method to make this the current thread + */ + private native void nMakeCurrent(); + + /** + * @return true if this is the current rendering context and the correct + * thread + */ + public final boolean isValid() { + return created + && currentContext == this + && Thread.currentThread() == renderThread; + } +} diff --git a/src/java/org/lwjgl/opengl/CoreGL14.java b/src/java/org/lwjgl/opengl/CoreGL14.java new file mode 100644 index 00000000..d39a1585 --- /dev/null +++ b/src/java/org/lwjgl/opengl/CoreGL14.java @@ -0,0 +1,28 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * CoreGL14.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +/** + * The core OpenGL1.4 API, with no extensions. + * + * @author foo + */ +public class CoreGL14 extends BaseGL implements CoreGL14Constants { + + /** + * Constructor for CoreGL14. + */ + public CoreGL14( + int colorBits, + int alphaBits, + int depthBits, + int stencilBits) { + super(colorBits, alphaBits, depthBits, stencilBits); + } + +} + + diff --git a/src/java/org/lwjgl/opengl/CoreGL14Constants.java b/src/java/org/lwjgl/opengl/CoreGL14Constants.java new file mode 100644 index 00000000..3ae6f784 --- /dev/null +++ b/src/java/org/lwjgl/opengl/CoreGL14Constants.java @@ -0,0 +1,19 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * BaseGLConstants.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * CoreGL14Constants.java Created on Aug 1, 2002 by foo + */ +/** + * Defines the core constants for OpenGL 1.4 + * @author foo + */ +public interface CoreGL14Constants { + +} diff --git a/src/java/org/lwjgl/opengl/GL.java b/src/java/org/lwjgl/opengl/GL.java new file mode 100644 index 00000000..a34d4f48 --- /dev/null +++ b/src/java/org/lwjgl/opengl/GL.java @@ -0,0 +1,52 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * GL.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +import org.lwjgl.Sys; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * BaseGLConstants.java Created on Aug 1, 2002 by foo + */ +/** + * The GL itself, with all supported extensions, based on OpenGL 1.4. + * + * @author foo + */ +public class GL extends CoreGL14 implements GLConstants { + + static { + System.loadLibrary(Sys.LIBRARY_NAME); + } + + /** + * Constructor for GL. + */ + public GL(int colorBits, int alphaBits, int depthBits, int stencilBits) { + super(colorBits, alphaBits, depthBits, stencilBits); + } + + /** + * Determine which extensions are available + */ + private void determineAvailableExtensions() { + } + + /* (non-Javadoc) + * @see org.lwjgl.opengl.BaseGL#init() + */ + protected void init() { + super.init(); + + // Right after creation we can go and find out what extensions are + // available. We can't actually determine this beforehand of course + // because the available extensions can only be determined when there's + // an actual rendering context. + determineAvailableExtensions(); + } + +} diff --git a/src/java/org/lwjgl/opengl/GLConstants.java b/src/java/org/lwjgl/opengl/GLConstants.java new file mode 100644 index 00000000..900cf17d --- /dev/null +++ b/src/java/org/lwjgl/opengl/GLConstants.java @@ -0,0 +1,20 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * GLConstants.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +/** + * (C) 2002 Shaven Puppy Ltd + * + * BaseGLConstants.java Created on Aug 1, 2002 by foo + */ +/** + * All GL constants, including all supported extensions. + * + * @author foo + */ +public interface GLConstants extends CoreGL14Constants { + +} diff --git a/src/java/org/lwjgl/opengl/OpenGLException.java b/src/java/org/lwjgl/opengl/OpenGLException.java new file mode 100644 index 00000000..e1ea6359 --- /dev/null +++ b/src/java/org/lwjgl/opengl/OpenGLException.java @@ -0,0 +1,48 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * OpenGLException.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.opengl; + +/** + * Thrown by the debug build library of the LWJGL if any OpenGL operation + * causes an error. + * + * @author foo + */ +public class OpenGLException extends RuntimeException { + + /** + * Constructor for OpenGLException. + */ + public OpenGLException() { + super(); + } + + /** + * Constructor for OpenGLException. + * @param message + */ + public OpenGLException(String message) { + super(message); + } + + /** + * Constructor for OpenGLException. + * @param message + * @param cause + */ + public OpenGLException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructor for OpenGLException. + * @param cause + */ + public OpenGLException(Throwable cause) { + super(cause); + } + +} diff --git a/src/java/org/lwjgl/vector/Matrix2f.java b/src/java/org/lwjgl/vector/Matrix2f.java new file mode 100644 index 00000000..6ab0bca8 --- /dev/null +++ b/src/java/org/lwjgl/vector/Matrix2f.java @@ -0,0 +1,26 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Matrix2f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Matrix2f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Matrix2f { + + /** + * Constructor for Matrix2f. + */ + public Matrix2f() { + super(); + } + +} diff --git a/src/java/org/lwjgl/vector/Matrix3f.java b/src/java/org/lwjgl/vector/Matrix3f.java new file mode 100644 index 00000000..4029a9ce --- /dev/null +++ b/src/java/org/lwjgl/vector/Matrix3f.java @@ -0,0 +1,26 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Matrix3f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Matrix3f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Matrix3f { + + /** + * Constructor for Matrix3f. + */ + public Matrix3f() { + super(); + } + +} diff --git a/src/java/org/lwjgl/vector/Matrix4f.java b/src/java/org/lwjgl/vector/Matrix4f.java new file mode 100644 index 00000000..e1c6f047 --- /dev/null +++ b/src/java/org/lwjgl/vector/Matrix4f.java @@ -0,0 +1,26 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Matrix4f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Matrix4f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Matrix4f { + + /** + * Constructor for Matrix4f. + */ + public Matrix4f() { + super(); + } + +} diff --git a/src/java/org/lwjgl/vector/Vector2f.java b/src/java/org/lwjgl/vector/Vector2f.java new file mode 100644 index 00000000..9d36e47c --- /dev/null +++ b/src/java/org/lwjgl/vector/Vector2f.java @@ -0,0 +1,28 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Vector2f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Vector2f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Vector2f { + + public float x, y; + + /** + * Constructor for Vector2f. + */ + public Vector2f() { + super(); + } + +} diff --git a/src/java/org/lwjgl/vector/Vector3f.java b/src/java/org/lwjgl/vector/Vector3f.java new file mode 100644 index 00000000..8e549591 --- /dev/null +++ b/src/java/org/lwjgl/vector/Vector3f.java @@ -0,0 +1,28 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Vector3f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Vector3f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Vector3f { + + public float x, y, z; + + /** + * Constructor for Vector3f. + */ + public Vector3f() { + super(); + } + +} diff --git a/src/java/org/lwjgl/vector/Vector4f.java b/src/java/org/lwjgl/vector/Vector4f.java new file mode 100644 index 00000000..02731430 --- /dev/null +++ b/src/java/org/lwjgl/vector/Vector4f.java @@ -0,0 +1,28 @@ +/** + * (C) 2002 Shaven Puppy Ltd + * + * Vector4f.java Created on Aug 1, 2002 by foo + */ +package org.lwjgl.vector; + +/** + * (C) 2002 JGL.org + * + * Vector4f.java Created on Aug 1, 2002 by foo + */ +/** + * + * @author foo + */ +public class Vector4f { + + public float x, y, z, w; + + /** + * Constructor for Vector4f. + */ + public Vector4f() { + super(); + } + +}