aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2001-02-23 05:08:10 +0000
committerSven Gothel <[email protected]>2001-02-23 05:08:10 +0000
commit82cd20ed209f12e22e2f5a92719b3be2bb92d8ed (patch)
tree6db7f6e46a2195c49bd20e4c6b42c9b206a920fb /gl4java
parent70be669b0db3713117982dbeeadbb91ed670e901 (diff)
Version 2.6.0.0
Diffstat (limited to 'gl4java')
-rw-r--r--gl4java/GLContext.java.skel242
-rw-r--r--gl4java/GLUFuncJauJNI.java10
-rw-r--r--gl4java/GLUFuncJauJNInf.java1650
-rw-r--r--gl4java/awt/GLAnimCanvas.java1489
-rw-r--r--gl4java/awt/GLCanvas.java1877
-rwxr-xr-xgl4java/awt/GLImageCanvas.java811
-rw-r--r--gl4java/swing/GLAnimJPanel.java92
-rw-r--r--gl4java/swing/GLJPanel.java1798
8 files changed, 4156 insertions, 3813 deletions
diff --git a/gl4java/GLContext.java.skel b/gl4java/GLContext.java.skel
index 56750cc..c011f94 100644
--- a/gl4java/GLContext.java.skel
+++ b/gl4java/GLContext.java.skel
@@ -319,60 +319,6 @@ public class GLContext extends Object
protected boolean offScreenRenderer = false;
/**
- * Do we use doubleBuffer - of course !
- * This is the default visual property ... !
- *
- * This is set via the constructor !
- *
- * @see gl4java.GLContext#isDoubleBuffer
- * @see gl4java.GLContext#GLContext
- */
- protected boolean doubleBuffer = true;
-
- /**
- * Visual pre-set for stencil-bit number, default: 0
- *
- * @see gl4java.GLContext#GLContext
- */
- protected int stencilBits = 0;
-
- /**
- * Visual pre-set for accumulator-size number, default: 0
- *
- * This value has a special behavior.
- * For input - within the contructor,
- * it is the value for each component !
- *
- * The output value, after the constructor returns,
- * it is the summary of all accumulation bits of all components !
- *
- * @see gl4java.GLContext#GLContext
- */
- protected int accumSize = 0;
-
- /**
- * Do we use stereoView - not yet ;-) !
- * This is the default visual property ... !
- *
- * This is set via the constructor !
- *
- * @see gl4java.GLContext#isStereoView
- * @see gl4java.GLContext#GLContext
- */
- protected boolean stereoView = false;
-
- /**
- * Do we use True-Color RGBA - of course ;-) !
- * This is the default visual property ... !
- *
- * This is set via the constructor !
- *
- * @see gl4java.GLContext#isRGBA
- * @see gl4java.GLContext#GLContext
- */
- protected boolean rgba = true;
-
- /**
* We normally do not have to create an own Window !
* This is the default visual property ... !
* But some machines, like SGI's Irix,
@@ -388,6 +334,15 @@ public class GLContext extends Object
protected boolean createOwnWindow = false;
/**
+ * The GLCapabilities ..
+ *
+ * This is set via the constructor !
+ *
+ * @see gl4java.GLContext#GLContext
+ */
+ protected GLCapabilities glCaps = null;
+
+ /**
* The resize flag, which indicates a resize for the next paint function !
* This flag will bes set in 'componentResized'
* and will be cleared after resize (glViewport) in sDisplay !!
@@ -475,56 +430,74 @@ public class GLContext extends Object
* @see gl4java.GLContext#OsX11
* @see gl4java.GLContext#OsMac
*/
- public final int getNativeOSType() { return osType; }
+ public static int getNativeOSType() { return osType; }
+
+ public static String getNativeOSName() { return osName; }
/**
* Query the visual property ... !
*
* After a GLContext is created, this property can be queried !
*
- * @see gl4java.GLContext#doubleBuffer
+ * @see gl4java.GLContext#glCaps
* @see gl4java.GLContext#GLContext
*/
- public final boolean isDoubleBuffer() { return doubleBuffer; }
+ public final GLCapabilities getGLCapabilities() { return glCaps; }
/**
* Query the visual property ... !
*
* After a GLContext is created, this property can be queried !
*
- * @see gl4java.GLContext#stereoView
+ * @see gl4java.GLContext#glCaps
* @see gl4java.GLContext#GLContext
*/
- public final int getStencilBitNumber() { return stencilBits; }
+ public final boolean isDoubleBuffer() { return glCaps.getDoubleBuffered(); }
/**
* Query the visual property ... !
*
* After a GLContext is created, this property can be queried !
*
+ * @see gl4java.GLContext#glCaps
* @see gl4java.GLContext#GLContext
*/
- public final int getAccumSize() { return accumSize; }
+ public final int getStencilBitNumber() { return glCaps.getStencilBits(); }
/**
* Query the visual property ... !
*
* After a GLContext is created, this property can be queried !
*
- * @see gl4java.GLContext#stereoView
+ * @see gl4java.GLContext#glCaps
* @see gl4java.GLContext#GLContext
*/
- public final boolean isStereoView() { return stereoView; }
+ public final int getAccumSize()
+ { return glCaps.getAccumRedBits()+
+ glCaps.getAccumGreenBits()+
+ glCaps.getAccumBlueBits()+
+ glCaps.getAccumAlphaBits();
+ }
/**
* Query the visual property ... !
*
* After a GLContext is created, this property can be queried !
*
- * @see gl4java.GLContext#rgba
+ * @see gl4java.GLContext#glCaps
* @see gl4java.GLContext#GLContext
*/
- public final boolean isRGBA() { return rgba; }
+ public final boolean isStereoView() { return glCaps.getStereo(); }
+
+ /**
+ * Query the visual property ... !
+ *
+ * After a GLContext is created, this property can be queried !
+ *
+ * @see gl4java.GLContext#glCaps
+ * @see gl4java.GLContext#GLContext
+ */
+ public final boolean isRGBA() { return glCaps.getTrueColor(); }
/**
* Query the visual property ... !
@@ -578,9 +551,10 @@ public class GLContext extends Object
String gluLibName
)
{
- System.out.println("GLContext.loadNativeLibraries ...");
if(libsLoaded) return true;
- System.out.println("GLContext.loadNativeLibraries will do it !");
+
+ if(gljClassDebug)
+ System.out.println("GLContext.loadNativeLibraries will do it !");
String libNames[] = null;
@@ -790,6 +764,7 @@ public class GLContext extends Object
String gluName = defGLUFuncClass;
boolean info=false;
boolean exitImmediatly=false;
+ boolean noFactory=false;
int i = 0;
boolean ok=true;
@@ -803,6 +778,7 @@ public class GLContext extends Object
System.out.println(" -gluclass <glu-class> \t choose a custom the gl4java-glu-class java GLUFunc implementation (default: GLUFuncJauJNI)");
System.out.println(" -info \t creates a GLContext and prints all avaiable information of GL/GLU and GL4Java");
System.out.println(" -infotxt \t like -info, but exits straight after -info !");
+ System.out.println(" -noFactory \t creates a GLContext without the new GLDrawableFactory API");
System.exit(0);
}
@@ -823,6 +799,8 @@ public class GLContext extends Object
} else if(args[i].equals("-infotxt")) {
info=true;
exitImmediatly=true;
+ } else if(args[i].equals("-noFactory")) {
+ noFactory=true;
} else {
System.out.println("illegal arg "+i+": "+args[i]);
ok=false;
@@ -860,7 +838,21 @@ public class GLContext extends Object
Frame f = new Frame("GL4Java Info");
f.setSize(10, 10);
- Canvas cvs = new Canvas();
+ Canvas cvs = null;
+ GLCapabilities glCaps = new GLCapabilities();
+ gl4java.drawable.GLDrawableFactory df =
+ gl4java.drawable.GLDrawableFactory.getFactory();
+
+ if(noFactory ||
+ !(df instanceof gl4java.drawable.SunJDK13GLDrawableFactory)
+ )
+ {
+ cvs = new Canvas();
+ } else {
+ gl4java.drawable.SunJDK13GLDrawableFactory sdf =
+ (gl4java.drawable.SunJDK13GLDrawableFactory)df;
+ cvs = new Canvas(sdf.getGraphicsConfiguration(glCaps));
+ }
cvs.setVisible(true);
cvs.setSize(50,50);
f.add("Center", cvs);
@@ -869,7 +861,7 @@ public class GLContext extends Object
// f.pack();
f.setVisible(true);
- GLContext glj = new GLContext(cvs, gl, glu);
+ GLContext glj = new GLContext( cvs, gl, glu, glCaps, null);
Frame fInfo = glj.gljShowVersions();
@@ -891,6 +883,8 @@ public class GLContext extends Object
}
}
+ public static int getJVMVersionMajor() { return jvmVersionMajor; }
+ public static int getJVMVersionMinor() { return jvmVersionMinor; }
public static String getJVMVendor() { return jvmVendor; }
public static boolean isNetscapeJVM() { return isNetscapeJvm; }
public static boolean isMicrosoftJVM() { return isMicrosoftJvm; }
@@ -923,23 +917,17 @@ public class GLContext extends Object
* @param glf the users selected GLUFunc implementation
* @param _createOwnWindow the flag for the visual property
* @param _offScreenRenderer the flag for the visual property
- * @param _doubleBuffer the flag for the visual property
- * @param _stereoView the flag for the visual property
- * @param _rgba the flag for the visual property
- * @param _stencilBits the flag for the visual property
- * @param _accumSize the flag for the visual property
- * @param _sharedGLContext the shared GLContext
* @param _offScrnSize the fixed offscreen pixmap size
+ * @param _glCaps the GLCapabilities
+ * @param _sharedGLContext the shared GLContext
*
*/
protected GLContext( Component comp, GLFunc glf, GLUFunc gluf,
- boolean _createOwnWindow, boolean _offScreenRenderer,
- boolean _doubleBuffer, boolean _stereoView,
- boolean _rgba,
- int _stencilBits,
- int _accumSize,
- GLContext _sharedGLContext,
- Dimension _offScrnSize
+ boolean _createOwnWindow,
+ boolean _offScreenRenderer,
+ Dimension _offScrnSize,
+ GLCapabilities _glCaps,
+ GLContext _sharedGLContext
)
{
super( );
@@ -949,13 +937,10 @@ public class GLContext extends Object
glu = gluf ;
createOwnWindow = _createOwnWindow;
offScreenRenderer = _offScreenRenderer;
- doubleBuffer=_doubleBuffer;
- stereoView=_stereoView;
- rgba=_rgba;
- stencilBits=_stencilBits;
- accumSize=_accumSize;
offScrnSize= _offScrnSize;
+ glCaps = _glCaps;
+
this.sharedGLContext = _sharedGLContext;
if(sharedGLContext != null)
sharedGLContextNative =
@@ -1009,6 +994,77 @@ public class GLContext extends Object
System.out.println("GLContext GLContext() failed");
}
}
+ /**
+ *
+ * Constructor
+ *
+ * This privat constructor is for all possible
+ * compinations and is called from the customized
+ * constructors.
+ *
+ * First the GLContext is fetched from the Component itself !
+ * To do so, the Component is set visible if it is not !
+ *
+ * If a GLContext is fetched, it is current !
+ *
+ * @param comp the users component for the gl-context
+ * @param glf the users selected GLFunc implementation
+ * @param glf the users selected GLUFunc implementation
+ * @param _createOwnWindow the flag for the visual property
+ * @param _offScreenRenderer the flag for the visual property
+ * @param _doubleBuffer the flag for the visual property
+ * @param _stereoView the flag for the visual property
+ * @param _rgba the flag for the visual property
+ * @param _stencilBits the flag for the visual property
+ * @param _accumSize the flag for the visual property
+ * @param _sharedGLContext the shared GLContext
+ * @param _offScrnSize the fixed offscreen pixmap size
+ *
+ */
+ protected GLContext( Component comp, GLFunc glf, GLUFunc gluf,
+ boolean _createOwnWindow, boolean _offScreenRenderer,
+ boolean _doubleBuffer, boolean _stereoView,
+ boolean _rgba,
+ int _stencilBits,
+ int _accumSize,
+ GLContext _sharedGLContext,
+ Dimension _offScrnSize
+ )
+ {
+ this( comp, glf, gluf, _createOwnWindow,
+ _offScreenRenderer, _offScrnSize,
+ new GLCapabilities(_doubleBuffer, _stereoView,
+ _rgba, _stencilBits,
+ _accumSize, _accumSize,
+ _accumSize, _accumSize),
+ _sharedGLContext);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * First the GLContext is fetched from the Component itself !
+ * To do so, the Component is set visible if it is not !
+ *
+ * If a GLContext is fetched, it is current !
+ *
+ * @param comp the users component for the gl-context
+ * @param glf the users selected GLFunc implementation
+ * @param glf the users selected GLUFunc implementation
+ * @param _glCaps the GLCapabilities
+ * @param _sharedGLContext the shared GLContext
+ *
+ */
+ public GLContext( Component comp, GLFunc glf, GLUFunc gluf,
+ GLCapabilities _glCaps,
+ GLContext _sharedGLContext
+ )
+ {
+ this( comp, glf, gluf, false,
+ false, null, _glCaps,
+ _sharedGLContext);
+ }
/**
*
@@ -1719,6 +1775,12 @@ public class GLContext extends Object
{
if( libsLoaded==false ) return ;
+ if(glCaps==null)
+ {
+ System.out.println("Internal error: glCaps not initialized !!");
+ throw new GL4JavaInitException ();
+ }
+
if(pData==0 && !offScreenRenderer && !useJAWT())
{
System.out.println("could not open a GL widget -- Win CONTEXT");
@@ -2252,7 +2314,7 @@ public class GLContext extends Object
return gljSwapNative( displayHandle,
windowHandle,
glContext,
- doubleBuffer);
+ glCaps.getDoubleBuffered());
}
private static final native boolean gljSwapNative( long disp,
@@ -2396,6 +2458,10 @@ public class GLContext extends Object
if(libsLoaded==false || gl==null || glu==null || !gljIsInit())
return null;
+ String jvmstr = "Java Virtual Machine: Version "+ getJVMVersionMajor()+
+ "." + getJVMVersionMinor() +", Vendor: "+
+ getJVMVendor() + "\n" ;
+
String info1= "GL4Java - LGPL-Version" + "\n" +
"-------------------------------------------------\n" +
"-------------------------------------------------\n" +
@@ -2420,6 +2486,8 @@ public class GLContext extends Object
" Version: "+glu.getNativeVersion() + "\n" +
" Vendor : "+glu.getNativeVendor() + "\n" +
"-------------------------------------------------\n" +
+ "\n"+
+ jvmstr +
"\n" ;
String glVen = gl.glGetString(GLFunc.GL_VENDOR);
diff --git a/gl4java/GLUFuncJauJNI.java b/gl4java/GLUFuncJauJNI.java
index 5ba2f08..d0a29ea 100644
--- a/gl4java/GLUFuncJauJNI.java
+++ b/gl4java/GLUFuncJauJNI.java
@@ -32,7 +32,7 @@ public final String getClassVendor ( )
{ return "Jausoft - Sven Goethel Software Development"; }
public final String getClassVersion ( )
-{ return "2.4.1.0"; }
+{ return "2.5.2.0"; }
/**
@@ -819,7 +819,7 @@ public final native long gluNewTess( );
) ;
/* C2J Parser Version 1.5 Beta: Java program parsed successfully. */
-
-
-}
-
+
+
+}
+
diff --git a/gl4java/GLUFuncJauJNInf.java b/gl4java/GLUFuncJauJNInf.java
index f509fe4..046e6df 100644
--- a/gl4java/GLUFuncJauJNInf.java
+++ b/gl4java/GLUFuncJauJNInf.java
@@ -1,825 +1,825 @@
-/* WARNING ! WARNING *** THIS FILE IS GENERATED BY C2J !!!
-
- DO NOT MAKE ANY CHANGES *** MAKE CHANGES IN THE SKELETON FILES !!!
-*/
-
-
-/**
- * @(#) GLUFuncJauJNInf.java
- */
-
-
-package gl4java;
-
-/**
- * The default implementation class for GLU native function mapping
- *
- * @version 2.00, 21. April 1999
- * @author Sven Goethel
- */
-public class GLUFuncJauJNInf
- implements GLUFunc
-{
-
-
-public native String gluErrorString ( int errorCode ) ;
-public native String gluGetString ( int name ) ;
-
-public native String getNativeVendor ( ) ;
-public native String getNativeVersion ( ) ;
-
-public String getClassVendor ( )
-{ return "Jausoft - Sven Goethel Software Development"; }
-
-public String getClassVersion ( )
-{ return "2.4.1.0"; }
-
-
-/**
- * The Callback registry function.
- * To achieve the signature (internal argument signature)
- * you can use the "javap -s <classname>" toolkit of the JDK !
- *
- * @param qobj the quadratic id, fetch with gluNewQuadric
- * @param which the id for the callback type
- * @param methodClassInstance the class instance,
- * which implements the callback-method
- * @param methodName the name of the callback-method
- * @param signature the signature of the callback-method.
- *
- * @see GLUFunc#gluNewQuadric
- */
-public native void gluQuadricCallback(
- long qobj, int which,
- Object methodClassInstance,
- String methodName,
- String signature
- );
-
-/**
- * The Callback registry function.
- * To achieve the signature (internal argument signature)
- * you can use the "javap -s <classname>" toolkit of the JDK !
- *
- * @param nobj the nurbs id, fetch with gluNewNurbsRenderer
- * @param which the id for the callback type
- * @param methodClassInstance the class instance,
- * which implements the callback-method
- * @param methodName the name of the callback-method
- * @param signature the signature of the callback-method.
- *
- * @see GLUFunc#gluNewNurbsRenderer
- */
-public native void gluNurbsCallback(
- long nobj, int which,
- Object methodClassInstance,
- String methodName,
- String signature
- );
-
-
-/**
- * The Callback registry function.
- * To achieve the signature (internal argument signature)
- * you can use the "javap -s <classname>" toolkit of the JDK !
- *
- * @param tobj the tesselation id, fetch with gluNewTess
- * @param which the id for the callback type
- * @param methodClassInstance the class instance,
- * which implements the callback-method
- * @param methodName the name of the callback-method
- * @param signature the signature of the callback-method.
- * @param voidArrayLen1 the optional length of the 1st array
- * in the callback-methods argument-list
- * @param voidArrayLen2 the optional length of the 2nd array
- * in the callback-methods argument-list
- * @param voidArrayLen3 the optional length of the 3rd array
- * in the callback-methods argument-list
- * @param voidArrayLen4 the optional length of the 4th array
- * in the callback-methods argument-list
- * @param voidArrayLen5 the optional length of the 5th array
- * in the callback-methods argument-list
- *
- * @see GLUFunc#gluNewTess
- */
-public native void gluTessCallback(
- long tobj, int which,
- Object methodClassInstance,
- String methodName,
- String signature,
- int voidArrayLen1,
- int voidArrayLen2,
- int voidArrayLen3,
- int voidArrayLen4,
- int voidArrayLen5
- );
-
-/**
- * The Callback de-registry function.
- *
- * @param qobj the quadratic id, for which all callback-methods
- * should be de-registered
- */
-public native void gluDeleteQuadric( long qobj );
-
-/**
- * The Callback de-registry function.
- *
- * @param nobj the nurbs id, for which all callback-methods
- * should be de-registered
- */
-public native void gluDeleteNurbsRenderer( long nobj );
-
-/**
- * The Callback de-registry function.
- *
- * @param tobj the tesselation id, for which all callback-methods
- * should be de-registered
- */
-public native void gluDeleteTess( long tobj );
-
-public native long gluNewQuadric( );
-public native long gluNewNurbsRenderer( );
-public native long gluNewTess( );
-
-/**
- * C2J Parser Version 1.5 Beta
- * Jausoft - Sven Goethel Software Development
- * Reading from file: glu-proto-auto.orig.h . . .
- * Destination-Class: gl4java_GLUFuncJauJNInf !
- */
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluLookAt ( GLdouble eyex , GLdouble eyey , GLdouble eyez , GLdouble centerx , GLdouble centery , GLdouble centerz , GLdouble upx , GLdouble upy , GLdouble upz ) ;
- * </pre>
- */
- public native void gluLookAt (
- double eyex,
- double eyey,
- double eyez,
- double centerx,
- double centery,
- double centerz,
- double upx,
- double upy,
- double upz
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluOrtho2D ( GLdouble left , GLdouble right , GLdouble bottom , GLdouble top ) ;
- * </pre>
- */
- public native void gluOrtho2D (
- double left,
- double right,
- double bottom,
- double top
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluPerspective ( GLdouble fovy , GLdouble aspect , GLdouble zNear , GLdouble zFar ) ;
- * </pre>
- */
- public native void gluPerspective (
- double fovy,
- double aspect,
- double zNear,
- double zFar
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluPickMatrix ( GLdouble x , GLdouble y , GLdouble width , GLdouble height , GLint * viewport ) ;
- * </pre>
- */
- public native void gluPickMatrix (
- double x,
- double y,
- double width,
- double height,
- int[] viewport
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern GLint gluProject ( GLdouble objx , GLdouble objy , GLdouble objz , const GLdouble modelMatrix [ 16 ] , const GLdouble projMatrix [ 16 ] , const GLint viewport [ 4 ] , GLdouble * winx , GLdouble * winy , GLdouble * winz ) ;
- * </pre>
- */
- public native int gluProject (
- double objx,
- double objy,
- double objz,
- double[] modelMatrix,
- double[] projMatrix,
- int[] viewport,
- double[] winx,
- double[] winy,
- double[] winz
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern GLint gluUnProject ( GLdouble winx , GLdouble winy , GLdouble winz , const GLdouble modelMatrix [ 16 ] , const GLdouble projMatrix [ 16 ] , const GLint viewport [ 4 ] , GLdouble * objx , GLdouble * objy , GLdouble * objz ) ;
- * </pre>
- */
- public native int gluUnProject (
- double winx,
- double winy,
- double winz,
- double[] modelMatrix,
- double[] projMatrix,
- int[] viewport,
- double[] objx,
- double[] objy,
- double[] objz
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern GLint gluScaleImage ( GLenum format , GLsizei widthin , GLsizei heightin , GLenum typein , const char * datain , GLsizei widthout , GLsizei heightout , GLenum typeout , char * dataout ) ;
- * </pre>
- */
- public native int gluScaleImage (
- int format,
- int widthin,
- int heightin,
- int typein,
- byte[] datain,
- int widthout,
- int heightout,
- int typeout,
- byte[] dataout
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern GLint gluBuild1DMipmaps ( GLenum target , GLint components , GLint width , GLenum format , GLenum type , const void * data ) ;
- * </pre>
- */
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- byte[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- short[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- int[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- float[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- double[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- boolean[] data
- ) ;
- public native int gluBuild1DMipmaps (
- int target,
- int components,
- int width,
- int format,
- int type,
- long[] data
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern GLint gluBuild2DMipmaps ( GLenum target , GLint components , GLint width , GLint height , GLenum format , GLenum type , const void * data ) ;
- * </pre>
- */
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- byte[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- short[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- int[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- float[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- double[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- boolean[] data
- ) ;
- public native int gluBuild2DMipmaps (
- int target,
- int components,
- int width,
- int height,
- int format,
- int type,
- long[] data
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluQuadricDrawStyle ( GLUquadricObj * quadObject , GLenum drawStyle ) ;
- * </pre>
- */
- public native void gluQuadricDrawStyle (
- long quadObject,
- int drawStyle
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluQuadricOrientation ( GLUquadricObj * quadObject , GLenum orientation ) ;
- * </pre>
- */
- public native void gluQuadricOrientation (
- long quadObject,
- int orientation
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluQuadricNormals ( GLUquadricObj * quadObject , GLenum normals ) ;
- * </pre>
- */
- public native void gluQuadricNormals (
- long quadObject,
- int normals
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluQuadricTexture ( GLUquadricObj * quadObject , GLboolean textureCoords ) ;
- * </pre>
- */
- public native void gluQuadricTexture (
- long quadObject,
- boolean textureCoords
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluCylinder ( GLUquadricObj * qobj , GLdouble baseRadius , GLdouble topRadius , GLdouble height , GLint slices , GLint stacks ) ;
- * </pre>
- */
- public native void gluCylinder (
- long qobj,
- double baseRadius,
- double topRadius,
- double height,
- int slices,
- int stacks
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluSphere ( GLUquadricObj * qobj , GLdouble radius , GLint slices , GLint stacks ) ;
- * </pre>
- */
- public native void gluSphere (
- long qobj,
- double radius,
- int slices,
- int stacks
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluDisk ( GLUquadricObj * qobj , GLdouble innerRadius , GLdouble outerRadius , GLint slices , GLint loops ) ;
- * </pre>
- */
- public native void gluDisk (
- long qobj,
- double innerRadius,
- double outerRadius,
- int slices,
- int loops
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluPartialDisk ( GLUquadricObj * qobj , GLdouble innerRadius , GLdouble outerRadius , GLint slices , GLint loops , GLdouble startAngle , GLdouble sweepAngle ) ;
- * </pre>
- */
- public native void gluPartialDisk (
- long qobj,
- double innerRadius,
- double outerRadius,
- int slices,
- int loops,
- double startAngle,
- double sweepAngle
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluLoadSamplingMatrices ( GLUnurbsObj * nobj , const GLfloat modelMatrix [ 16 ] , const GLfloat projMatrix [ 16 ] , const GLint viewport [ 4 ] ) ;
- * </pre>
- */
- public native void gluLoadSamplingMatrices (
- long nobj,
- float[] modelMatrix,
- float[] projMatrix,
- int[] viewport
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluNurbsProperty ( GLUnurbsObj * nobj , GLenum property , GLfloat value ) ;
- * </pre>
- */
- public native void gluNurbsProperty (
- long nobj,
- int property,
- float value
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluGetNurbsProperty ( GLUnurbsObj * nobj , GLenum property , GLfloat * value ) ;
- * </pre>
- */
- public native void gluGetNurbsProperty (
- long nobj,
- int property,
- float[] value
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluBeginCurve ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluBeginCurve (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluEndCurve ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluEndCurve (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluNurbsCurve ( GLUnurbsObj * nobj , GLint nknots , GLfloat * knot , GLint stride , GLfloat * ctlarray , GLint order , GLenum type ) ;
- * </pre>
- */
- public native void gluNurbsCurve (
- long nobj,
- int nknots,
- float[] knot,
- int stride,
- float[] ctlarray,
- int order,
- int type
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluBeginSurface ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluBeginSurface (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluEndSurface ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluEndSurface (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluNurbsSurface ( GLUnurbsObj * nobj , GLint sknot_count , GLfloat * sknot , GLint tknot_count , GLfloat * tknot , GLint s_stride , GLint t_stride , GLfloat * ctlarray , GLint sorder , GLint torder , GLenum type ) ;
- * </pre>
- */
- public native void gluNurbsSurface (
- long nobj,
- int sknot_count,
- float[] sknot,
- int tknot_count,
- float[] tknot,
- int s_stride,
- int t_stride,
- float[] ctlarray,
- int sorder,
- int torder,
- int type
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluBeginTrim ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluBeginTrim (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluEndTrim ( GLUnurbsObj * nobj ) ;
- * </pre>
- */
- public native void gluEndTrim (
- long nobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluPwlCurve ( GLUnurbsObj * nobj , GLint count , GLfloat * array , GLint stride , GLenum type ) ;
- * </pre>
- */
- public native void gluPwlCurve (
- long nobj,
- int count,
- float[] array,
- int stride,
- int type
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessBeginPolygon ( GLUtesselator * tobj , void * polygon_data ) ;
- * </pre>
- */
- public native void gluTessBeginPolygon (
- long tobj,
- byte[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- short[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- int[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- float[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- double[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- boolean[] polygon_data
- ) ;
- public native void gluTessBeginPolygon (
- long tobj,
- long[] polygon_data
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessBeginContour ( GLUtesselator * tobj ) ;
- * </pre>
- */
- public native void gluTessBeginContour (
- long tobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessVertex ( GLUtesselator * tobj , GLdouble coords [ 3 ] , void * vertex_data ) ;
- * </pre>
- */
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- byte[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- short[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- int[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- float[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- double[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- boolean[] vertex_data
- ) ;
- public native void gluTessVertex (
- long tobj,
- double[] coords,
- long[] vertex_data
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessEndContour ( GLUtesselator * tobj ) ;
- * </pre>
- */
- public native void gluTessEndContour (
- long tobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessEndPolygon ( GLUtesselator * tobj ) ;
- * </pre>
- */
- public native void gluTessEndPolygon (
- long tobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessProperty ( GLUtesselator * tobj , GLenum which , GLdouble value ) ;
- * </pre>
- */
- public native void gluTessProperty (
- long tobj,
- int which,
- double value
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluTessNormal ( GLUtesselator * tobj , GLdouble x , GLdouble y , GLdouble z ) ;
- * </pre>
- */
- public native void gluTessNormal (
- long tobj,
- double x,
- double y,
- double z
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluGetTessProperty ( GLUtesselator * tobj , GLenum which , GLdouble * value ) ;
- * </pre>
- */
- public native void gluGetTessProperty (
- long tobj,
- int which,
- double[] value
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluBeginPolygon ( GLUtesselator * tobj ) ;
- * </pre>
- */
- public native void gluBeginPolygon (
- long tobj
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluNextContour ( GLUtesselator * tobj , GLenum type ) ;
- * </pre>
- */
- public native void gluNextContour (
- long tobj,
- int type
- ) ;
-
-/**
- * Original Function-Prototype :
- * <pre>
- extern void gluEndPolygon ( GLUtesselator * tobj ) ;
- * </pre>
- */
- public native void gluEndPolygon (
- long tobj
- ) ;
-
-/* C2J Parser Version 1.5 Beta: Java program parsed successfully. */
-
-
-}
-
+/* WARNING ! WARNING *** THIS FILE IS GENERATED BY C2J !!!
+
+ DO NOT MAKE ANY CHANGES *** MAKE CHANGES IN THE SKELETON FILES !!!
+*/
+
+
+/**
+ * @(#) GLUFuncJauJNInf.java
+ */
+
+
+package gl4java;
+
+/**
+ * The default implementation class for GLU native function mapping
+ *
+ * @version 2.00, 21. April 1999
+ * @author Sven Goethel
+ */
+public class GLUFuncJauJNInf
+ implements GLUFunc
+{
+
+
+public native String gluErrorString ( int errorCode ) ;
+public native String gluGetString ( int name ) ;
+
+public native String getNativeVendor ( ) ;
+public native String getNativeVersion ( ) ;
+
+public String getClassVendor ( )
+{ return "Jausoft - Sven Goethel Software Development"; }
+
+public String getClassVersion ( )
+{ return "2.5.2.0"; }
+
+
+/**
+ * The Callback registry function.
+ * To achieve the signature (internal argument signature)
+ * you can use the "javap -s <classname>" toolkit of the JDK !
+ *
+ * @param qobj the quadratic id, fetch with gluNewQuadric
+ * @param which the id for the callback type
+ * @param methodClassInstance the class instance,
+ * which implements the callback-method
+ * @param methodName the name of the callback-method
+ * @param signature the signature of the callback-method.
+ *
+ * @see GLUFunc#gluNewQuadric
+ */
+public native void gluQuadricCallback(
+ long qobj, int which,
+ Object methodClassInstance,
+ String methodName,
+ String signature
+ );
+
+/**
+ * The Callback registry function.
+ * To achieve the signature (internal argument signature)
+ * you can use the "javap -s <classname>" toolkit of the JDK !
+ *
+ * @param nobj the nurbs id, fetch with gluNewNurbsRenderer
+ * @param which the id for the callback type
+ * @param methodClassInstance the class instance,
+ * which implements the callback-method
+ * @param methodName the name of the callback-method
+ * @param signature the signature of the callback-method.
+ *
+ * @see GLUFunc#gluNewNurbsRenderer
+ */
+public native void gluNurbsCallback(
+ long nobj, int which,
+ Object methodClassInstance,
+ String methodName,
+ String signature
+ );
+
+
+/**
+ * The Callback registry function.
+ * To achieve the signature (internal argument signature)
+ * you can use the "javap -s <classname>" toolkit of the JDK !
+ *
+ * @param tobj the tesselation id, fetch with gluNewTess
+ * @param which the id for the callback type
+ * @param methodClassInstance the class instance,
+ * which implements the callback-method
+ * @param methodName the name of the callback-method
+ * @param signature the signature of the callback-method.
+ * @param voidArrayLen1 the optional length of the 1st array
+ * in the callback-methods argument-list
+ * @param voidArrayLen2 the optional length of the 2nd array
+ * in the callback-methods argument-list
+ * @param voidArrayLen3 the optional length of the 3rd array
+ * in the callback-methods argument-list
+ * @param voidArrayLen4 the optional length of the 4th array
+ * in the callback-methods argument-list
+ * @param voidArrayLen5 the optional length of the 5th array
+ * in the callback-methods argument-list
+ *
+ * @see GLUFunc#gluNewTess
+ */
+public native void gluTessCallback(
+ long tobj, int which,
+ Object methodClassInstance,
+ String methodName,
+ String signature,
+ int voidArrayLen1,
+ int voidArrayLen2,
+ int voidArrayLen3,
+ int voidArrayLen4,
+ int voidArrayLen5
+ );
+
+/**
+ * The Callback de-registry function.
+ *
+ * @param qobj the quadratic id, for which all callback-methods
+ * should be de-registered
+ */
+public native void gluDeleteQuadric( long qobj );
+
+/**
+ * The Callback de-registry function.
+ *
+ * @param nobj the nurbs id, for which all callback-methods
+ * should be de-registered
+ */
+public native void gluDeleteNurbsRenderer( long nobj );
+
+/**
+ * The Callback de-registry function.
+ *
+ * @param tobj the tesselation id, for which all callback-methods
+ * should be de-registered
+ */
+public native void gluDeleteTess( long tobj );
+
+public native long gluNewQuadric( );
+public native long gluNewNurbsRenderer( );
+public native long gluNewTess( );
+
+/**
+ * C2J Parser Version 1.5 Beta
+ * Jausoft - Sven Goethel Software Development
+ * Reading from file: glu-proto-auto.orig.h . . .
+ * Destination-Class: gl4java_GLUFuncJauJNInf !
+ */
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluLookAt ( GLdouble eyex , GLdouble eyey , GLdouble eyez , GLdouble centerx , GLdouble centery , GLdouble centerz , GLdouble upx , GLdouble upy , GLdouble upz ) ;
+ * </pre>
+ */
+ public native void gluLookAt (
+ double eyex,
+ double eyey,
+ double eyez,
+ double centerx,
+ double centery,
+ double centerz,
+ double upx,
+ double upy,
+ double upz
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluOrtho2D ( GLdouble left , GLdouble right , GLdouble bottom , GLdouble top ) ;
+ * </pre>
+ */
+ public native void gluOrtho2D (
+ double left,
+ double right,
+ double bottom,
+ double top
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluPerspective ( GLdouble fovy , GLdouble aspect , GLdouble zNear , GLdouble zFar ) ;
+ * </pre>
+ */
+ public native void gluPerspective (
+ double fovy,
+ double aspect,
+ double zNear,
+ double zFar
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluPickMatrix ( GLdouble x , GLdouble y , GLdouble width , GLdouble height , GLint * viewport ) ;
+ * </pre>
+ */
+ public native void gluPickMatrix (
+ double x,
+ double y,
+ double width,
+ double height,
+ int[] viewport
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern GLint gluProject ( GLdouble objx , GLdouble objy , GLdouble objz , const GLdouble modelMatrix [ 16 ] , const GLdouble projMatrix [ 16 ] , const GLint viewport [ 4 ] , GLdouble * winx , GLdouble * winy , GLdouble * winz ) ;
+ * </pre>
+ */
+ public native int gluProject (
+ double objx,
+ double objy,
+ double objz,
+ double[] modelMatrix,
+ double[] projMatrix,
+ int[] viewport,
+ double[] winx,
+ double[] winy,
+ double[] winz
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern GLint gluUnProject ( GLdouble winx , GLdouble winy , GLdouble winz , const GLdouble modelMatrix [ 16 ] , const GLdouble projMatrix [ 16 ] , const GLint viewport [ 4 ] , GLdouble * objx , GLdouble * objy , GLdouble * objz ) ;
+ * </pre>
+ */
+ public native int gluUnProject (
+ double winx,
+ double winy,
+ double winz,
+ double[] modelMatrix,
+ double[] projMatrix,
+ int[] viewport,
+ double[] objx,
+ double[] objy,
+ double[] objz
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern GLint gluScaleImage ( GLenum format , GLsizei widthin , GLsizei heightin , GLenum typein , const char * datain , GLsizei widthout , GLsizei heightout , GLenum typeout , char * dataout ) ;
+ * </pre>
+ */
+ public native int gluScaleImage (
+ int format,
+ int widthin,
+ int heightin,
+ int typein,
+ byte[] datain,
+ int widthout,
+ int heightout,
+ int typeout,
+ byte[] dataout
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern GLint gluBuild1DMipmaps ( GLenum target , GLint components , GLint width , GLenum format , GLenum type , const void * data ) ;
+ * </pre>
+ */
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ byte[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ short[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ int[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ float[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ double[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ boolean[] data
+ ) ;
+ public native int gluBuild1DMipmaps (
+ int target,
+ int components,
+ int width,
+ int format,
+ int type,
+ long[] data
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern GLint gluBuild2DMipmaps ( GLenum target , GLint components , GLint width , GLint height , GLenum format , GLenum type , const void * data ) ;
+ * </pre>
+ */
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ byte[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ short[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ int[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ float[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ double[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ boolean[] data
+ ) ;
+ public native int gluBuild2DMipmaps (
+ int target,
+ int components,
+ int width,
+ int height,
+ int format,
+ int type,
+ long[] data
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluQuadricDrawStyle ( GLUquadricObj * quadObject , GLenum drawStyle ) ;
+ * </pre>
+ */
+ public native void gluQuadricDrawStyle (
+ long quadObject,
+ int drawStyle
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluQuadricOrientation ( GLUquadricObj * quadObject , GLenum orientation ) ;
+ * </pre>
+ */
+ public native void gluQuadricOrientation (
+ long quadObject,
+ int orientation
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluQuadricNormals ( GLUquadricObj * quadObject , GLenum normals ) ;
+ * </pre>
+ */
+ public native void gluQuadricNormals (
+ long quadObject,
+ int normals
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluQuadricTexture ( GLUquadricObj * quadObject , GLboolean textureCoords ) ;
+ * </pre>
+ */
+ public native void gluQuadricTexture (
+ long quadObject,
+ boolean textureCoords
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluCylinder ( GLUquadricObj * qobj , GLdouble baseRadius , GLdouble topRadius , GLdouble height , GLint slices , GLint stacks ) ;
+ * </pre>
+ */
+ public native void gluCylinder (
+ long qobj,
+ double baseRadius,
+ double topRadius,
+ double height,
+ int slices,
+ int stacks
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluSphere ( GLUquadricObj * qobj , GLdouble radius , GLint slices , GLint stacks ) ;
+ * </pre>
+ */
+ public native void gluSphere (
+ long qobj,
+ double radius,
+ int slices,
+ int stacks
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluDisk ( GLUquadricObj * qobj , GLdouble innerRadius , GLdouble outerRadius , GLint slices , GLint loops ) ;
+ * </pre>
+ */
+ public native void gluDisk (
+ long qobj,
+ double innerRadius,
+ double outerRadius,
+ int slices,
+ int loops
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluPartialDisk ( GLUquadricObj * qobj , GLdouble innerRadius , GLdouble outerRadius , GLint slices , GLint loops , GLdouble startAngle , GLdouble sweepAngle ) ;
+ * </pre>
+ */
+ public native void gluPartialDisk (
+ long qobj,
+ double innerRadius,
+ double outerRadius,
+ int slices,
+ int loops,
+ double startAngle,
+ double sweepAngle
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluLoadSamplingMatrices ( GLUnurbsObj * nobj , const GLfloat modelMatrix [ 16 ] , const GLfloat projMatrix [ 16 ] , const GLint viewport [ 4 ] ) ;
+ * </pre>
+ */
+ public native void gluLoadSamplingMatrices (
+ long nobj,
+ float[] modelMatrix,
+ float[] projMatrix,
+ int[] viewport
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluNurbsProperty ( GLUnurbsObj * nobj , GLenum property , GLfloat value ) ;
+ * </pre>
+ */
+ public native void gluNurbsProperty (
+ long nobj,
+ int property,
+ float value
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluGetNurbsProperty ( GLUnurbsObj * nobj , GLenum property , GLfloat * value ) ;
+ * </pre>
+ */
+ public native void gluGetNurbsProperty (
+ long nobj,
+ int property,
+ float[] value
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluBeginCurve ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluBeginCurve (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluEndCurve ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluEndCurve (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluNurbsCurve ( GLUnurbsObj * nobj , GLint nknots , GLfloat * knot , GLint stride , GLfloat * ctlarray , GLint order , GLenum type ) ;
+ * </pre>
+ */
+ public native void gluNurbsCurve (
+ long nobj,
+ int nknots,
+ float[] knot,
+ int stride,
+ float[] ctlarray,
+ int order,
+ int type
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluBeginSurface ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluBeginSurface (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluEndSurface ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluEndSurface (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluNurbsSurface ( GLUnurbsObj * nobj , GLint sknot_count , GLfloat * sknot , GLint tknot_count , GLfloat * tknot , GLint s_stride , GLint t_stride , GLfloat * ctlarray , GLint sorder , GLint torder , GLenum type ) ;
+ * </pre>
+ */
+ public native void gluNurbsSurface (
+ long nobj,
+ int sknot_count,
+ float[] sknot,
+ int tknot_count,
+ float[] tknot,
+ int s_stride,
+ int t_stride,
+ float[] ctlarray,
+ int sorder,
+ int torder,
+ int type
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluBeginTrim ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluBeginTrim (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluEndTrim ( GLUnurbsObj * nobj ) ;
+ * </pre>
+ */
+ public native void gluEndTrim (
+ long nobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluPwlCurve ( GLUnurbsObj * nobj , GLint count , GLfloat * array , GLint stride , GLenum type ) ;
+ * </pre>
+ */
+ public native void gluPwlCurve (
+ long nobj,
+ int count,
+ float[] array,
+ int stride,
+ int type
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessBeginPolygon ( GLUtesselator * tobj , void * polygon_data ) ;
+ * </pre>
+ */
+ public native void gluTessBeginPolygon (
+ long tobj,
+ byte[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ short[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ int[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ float[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ double[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ boolean[] polygon_data
+ ) ;
+ public native void gluTessBeginPolygon (
+ long tobj,
+ long[] polygon_data
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessBeginContour ( GLUtesselator * tobj ) ;
+ * </pre>
+ */
+ public native void gluTessBeginContour (
+ long tobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessVertex ( GLUtesselator * tobj , GLdouble coords [ 3 ] , void * vertex_data ) ;
+ * </pre>
+ */
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ byte[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ short[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ int[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ float[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ double[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ boolean[] vertex_data
+ ) ;
+ public native void gluTessVertex (
+ long tobj,
+ double[] coords,
+ long[] vertex_data
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessEndContour ( GLUtesselator * tobj ) ;
+ * </pre>
+ */
+ public native void gluTessEndContour (
+ long tobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessEndPolygon ( GLUtesselator * tobj ) ;
+ * </pre>
+ */
+ public native void gluTessEndPolygon (
+ long tobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessProperty ( GLUtesselator * tobj , GLenum which , GLdouble value ) ;
+ * </pre>
+ */
+ public native void gluTessProperty (
+ long tobj,
+ int which,
+ double value
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluTessNormal ( GLUtesselator * tobj , GLdouble x , GLdouble y , GLdouble z ) ;
+ * </pre>
+ */
+ public native void gluTessNormal (
+ long tobj,
+ double x,
+ double y,
+ double z
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluGetTessProperty ( GLUtesselator * tobj , GLenum which , GLdouble * value ) ;
+ * </pre>
+ */
+ public native void gluGetTessProperty (
+ long tobj,
+ int which,
+ double[] value
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluBeginPolygon ( GLUtesselator * tobj ) ;
+ * </pre>
+ */
+ public native void gluBeginPolygon (
+ long tobj
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluNextContour ( GLUtesselator * tobj , GLenum type ) ;
+ * </pre>
+ */
+ public native void gluNextContour (
+ long tobj,
+ int type
+ ) ;
+
+/**
+ * Original Function-Prototype :
+ * <pre>
+ extern void gluEndPolygon ( GLUtesselator * tobj ) ;
+ * </pre>
+ */
+ public native void gluEndPolygon (
+ long tobj
+ ) ;
+
+/* C2J Parser Version 1.5 Beta: Java program parsed successfully. */
+
+
+}
+
diff --git a/gl4java/awt/GLAnimCanvas.java b/gl4java/awt/GLAnimCanvas.java
index 499b328..50aa78d 100644
--- a/gl4java/awt/GLAnimCanvas.java
+++ b/gl4java/awt/GLAnimCanvas.java
@@ -1,745 +1,744 @@
-/**
- * @(#) GLAnimCanvas.java
- */
-
-package gl4java.awt;
-
-import gl4java.GLContext;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.lang.Math;
-
-
-/**
- * This is meant as an base class writing
- * Animations. A clean usage of multi-threading compatible
- * with JAVA2 is implemented here !
- *
- * <p>
- *
- * If you are interessting in further Documentation and/or
- * the history of GL4Java follow the following link.
- *
- * <pre>
- <a href="../../GL4Java.html">The GL4Java Documentation</a>
- * </pre>
- * <p>
- *
- * This code uses repaint() to fire a sDisplay call by the AWT-Event thread !
- * and sleep to suspend for a given Frames per secounds value as default !!
- *
- * To switch this behavior for a better performance, and responsiveness
- * so that sDisplay is called by the animation thread itself
- * call:
- *
- * <pre>
- <a href="GLAnimCanvas.html#setUseRepaint(boolean)">setUseRepaint(false)</a>
- * </pre>
- * <p>
- *
- * This code sleep's for a given Frames per secounds after each frame
- * as default !!
- *
- * To switch this behavior for a better performance,
- * so that much frames are rendered as the machine can do !
- * call:
- *
- * <pre>
- <a href="GLAnimCanvas.html#setUseFpsSleep(boolean)">setUseFpsSleep(false)</a>
- * </pre>
- * <p>
- * But be sure, that the other threads may not have enough time or i
- * may not get the cpu power ...
- *
- * The following settings for setUseRepaint and setUseFpsSleep looks fine:
- *
- * <pre>
- <p>
- A JVM with operating system threads has: <b>native-threads</b>
- <p>
- A JVM where all JVM threads runs in one operating-system-thread
- has: <b>green-threads</b>
-
- <a name="table">
- <table border>
- <tr>
- <th><th>green-threads<th>native-threads
- <tr>
- <td align=center><a href="GLAnimCanvas.html#setUseRepaint(boolean)"><code>setUseRepaint</code></a>
- <td align=center><code>true</code>
- <td align=center><code> true & false </code>
- <tr>
- <td align=center><a href="GLAnimCanvas.html#setUseFpsSleep(boolean)"><code>setUseFpsSleep</code></a>
- <td align=center><code>true</code>
- <td align=center><code> true & false </code>
-
- </table>
- </a>
- * </pre>
- *
- * If you play with setUseRepaint or setUseFpsSleep,
- * be shure to have a Java VM with native-thread support,
- * because a GL-Context can be shared by many threads,
- * but one thread can have just one GL-Context !
- *
- * <p>
- *
- * Since GL4Java 2.5.2 and using a JVM >= 1.3
- * the multithreading support is stable !
- *
- * <p>
- *
- * (comments welcome)
- *
- * <p>
- * To use real fps settings, the following functions provides you to do so:
- * <pre>
- <a href="GLAnimCanvas.html#setAnimateFps(double)">setAnimateFps</a>
- <a href="GLAnimCanvas.html#getMaxFps()">getMaxFps</a>
- * </pre>
- * Like the first animation run, this class renders a view frames (default 10)
- * to subtract the render time from the sleep time !
- * <p>
- * You should overwrite the following methods for your needs:
- * <pre>
- <a href="GLCanvas.html#init()">preInit - initialisation before creating GLContext</a>
- <a href="GLAnimCanvas.html#init()">init - 1st initialisation</a>
- <a href="GLCanvas.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
- <a href="GLAnimCanvas.html#display()">display - render one frame</a>
- <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize)</a>
- <a href="GLAnimCanvas.html#ReInit()">ReInit - ReInitialisation after stop for setSuspended(false)</a>
- * </pre>
- *
- * @see gl4java.awt.GLCanvas
- * @version 2.0, 21. April 1999
- * @author Sven Goethel
- *
- */
-public class GLAnimCanvas extends GLCanvas
- implements Runnable
-{
- /**
- * To support frames per scounds,
- * instead of killing the machine :-)
- *
- * A little GUI is supported !
- *
- * @see gl4java.awt.GLAnimCanvas#run
- */
- protected double FramesPerSec=20;
- protected long mSecPerFrame=0;
-
- protected static int globalThreadNumber=0;
-
- public static int getGlobalThreadNumber()
- {
- return globalThreadNumber;
- }
-
- /**
- * the delays ..
- */
- protected long dFpsMilli = 0;
-
- /**
- * The thread for referencing Thread (Animation)
- *
- * @see gl4java.awt.GLAnimCanvas#stop
- * @see gl4java.awt.GLAnimCanvas#start
- * @see gl4java.awt.GLAnimCanvas#run
- */
- protected Thread killme = null;
-
- /**
- * Instead of using suspend (JAVA2)
- *
- * @see gl4java.awt.GLAnimCanvas#run
- */
- protected boolean threadSuspended = false;
-
- static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
- System.out.println("GLAnimCanvas could not load def. native libs.");
- }
-
- /**
- *
- * Constructor
- *
- * @see gl4java.awt.GLCanvas#GLCanvas
- *
- */
- public GLAnimCanvas( int width, int height,
- String gl_Name,
- String glu_Name
- )
- {
- super( width, height, gl_Name, glu_Name );
- setAnimateFps(FramesPerSec);
- }
-
- /**
- *
- * Constructor
- *
- * Uses the default GLFunc and GLUFunc implementation !
- *
- * @see gl4java.awt.GLCanvas#GLCanvas
- *
- */
- public GLAnimCanvas( int width, int height )
- {
- super( width, height);
- setAnimateFps(FramesPerSec);
- }
-
- /**
- * init should be overwritten by you,
- * to enter your initialisation code
- *
- */
- public void init()
- {
- /* here we should add and initialize our JAVA components */
-
- /* ... and furthet OpenGL init's - like you want to */
-
- glj.gljCheckGL();
-
- ReInit();
-
- /* and start our working thread ... */
- start();
- }
-
- /**
- *
- * This is the rendering-method called by sDisplay
- * (and sDisplay is called by paint, or by the thread directly !).
- * The derived-class (Your Subclass) will redefine this,
- * to draw it's own animation !
- *
- * <p>
- *
- * You MUST encapsulate your OpenGL call's within:
- * <pre>
- - glj.gljMakeCurrent()
- YOUR OpenGL commands here !
- - glj.gljFree()
- * </pre>
- * <p>
- *
- * You should set shallWeRender here,
- * to signalize the animation-loop 'run' to supsend
- * <p>
- * To restart the thread, just call setSuspended(false)
- *
- * @see gl4java.awt.GLAnimCanvas#shallWeRender
- * @see gl4java.awt.GLAnimCanvas#run
- * @see gl4java.awt.GLAnimCanvas#setSuspended
- * @see gl4java.awt.GLCanvas#sDisplay
- * @see gl4java.awt.GLCanvas#paint
- */
- public void display()
- {
- int i;
-
- /* Standard GL4Java Init */
- if( cvsIsInit()==false )
- {
- if(glj.gljClassDebug)
- System.out.println("GLAnimCanvas not initialized yet ...");
- return;
- }
-
- if( glj.gljMakeCurrent() == false )
- {
- if(glj.gljClassDebug)
- System.out.println("GLAnimCanvas problem in gljMakeCurrent() method");
- return;
- }
-
- // ... just render it
-
- /* For your animation dutys ;-) */
- glj.gljSwap();
- glj.gljCheckGL();
- glj.gljFree();
- }
-
- /**
- * ReInit should be overwritten by you,
- * to enter your re-initialisation within setSuspended(false)
- *
- * @see gl4java.awt.GLAnimCanvas#setSuspended
- */
- public void ReInit()
- {
- }
-
- protected boolean useRepaint = true;
-
- protected boolean useFpsSleep = true;
-
- /**
- * The normal behavior is to use 'repaint'
- * within the AWT-Event Thread to render.
- * <p>
- * If you have serious reasons, e.g. measuring performance,
- * you can change it while invoke this function with 'false'.
- * In this case, the thread itself calls the sDisplay method !
- *
- * On fast good multi-threading machines (native-thread-JVM),
- * this should increase the performance and the responsiveness !
- * <p>
- *
- * @param b if true, uses repaint (default), otherwise directly sDisplay
- * @see gl4java.awt.GLCanvas#sDisplay
- * @see gl4java.awt.GLAnimCanvas#setUseFpsSleep
- */
- public void setUseRepaint(boolean b)
- {
- useRepaint = b;
- }
-
- /**
- * The normal behavior is to use FpsSleep
- *
- * But you can overwrite this behavior and
- * drop the Frame Per Secound sleeps -
- * so that much frames are rendered as the machine can do !
- * <p>
- *
- * @param b if true, uses Fps sleeping, else not !
- * @see gl4java.awt.GLCanvas#sDisplay
- * @see gl4java.awt.GLAnimCanvas#setUseRepaint
- */
- public void setUseFpsSleep(boolean b)
- {
- useFpsSleep = b;
- }
-
- public boolean getUseRepaint()
- {
- return useRepaint;
- }
-
- public boolean getUseFpsSleep()
- {
- return useFpsSleep;
- }
-
- /**
- * HERE WE DO HAVE OUR RUNNING THREAD !
- * WE NEED STUFF LIKE THAT FOR ANIMATION ;-)
- */
- public void start()
- {
- if(killme == null)
- {
- killme = new Thread(this);
- killme.start();
-
- resetFpsCounter();
- }
- }
-
- public synchronized void stop()
- {
- killme = null;
- threadSuspended=false;
-
- notifyAll();
- }
-
- /**
- * You should call this before releasing/dispose this Window !
- * Also you can overwrite this class,
- * to dispose your own elements, e.g. a Frame etc. -
- * but be shure that you call
- * cvsDispose implementation call this one !
- *
- * This function calls gljDestroy of GLContext !
- *
- * @see gl4java.GLContext#gljDestroy
- * @see gl4java.awt.GLCanvas#cvsDispose
- * @see gl4java.awt.GLCanvas#doCleanup
- */
- public void cvsDispose()
- {
- stop();
- super.cvsDispose();
- }
-
- /**
- * Should be set in display,
- * whether to render or not while the animation loop
- * <p>
- * If shallWeRender is false,
- * this thread will suspend !
- *
- * @see gl4java.awt.GLAnimCanvas#display
- * @see gl4java.awt.GLAnimCanvas#run
- */
- protected boolean shallWeRender = true;
- protected boolean isRunning = false;
-
- private long _fDelay = 0;
- private long _fDelay_Frames = 10;
- private boolean _fDelaySync=true;
- private boolean _fDelayRun=false;
-
- /**
- * The running loop for animations
- * which initiates the call of display
- *
- * @see gl4java.awt.GLAnimCanvas#shallWeRender
- * @see gl4java.awt.GLAnimCanvas#display
- */
- public void run()
- {
- Thread thisThread = Thread.currentThread();
-
- isRunning = true;
-
- synchronized (this) {
- globalThreadNumber++;
- }
-
- while (killme==thisThread)
- {
- if(cvsIsInit())
- {
- /* DRAW THE TINGS .. */
- if (shallWeRender)
- {
- if(useRepaint)
- repaint();
- else
- sDisplay();
- } else {
- synchronized (this) {
- threadSuspended=true;
- }
- }
-
- if(fps_isCounting)
- fps_frames++;
-
- }
-
- try {
- if(useFpsSleep)
- {
- if(useRepaint)
- {
- if(mSecPerFrame<_f_dur)
- dFpsMilli=_f_dur;
- else
- dFpsMilli=mSecPerFrame;
- }
- else
- {
- dFpsMilli= mSecPerFrame - _f_dur;
- if (dFpsMilli<=0)
- dFpsMilli= 1;
- }
-
- Thread.currentThread().sleep(dFpsMilli, 0 );
- } else {
- Thread.yield();
- }
-
- if (threadSuspended) {
- stopFpsCounter();
- synchronized (this) {
- while (threadSuspended)
- wait();
- }
- }
- } catch (InterruptedException e)
- {}
- }
-
- if(glj!=null)
- glj.gljFree(); // just to be sure ..
-
- synchronized (this) {
- globalThreadNumber--;
- }
-
- isRunning = false;
- }
-
- /**
- * Here we can (re)start or suspend animation ...
- *
- * If the thread should be (re)started and is not alive -> killed,
- * or never be started, it will be started !
- *
- * @param suspend if true the thread will be suspended,
- * if false, the thread will be (re)started
- *
- * @see gl4java.awt.GLAnimCanvas#isAlive
- * @see gl4java.awt.GLAnimCanvas#start
- */
- public void setSuspended(boolean suspend)
- {
- setSuspended(suspend, false);
- }
-
- /**
- * Here we can (re)start or suspend animation ...
- *
- * If the thread should be (re)started and is not alive -> killed,
- * or never be started, it will be started !
- *
- * @param suspend if true the thread will be suspended,
- * if false, the thread will be (re)started
- *
- * @param reInit if true the ReInit will be called additionally,
- * where the user can set additional initialisations
- *
- * @see gl4java.awt.GLAnimCanvas#isAlive
- * @see gl4java.awt.GLAnimCanvas#start
- */
- public synchronized void setSuspended(boolean suspend, boolean reInit)
- {
- if(suspend) {
- shallWeRender=false;
- } else if(isAlive()==false) {
- start();
- } else {
- // the thread is alive, but suspended and should be
- // re-started
- shallWeRender=true;
- resetFpsCounter();
-
- if(reInit)
- ReInit();
-
- threadSuspended=false;
- notifyAll();
- }
- }
-
- /**
- * is the thread alive, means is started and not died ?
- *
- * @see gl4java.awt.GLAnimCanvas#run
- * @see gl4java.awt.GLAnimCanvas#setSuspended
- * @see gl4java.awt.GLAnimCanvas#start
- * @see gl4java.awt.GLAnimCanvas#stop
- */
- public boolean isAlive()
- {
- if(killme==null) return false;
- return killme.isAlive();
- }
-
- /**
- * is the thread suspended, means is started but waiting,
- * or not alive (ok :-| - but it is practical)
- *
- * @see gl4java.awt.GLAnimCanvas#run
- * @see gl4java.awt.GLAnimCanvas#setSuspended
- * @see gl4java.awt.GLAnimCanvas#start
- * @see gl4java.awt.GLAnimCanvas#stop
- */
- public boolean isSuspended()
- {
- if(killme==null) return true;
- return threadSuspended;
- }
-
- private double fps=0; // frame-per-sec
- private long fps_duration =0; // milli-secs
- private long fps_start=0; // milli-secs
- private long fps_frames =0; // number of frames
- private boolean fps_isCounting =true; // shall i count
- private boolean verboseFps =false; // shall i be verbose
-
- /**
- * resets the Fps Counter
- * <p>
- * this function is called automatically by
- * start and setSuspended
- *
- * @see gl4java.awt.GLAnimCanvas#start
- * @see gl4java.awt.GLAnimCanvas#setSuspended
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public void resetFpsCounter()
- {
- fps=0; // frame-per-sec
- fps_duration =0; // milli-secs
- fps_frames =0; // number of frames
- fps_isCounting =true; // shall i count
- fps_start=System.currentTimeMillis();
- }
-
- /**
- * stops the Fps Counter and sets all values
- * fot the getFps* methods
- * <p>
- * this function is called automatically by
- * run, if the thread is suspended via shallWeRender
- * <p>
- * All data's are print out on System.out
- * if verboseFps is set !
- *
- * @see gl4java.awt.GLAnimCanvas#run
- * @see gl4java.awt.GLAnimCanvas#shallWeRender
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public void stopFpsCounter()
- {
- if(fps_isCounting==true)
- {
- long fps_end=System.currentTimeMillis();
- fps_duration = fps_end-fps_start;
- double timed= ((double)fps_duration)/1000.0;
- if(timed==0) timed=1.0;
- fps = ((double)fps_frames)/timed ;
- fps_isCounting=false;
- }
- if(verboseFps)
- {
- System.out.println("\nfps = "+String.valueOf(fps));
- System.out.println("time = "+String.valueOf(fps_duration)+" ms");
- System.out.println("frames = "+String.valueOf(fps_frames));
- if(fps_frames==0) fps_frames=1;
- System.out.println("time/f = "+String.valueOf(fps_duration/fps_frames)+" ms");
- }
- }
-
- /**
- * sets if the Fps data shall be printed to System.out
- * while stopFpsCounter is called !
- * <p>
- * verboseFps is set to true by default !
- *
- * @see gl4java.awt.GLAnimCanvas#run
- * @see gl4java.awt.GLAnimCanvas#shallWeRender
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public void setVerboseFps(boolean v)
- {
- verboseFps=v;
- }
-
- /**
- * returns the calculated frames per secounds
- * <p>
- * this data is avaiable after calling stopFpsCounter
- *
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public double getFps()
- {
- return fps;
- }
-
- /**
- * returns the calculated duration in millisecs
- * <p>
- * this data is avaiable after calling stopFpsCounter
- *
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public long getFpsDuration()
- {
- return fps_duration;
- }
-
- /**
- * returns the calculated frames number
- * <p>
- * this data is avaiable after calling stopFpsCounter
- *
- * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
- * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
- * @see gl4java.awt.GLAnimCanvas#getFps
- * @see gl4java.awt.GLAnimCanvas#getFpsDuration
- * @see gl4java.awt.GLAnimCanvas#getFpsFrames
- * @see gl4java.awt.GLAnimCanvas#setVerboseFps
- */
- public long getFpsFrames()
- {
- return fps_frames;
- }
-
- /**
- * Just set the FramePerSecounds for Animation
- *
- * @deprecated Now the frames per seconds are allways
- * calculated, no pre-sync needed.
- * @see #setAnimateFps(double)
- */
- public void setAnimateFps(double fps, int synFrames)
- {
- setAnimateFps(fps);
- }
-
- /**
- * Just set the FramePerSecounds for Animation
- *
- * @see gl4java.awt.GLAnimCanvas#getMaxFps
- */
- public void setAnimateFps(double fps)
- {
- FramesPerSec=fps;
- mSecPerFrame = (long) ( (1.0/FramesPerSec) * 1000.0 ) ;
- if(verboseFps)
- {
- System.out.println("\nset fps := "+
- String.valueOf(fps)+
- " -> "+String.valueOf(mSecPerFrame)+
- " [ms/frame]"
- );
- }
- resetFpsCounter();
- }
-
- /**
- * Just get the maximum number of Frames per secounds,
- * which is calculated with the time, one frame needs to render !
- *
- * this value is avaiable after the thread is started
- * and the first frames are rendered !
- *
- * @see gl4java.awt.GLAnimCanvas#setAnimateFps
- */
- public double getMaxFps()
- {
- return (1.0/(double)_f_dur)*1000.0;
- }
-
-}
-
+/**
+ * @(#) GLAnimCanvas.java
+ */
+
+package gl4java.awt;
+
+import gl4java.*;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.Math;
+
+
+/**
+ * This is meant as an base class writing
+ * Animations. A clean usage of multi-threading compatible
+ * with JAVA2 is implemented here !
+ *
+ * <p>
+ *
+ * If you are interessting in further Documentation and/or
+ * the history of GL4Java follow the following link.
+ *
+ * <pre>
+ <a href="../../GL4Java.html">The GL4Java Documentation</a>
+ * </pre>
+ *
+ * <p>
+ * There are two ways of using a GLAnimCanvas: the {@link
+ * gl4java.GLEventListener} model or the subclassing model. Earlier
+ * versions of OpenGL for Java only supported the subclassing model.
+ * The default implementations of {@link gl4java.awt.GLCanvas#init},
+ * {@link gl4java.awt.GLCanvas#display},
+ * {@link gl4java.awt.GLCanvas#reshape} and
+ # {@link gl4java.awt.GLCanvas#doCleanup}
+ * now send events to GLEventListeners; they can
+ * still be overridden as before to support the subclassing model.
+ *
+ * <p>
+ * If using the subclassing model, you should override the following
+ * methods for your needs:
+ * <pre>
+ <a href="GLCanvas.html#init()">preInit - initialisation before creating GLContext</a>
+ <a href="GLAnimCanvas.html#init()">init - 1st initialisation</a>
+ <a href="GLCanvas.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
+ <a href="GLAnimCanvas.html#display()">display - render one frame</a>
+ <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize)</a>
+ <a href="GLAnimCanvas.html#ReInit()">ReInit - ReInitialisation after stop for setSuspended(false)</a>
+ * </pre>
+ *
+ * <p>
+ *
+ * This code uses repaint() to fire a sDisplay call by the AWT-Event thread !
+ * and sleep to suspend for a given Frames per secounds value as default !!
+ *
+ * To switch this behavior for a better performance, and responsiveness
+ * so that sDisplay is called by the animation thread itself
+ * call:
+ *
+ * <pre>
+ <a href="GLAnimCanvas.html#setUseRepaint(boolean)">setUseRepaint(false)</a>
+ * </pre>
+ * <p>
+ *
+ * This code sleep's for a given Frames per secounds after each frame
+ * as default !!
+ *
+ * To switch this behavior for a better performance,
+ * so that much frames are rendered as the machine can do !
+ * call:
+ *
+ * <pre>
+ <a href="GLAnimCanvas.html#setUseFpsSleep(boolean)">setUseFpsSleep(false)</a>
+ * </pre>
+ * <p>
+ * But be sure, that the other threads may not have enough time or i
+ * may not get the cpu power ...
+ *
+ * The following settings for setUseRepaint and setUseFpsSleep looks fine:
+ *
+ * <pre>
+ <p>
+ A JVM with operating system threads has: <b>native-threads</b>
+ <p>
+ A JVM where all JVM threads runs in one operating-system-thread
+ has: <b>green-threads</b>
+
+ <a name="table">
+ <table border>
+ <tr>
+ <th><th>green-threads<th>native-threads
+ <tr>
+ <td align=center><a href="GLAnimCanvas.html#setUseRepaint(boolean)"><code>setUseRepaint</code></a>
+ <td align=center><code>true</code>
+ <td align=center><code> true & false </code>
+ <tr>
+ <td align=center><a href="GLAnimCanvas.html#setUseFpsSleep(boolean)"><code>setUseFpsSleep</code></a>
+ <td align=center><code>true</code>
+ <td align=center><code> true & false </code>
+
+ </table>
+ </a>
+ * </pre>
+ *
+ * If you play with setUseRepaint or setUseFpsSleep,
+ * be shure to have a Java VM with native-thread support,
+ * because a GL-Context can be shared by many threads,
+ * but one thread can have just one GL-Context !
+ *
+ * <p>
+ *
+ * Since GL4Java 2.5.2 and using a JVM >= 1.3
+ * the multithreading support is stable !
+ *
+ * <p>
+ *
+ * (comments welcome)
+ *
+ * <p>
+ * To use real fps settings, the following functions provides you to do so:
+ * <pre>
+ <a href="GLAnimCanvas.html#setAnimateFps(double)">setAnimateFps</a>
+ <a href="GLAnimCanvas.html#getMaxFps()">getMaxFps</a>
+ * </pre>
+ * Like the first animation run, this class renders a view frames (default 10)
+ * to subtract the render time from the sleep time !
+ *
+ * @see gl4java.awt.GLCanvas
+ * @version 2.0, 21. April 1999
+ * @author Sven Goethel
+ *
+ */
+public class GLAnimCanvas extends GLCanvas
+ implements Runnable
+{
+ /**
+ * To support frames per scounds,
+ * instead of killing the machine :-)
+ *
+ * A little GUI is supported !
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ */
+ protected double FramesPerSec=20;
+ protected long mSecPerFrame=0;
+
+ protected static int globalThreadNumber=0;
+
+ public static int getGlobalThreadNumber()
+ {
+ return globalThreadNumber;
+ }
+
+ /**
+ * the delays ..
+ */
+ protected long dFpsMilli = 0;
+
+ /**
+ * The thread for referencing Thread (Animation)
+ *
+ * @see gl4java.awt.GLAnimCanvas#stop
+ * @see gl4java.awt.GLAnimCanvas#start
+ * @see gl4java.awt.GLAnimCanvas#run
+ */
+ protected Thread killme = null;
+
+ /**
+ * Instead of using suspend (JAVA2)
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ */
+ protected boolean threadSuspended = false;
+
+ static {
+ if(GLContext.loadNativeLibraries(null, null, null)==false)
+ System.out.println("GLAnimCanvas could not load def. native libs.");
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ *
+ */
+ public GLAnimCanvas( int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ super( width, height, gl_Name, glu_Name );
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ *
+ */
+ public GLAnimCanvas( int width, int height )
+ {
+ super( width, height);
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ *
+ */
+ public GLAnimCanvas( GLCapabilities capabilities,
+ int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ super( capabilities, width, height, gl_Name, glu_Name );
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ *
+ */
+ public GLAnimCanvas( GLCapabilities capabilities,
+ int width, int height )
+ {
+ super( capabilities, width, height);
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ */
+ public GLAnimCanvas( GraphicsConfiguration config,
+ GLCapabilities capabilities,
+ int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ super( config, capabilities,
+ width, height, gl_Name, glu_Name );
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @see gl4java.awt.GLCanvas#GLCanvas
+ */
+ public GLAnimCanvas( GraphicsConfiguration config,
+ GLCapabilities capabilities,
+ int width, int height )
+ {
+ super( config, capabilities,
+ width, height);
+ setAnimateFps(FramesPerSec);
+ }
+
+ /**
+ * ReInit should be overwritten by you,
+ * to enter your re-initialisation within setSuspended(false)
+ *
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ */
+ public void ReInit()
+ {
+ }
+
+ protected boolean useRepaint = true;
+
+ protected boolean useFpsSleep = true;
+
+ /**
+ * The normal behavior is to use 'repaint'
+ * within the AWT-Event Thread to render.
+ * <p>
+ * If you have serious reasons, e.g. measuring performance,
+ * you can change it while invoke this function with 'false'.
+ * In this case, the thread itself calls the sDisplay method !
+ *
+ * On fast good multi-threading machines (native-thread-JVM),
+ * this should increase the performance and the responsiveness !
+ * <p>
+ *
+ * @param b if true, uses repaint (default), otherwise directly sDisplay
+ * @see gl4java.awt.GLCanvas#sDisplay
+ * @see gl4java.awt.GLAnimCanvas#setUseFpsSleep
+ */
+ public void setUseRepaint(boolean b)
+ {
+ useRepaint = b;
+ }
+
+ /**
+ * The normal behavior is to use FpsSleep
+ *
+ * But you can overwrite this behavior and
+ * drop the Frame Per Secound sleeps -
+ * so that much frames are rendered as the machine can do !
+ * <p>
+ *
+ * @param b if true, uses Fps sleeping, else not !
+ * @see gl4java.awt.GLCanvas#sDisplay
+ * @see gl4java.awt.GLAnimCanvas#setUseRepaint
+ */
+ public void setUseFpsSleep(boolean b)
+ {
+ useFpsSleep = b;
+ }
+
+ public boolean getUseRepaint()
+ {
+ return useRepaint;
+ }
+
+ public boolean getUseFpsSleep()
+ {
+ return useFpsSleep;
+ }
+
+ /**
+ * HERE WE DO HAVE OUR RUNNING THREAD !
+ * WE NEED STUFF LIKE THAT FOR ANIMATION ;-)
+ */
+ public void start()
+ {
+ if(killme == null)
+ {
+ killme = new Thread(this);
+ killme.start();
+
+ resetFpsCounter();
+ }
+ }
+
+ public synchronized void stop()
+ {
+ killme = null;
+ threadSuspended=false;
+
+ notifyAll();
+ }
+
+ /**
+ * You should call this before releasing/dispose this Window !
+ * Also you can overwrite this class,
+ * to dispose your own elements, e.g. a Frame etc. -
+ * but be shure that you call
+ * cvsDispose implementation call this one !
+ *
+ * This function calls gljDestroy of GLContext !
+ *
+ * @see gl4java.GLContext#gljDestroy
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ * @see gl4java.awt.GLCanvas#doCleanup
+ */
+ public void cvsDispose()
+ {
+ stop();
+ super.cvsDispose();
+ }
+
+ protected boolean shallWeRender = true;
+ protected boolean isRunning = false;
+
+ private long _fDelay = 0;
+ private long _fDelay_Frames = 10;
+ private boolean _fDelaySync=true;
+ private boolean _fDelayRun=false;
+
+ /**
+ * The running loop for animations
+ * which initiates the call of display
+ *
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLCanvas#display
+ */
+ public void run()
+ {
+ Thread thisThread = Thread.currentThread();
+
+ isRunning = true;
+
+ synchronized (this) {
+ globalThreadNumber++;
+ }
+
+ while (killme==thisThread)
+ {
+ if(cvsIsInit())
+ {
+ /* DRAW THE TINGS .. */
+ if (shallWeRender)
+ {
+ if(useRepaint)
+ repaint();
+ else
+ sDisplay();
+ } else {
+ synchronized (this) {
+ threadSuspended=true;
+ }
+ }
+
+ if(fps_isCounting)
+ fps_frames++;
+
+ }
+
+ try {
+ if(useFpsSleep)
+ {
+ if(useRepaint)
+ {
+ if(mSecPerFrame<_f_dur)
+ dFpsMilli=_f_dur;
+ else
+ dFpsMilli=mSecPerFrame;
+ }
+ else
+ {
+ dFpsMilli= mSecPerFrame - _f_dur;
+ if (dFpsMilli<=0)
+ dFpsMilli= 1;
+ }
+
+ Thread.currentThread().sleep(dFpsMilli, 0 );
+ } else {
+ Thread.yield();
+ }
+
+ if (threadSuspended) {
+ stopFpsCounter();
+ synchronized (this) {
+ while (threadSuspended)
+ wait();
+ }
+ }
+ } catch (InterruptedException e)
+ {}
+ }
+
+ if(glj!=null)
+ glj.gljFree(); // just to be sure ..
+
+ synchronized (this) {
+ globalThreadNumber--;
+ }
+
+ isRunning = false;
+ }
+
+ /**
+ * Here we can (re)start or suspend animation ...
+ *
+ * If the thread should be (re)started and is not alive -> killed,
+ * or never be started, it will be started !
+ *
+ * @param suspend if true the thread will be suspended,
+ * if false, the thread will be (re)started
+ *
+ * @see gl4java.awt.GLAnimCanvas#isAlive
+ * @see gl4java.awt.GLAnimCanvas#start
+ */
+ public void setSuspended(boolean suspend)
+ {
+ setSuspended(suspend, false);
+ }
+
+ /**
+ * Here we can (re)start or suspend animation ...
+ *
+ * If the thread should be (re)started and is not alive -> killed,
+ * or never be started, it will be started !
+ *
+ * @param suspend if true the thread will be suspended,
+ * if false, the thread will be (re)started
+ *
+ * @param reInit if true the ReInit will be called additionally,
+ * where the user can set additional initialisations
+ *
+ * @see gl4java.awt.GLAnimCanvas#isAlive
+ * @see gl4java.awt.GLAnimCanvas#start
+ * @see gl4java.awt.GLAnimCanvas#run
+ */
+ public synchronized void setSuspended(boolean suspend, boolean reInit)
+ {
+ if(suspend) {
+ shallWeRender=false;
+ } else if(isAlive()==false) {
+ start();
+ } else {
+ // the thread is alive, but suspended and should be
+ // re-started
+ shallWeRender=true;
+ resetFpsCounter();
+
+ if(reInit)
+ ReInit();
+
+ threadSuspended=false;
+ notifyAll();
+ }
+ }
+
+ /**
+ * is the thread alive, means is started and not died ?
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLAnimCanvas#start
+ * @see gl4java.awt.GLAnimCanvas#stop
+ */
+ public boolean isAlive()
+ {
+ if(killme==null) return false;
+ return killme.isAlive();
+ }
+
+ /**
+ * is the thread suspended, means is started but waiting,
+ * or not alive (ok :-| - but it is practical)
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLAnimCanvas#start
+ * @see gl4java.awt.GLAnimCanvas#stop
+ */
+ public boolean isSuspended()
+ {
+ if(killme==null) return true;
+ return threadSuspended;
+ }
+
+ private double fps=0; // frame-per-sec
+ private long fps_duration =0; // milli-secs
+ private long fps_start=0; // milli-secs
+ private long fps_frames =0; // number of frames
+ private boolean fps_isCounting =true; // shall i count
+ private boolean verboseFps =false; // shall i be verbose
+
+ /**
+ * resets the Fps Counter
+ * <p>
+ * this function is called automatically by
+ * start and after setSuspended suspends the
+ * animation thread !
+ *
+ * @see gl4java.awt.GLAnimCanvas#start
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public void resetFpsCounter()
+ {
+ fps=0; // frame-per-sec
+ fps_duration =0; // milli-secs
+ fps_frames =0; // number of frames
+ fps_isCounting =true; // shall i count
+ fps_start=System.currentTimeMillis();
+ }
+
+ /**
+ * stops the Fps Counter and sets all values
+ * fot the getFps* methods
+ * <p>
+ * this function is called automatically by
+ * run, if the thread is suspended via setSuspended(true)
+ * <p>
+ * All data's are print out on System.out
+ * if verboseFps is set !
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public void stopFpsCounter()
+ {
+ if(fps_isCounting==true)
+ {
+ long fps_end=System.currentTimeMillis();
+ fps_duration = fps_end-fps_start;
+ double timed= ((double)fps_duration)/1000.0;
+ if(timed==0) timed=1.0;
+ fps = ((double)fps_frames)/timed ;
+ fps_isCounting=false;
+ }
+ if(verboseFps)
+ {
+ System.out.println("\nfps = "+String.valueOf(fps));
+ System.out.println("time = "+String.valueOf(fps_duration)+" ms");
+ System.out.println("frames = "+String.valueOf(fps_frames));
+ if(fps_frames==0) fps_frames=1;
+ System.out.println("time/f = "+String.valueOf(fps_duration/fps_frames)+" ms");
+ }
+ }
+
+ /**
+ * sets if the Fps data shall be printed to System.out
+ * while stopFpsCounter is called !
+ * <p>
+ * verboseFps is set to true by default !
+ *
+ * @see gl4java.awt.GLAnimCanvas#run
+ * @see gl4java.awt.GLAnimCanvas#setSuspended
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public void setVerboseFps(boolean v)
+ {
+ verboseFps=v;
+ }
+
+ /**
+ * returns the calculated frames per secounds
+ * <p>
+ * this data is avaiable after calling stopFpsCounter
+ *
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public double getFps()
+ {
+ return fps;
+ }
+
+ /**
+ * returns the calculated duration in millisecs
+ * <p>
+ * this data is avaiable after calling stopFpsCounter
+ *
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public long getFpsDuration()
+ {
+ return fps_duration;
+ }
+
+ /**
+ * returns the calculated frames number
+ * <p>
+ * this data is avaiable after calling stopFpsCounter
+ *
+ * @see gl4java.awt.GLAnimCanvas#resetFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#stopFpsCounter
+ * @see gl4java.awt.GLAnimCanvas#getFps
+ * @see gl4java.awt.GLAnimCanvas#getFpsDuration
+ * @see gl4java.awt.GLAnimCanvas#getFpsFrames
+ * @see gl4java.awt.GLAnimCanvas#setVerboseFps
+ */
+ public long getFpsFrames()
+ {
+ return fps_frames;
+ }
+
+ /**
+ * Just set the FramePerSecounds for Animation
+ *
+ * @deprecated Now the frames per seconds are allways
+ * calculated, no pre-sync needed.
+ * @see #setAnimateFps(double)
+ */
+ public void setAnimateFps(double fps, int synFrames)
+ {
+ setAnimateFps(fps);
+ }
+
+ /**
+ * Just set the FramePerSecounds for Animation
+ *
+ * @see gl4java.awt.GLAnimCanvas#getMaxFps
+ */
+ public void setAnimateFps(double fps)
+ {
+ FramesPerSec=fps;
+ mSecPerFrame = (long) ( (1.0/FramesPerSec) * 1000.0 ) ;
+ if(verboseFps)
+ {
+ System.out.println("\nset fps := "+
+ String.valueOf(fps)+
+ " -> "+String.valueOf(mSecPerFrame)+
+ " [ms/frame]"
+ );
+ }
+ resetFpsCounter();
+ }
+
+ /**
+ * Just get the maximum number of Frames per secounds,
+ * which is calculated with the time, one frame needs to render !
+ *
+ * this value is avaiable after the thread is started
+ * and the first frames are rendered !
+ *
+ * @see gl4java.awt.GLAnimCanvas#setAnimateFps
+ */
+ public double getMaxFps()
+ {
+ return (1.0/(double)_f_dur)*1000.0;
+ }
+
+}
+
diff --git a/gl4java/awt/GLCanvas.java b/gl4java/awt/GLCanvas.java
index da4cbfa..f997bdd 100644
--- a/gl4java/awt/GLCanvas.java
+++ b/gl4java/awt/GLCanvas.java
@@ -1,814 +1,1063 @@
-/**
- * @(#) GLCanvas.java
- */
-
-
-package gl4java.awt;
-
-import gl4java.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-/**
- * This is meant as an base class writing
- * easy render functions. A clean usage of multi-threading compatible
- * with JAVA2 is implemented in GLAnimCanvas !
- *
- * <p>
- *
- * If you are interessting in further Documentation and/or
- * the history of GL4Java follow the following link.
- *
- * <pre>
- <a href="../../GL4Java.html">The GL4Java Documentation</a>
- * </pre>
- * <p>
- *
- * You should overwrite the following methods for your needs:
- * <pre>
- <a href="GLCanvas.html#init()">preInit - initialisation before creating GLContext</a>
- <a href="GLCanvas.html#init()">init - 1st initialisation after creating GLContext</a>
- <a href="GLCanvas.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
- <a href="GLCanvas.html#display()">display - render your frame</a>
- <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize), gljResize() is allready invoked !</a>
- * </pre>
- *
- * To check if you can use the GLContext and GL and GLU methods,
- * use the function
- * <pre>
- <a href="GLCanvas.html#cvsIsInit()">cvsIsInit</a>
- * </pre>
- * <p>
- * IF you remove/release a GLCanvas,
- * e.g. you want to close/dispose it�s Window (which contains this GLCanvas),
- * you HAVE TO call:
- *
- * <pre>
- <a href="GLCanvas.html#cvsDispose()">cvsDispose</a>
- * </pre>
- * You should call this before releasing/dispose this Window !
- * Also you can overwrite this class,
- * to dispose your own elements, e.g. a Frame etc. -
- * but be shure that you call
- * cvsDispose implementation call this one !
- *
- * <p>
- * We do override the following Canvas methods.
- *
- * <pre>
- <a href="GLCanvas.html#update(java.awt.Graphics)">update</a>
- <a href="GLCanvas.html#paint(java.awt.Graphics)">paint</a>
- * </pre>
- * <p>
- *
- * @see gl4java.awt.GLAnimCanvas
- * @version 2.0, 21. April 1999
- * @author Sven Goethel
- *
- */
-public class GLCanvas extends Canvas
- implements GLEnum, GLUEnum,
- ComponentListener, WindowListener, MouseListener
-{
- protected GLContext glj = null;
- public GLFunc gl = null;
- public GLUFunc glu = null;
-
- protected Dimension size = null;
- protected boolean mustResize = false;
-
- protected boolean needCvsDispose = false;
-
- /**
- * Visual pre-set for doubleBuffer, default: true
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected boolean doubleBuffer = true;
-
- /**
- * Visual pre-set for stencil-bit number, default: 0
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected int stencilBits = 0;
-
- /**
- * Visual pre-set for accumulator buffer size, default: 0
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * This value has a special behavior.
- * For input - within the contructor,
- * it is the value for each component !
- *
- * The output value, after the constructor returns,
- * it is the summary of all accumulation bits of all components !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected int accumSize = 0;
-
- /**
- * Visual pre-set for stereoView, default: false
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected boolean stereoView = false;
-
- /**
- * Visual pre-set for RGBA usage, default: true - of course ;-)
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected boolean rgba = true;
-
- /**
- * Visual pre-set for RGBA usage, default: true - of course ;-)
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected boolean createOwnWindow = false;
-
- /**
- * The context with wich display lists and textures will be shared.
- *
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#paint
- */
- protected GLContext sharedGLContext;
-
- static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
- System.out.println("GLCanvas could not load def. native libs.");
- }
-
- /**
- *
- * Constructor
- *
- * @param width the canvas initial-prefered width
- * @param height the canvas initial-prefered height
- *
- * @param gl_Name The name of the GLFunc implementation
- * If gl_Name==null, the default class will be used !
- *
- * @param glu_Name The name of the GLUFunc implementation
- * If gl_LibName==null, the default class will be used !
- *
- */
- public GLCanvas( int width, int height,
- String gl_Name,
- String glu_Name
- )
- {
- super( );
-
- if( (gl=GLContext.createGLFunc(gl_Name)) ==null)
- {
- System.out.println("GLFunc implementation "+gl_Name+" not created");
- }
- if( (glu=GLContext.createGLUFunc(glu_Name)) ==null)
- {
- System.out.println("GLUFunc implementation "+glu_Name+" not created");
- }
-
- size = new Dimension(width, height);
-
- setSize(size);
-
- }
-
- /**
- *
- * Constructor
- *
- * Uses the default GLFunc and GLUFunc implementation !
- *
- * @param width the canvas initial-prefered width
- * @param height the canvas initial-prefered height
- *
- */
- public GLCanvas( int width, int height )
- {
- this(width, height, null, null);
- }
-
- /* GLCanvas AWT classes */
-
- public Dimension getPreferredSize() {
- return getMinimumSize();
- }
-
- public Dimension getMinimumSize() {
- return size;
- }
-
- /**
- * Used to return the created GLContext
- */
- public final GLContext getGLContext() { return glj; }
-
- /**
- *
- * Overridden update
- * This one only call's the paint method, without clearing
- * the background - thats hopefully done by OpenGL ;-)
- *
- * @param g the Graphics Context
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- */
- public void update(Graphics g)
- {
- /* let's let OpenGL clear the background ... */
- paint(g);
- }
-
- /**
- * Safe the toplevel window
- */
- protected Window topLevelWindow = null;
-
- /**
- *
- * This function returns the found TopLevelWindow,
- * which contains this Canvas ..
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- */
- public final Window getTopLevelWindow()
- { return topLevelWindow; }
-
- /**
- * this function overrides the Canvas paint method !
- *
- * For the first paint,
- * the user function preInit is called, a GLContext is created
- * and the user function init is called !
- *
- * Also, if a GL Context exist, GLCanvas's sDisplay-method will be called
- * to do OpenGL-rendering.
- *
- * The sDisplay method itself calls the display-method !
- * sDisplay is needed to be thread-safe, to manage
- * the resize functionality and to safe the time per frame.
- *
- * To define your rendering, you should overwrite the display-method
- * in your derivation.
- *
- * @see gl4java.GLContext#GLContext
- * @see gl4java.awt.GLCanvas#cvsIsInit
- * @see gl4java.awt.GLCanvas#sDisplay
- * @see gl4java.awt.GLCanvas#display
- * @see gl4java.awt.GLCanvas#preInit
- * @see gl4java.awt.GLCanvas#init
- */
- public synchronized final void paint( Graphics g )
- {
- if(glj == null || ( !glj.gljIsInit() && isGLEnabled() ) )
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLCanvas create GLContext (recreate="+
- (glj != null) +")");
- preInit();
-
- if(glj!=null) glj=null;
-
- glj = new GLContext ( this, gl, glu,
- createOwnWindow,
- doubleBuffer, stereoView,
- rgba, stencilBits, accumSize,
- sharedGLContext );
-
- if(glj!=null)
- {
- createOwnWindow = glj.isOwnWindowCreated();
- doubleBuffer = glj.isDoubleBuffer();
- stencilBits = glj.getStencilBitNumber();
- accumSize = glj.getAccumSize();
- stereoView = glj.isStereoView();
- rgba = glj.isRGBA();
- }
-
- init();
-
- // fetch the top-level window ,
- // to add us as the windowListener
- //
- Container _c = getParent();
- Container c = null;
-
- while(_c!=null)
- {
- c = _c;
- _c = _c.getParent();
- }
-
- if(c instanceof Window) {
- topLevelWindow = (Window)c;
- topLevelWindow.addComponentListener(this);
- } else {
- topLevelWindow = null;
- System.out.println("toplevel is not a Window: "+c);
- }
-
- if(topLevelWindow!=null)
- {
- topLevelWindow.addWindowListener(this);
- } else {
- System.out.println("no parent found for "+getName());
- System.out.flush();
- }
-
- /* to be able for RESIZE event's */
- addComponentListener(this);
- addMouseListener(this);
- }
-
- sDisplay();
- }
-
- /**
- *
- * This is your pre-init method.
- * preInit is called just BEFORE the GL-Context is created.
- * You should override preInit, to initialize your visual-stuff,
- * like the protected vars: doubleBuffer and stereoView
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.awt.GLCanvas#doubleBuffer
- * @see gl4java.awt.GLCanvas#stereoView
- * @see gl4java.awt.GLCanvas#rgba
- * @see gl4java.awt.GLCanvas#stencilBits
- * @see gl4java.awt.GLCanvas#accumSize
- */
- public void preInit()
- {
- }
-
- /**
- *
- * This is your init method.
- * init is called right after the GL-Context is initialized.
- * You should override init, to initialize your stuff needed
- * by OpenGL an Java !
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- */
- public void init()
- {
- }
-
- /**
- * This method is used to clean up any OpenGL stuff (delete textures
- * or whatever) prior to actually deleting the OpenGL context.
- * You should override this with your own version, if you need to do
- * any cleanup work at this phase.
- * This functions is called within cvsDispose
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#cvsDispose
- */
- public void doCleanup()
- {
- }
-
- /**
- * This function returns, if everything is init: the GLContext,
- * the and the users init function
- * This value is set in the paint method!
- *
- * @return boolean
- *
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.awt.GLCanvas#init
- */
- public boolean cvsIsInit()
- {
- if(glj!=null)
- return glj.gljIsInit();
- return false;
- }
-
- /**
- * This function enables, disables the GL-Context !
- * If false is given, the openGL renderer/context is
- * disabled and disconected (gljFree is called, if initialized) !
- *
- * If disabled, all GL Functions are disabled but the
- * Destroy & Free are not !
- *
- * @return boolean
- *
- * @see gl4java.awt.GLCanvas#cvsDispose
- * @see gl4java.GLContext#setEnable
- * @see gl4java.GLContext#gljMakeCurrent
- * @see gl4java.GLContext#gljDestroy
- * @see gl4java.GLContext#gljFree
- */
- public void setGLEnabled(boolean b)
- {
- if(glj!=null)
- glj.setEnabled(b);
- }
-
- /**
- * This function enables, disables the GL-Context !
- * If false is given, the openGL renderer/context is
- * disabled and disconected (gljFree is called, if initialized) !
- *
- * If disabled, all GL Functions are disabled but the
- * Destroy & Free are not !
- *
- * The Visible-Flag of this AWT Component is also set to the given value !
- * The setVisible(boolean) method of Component is called !
- *
- * @return boolean
- *
- * @see gl4java.awt.GLCanvas#cvsDispose
- * @see gl4java.GLContext#setEnable
- * @see gl4java.GLContext#gljMakeCurrent
- * @see gl4java.GLContext#gljDestroy
- * @see gl4java.GLContext#gljFree
- */
- public void setVisible(boolean b)
- {
- if(glj!=null)
- glj.setEnabled(b);
- super.setVisible(b);
- }
-
- /**
- * This function queries, if the GL-Context is enabled !
- *
- * @return boolean
- *
- * @see gl4java.GLContext#isEnabled
- * @see gl4java.GLContext#gljMakeCurrent
- */
- public boolean isGLEnabled()
- {
- if(glj!=null)
- return glj.isEnabled();
- return false;
- }
-
- protected long _f_dur = 0;
-
- /**
- *
- * This is the thread save rendering-method called by paint.
- * The actual thread will be set to highes priority befor calling
- * 'display'. After 'display' the priority will be reset !
- *
- * 'gljFree' will be NOT called after 'display'.
- *
- * We tested the above to use multi-threading and
- * for the demonstration 'glDemos' it works ;-)) !
- *
- * BE SURE, if you want to call 'display' by yourself
- * (e.g. in the run method for animation)
- * YOU HAVE TO CALL sDisplay -- OR YOU MUST KNOW WHAT YOU ARE DOING THEN !
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.awt.GLCanvas#display
- */
- public synchronized final void sDisplay()
- {
- boolean ok = true;
-
- long _s = System.currentTimeMillis();
-
- if(!cvsIsInit())
- {
- return;
- }
-
- if( mustResize )
- {
- if( glj.gljMakeCurrent() == true )
- {
- size = getSize();
- glj.gljResize( size.width, size.height ) ;
- reshape(size.width, size.height);
- mustResize = false;
- invalidate();
- repaint(100);
- glj.gljFree();
- }
- }
- if(ok)
- {
- display();
- }
-
- _f_dur = System.currentTimeMillis()-_s;
- }
-
- /**
- *
- * This is the rendering-method called by sDisplay
- * (and sDisplay is called by paint !).
- * The derived-class (Your Subclass) will redefine this, to draw it's own...
- *
- * <p>
- *
- * You MUST encapsulate your OpenGL call's within:
- * <pre>
- - glj.gljMakeCurrent()
- YOUR OpenGL commands here !
- - glj.gljFree()
- * </pre>
- *
- * BE SURE, if you want to call 'display' by yourself
- * (e.g. in the run method for animation)
- * YOU HAVE TO CALL sDisplay !
- *
- * 'sDisplay' manages a semaphore to avoid reentrance of
- * the display function !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- *
- * @return void
- *
- * @see gl4java.awt.GLCanvas#sDisplay
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.GLContext#gljMakeCurrent
- * @see gl4java.GLContext#gljSwap
- */
- public void display()
- {
- }
-
- /**
- *
- * This is the reshape-method called by paint.
- * The derived-class (Your Subclass) will redefine this,
- * to manage your individual reshape ...
- *
- * This �reshape� method will be invoked after the first paint command
- * after GLCanvas.componentResize is called AND only if �gljUse� was
- * succesfull (so a call of gljUse is redundant).
- * �reshape� is not an overloading of java.awt.Component.reshape,
- * �reshape� is more like �glut�-reshape.
- *
- * GLCanvas.reshape allready has a simple default implementation,
- * which calls �gljResize� and �glViewport� - so you may be can
- * left this one as it is (no need to overload).
- * The needed call to �gljResize� is done by hte invoker paint !
- *
- * @param width the new width
- * @param height the new height
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.awt.GLCanvas#sDisplay
- */
- public void reshape( int width, int height )
- {
- gl.glViewport(0,0, width, height);
- }
-
- /**
- *
- * �componentResized� is the componentListeners event handler.
- *
- * This method sets the variable �mustResize� to true,
- * so the upcoming �paint� method-call will invoke �reshape� !
- *
- * This little look-alike complicating thing is done,
- * to avoid an Exception by using the glContext from more than
- * one concurrent thread�s !
- *
- * You cannot override this implementation, it is final
- * - override �reshape' instead !
- *
- * @param e the element, which is resized
- * @return void
- *
- * @see gl4java.awt.GLCanvas#paint
- * @see gl4java.awt.GLCanvas#reshape
- */
- public void componentResized(ComponentEvent e)
- {
- if(glj!=null && glj.gljIsInit() && e.getComponent()==this )
- {
- mustResize = true;
- repaint();
- }
- }
-
- public void componentMoved(ComponentEvent e)
- {
- if(glj!=null && glj.gljIsInit())
- {
- repaint(100);
- }
- }
-
- public void componentShown(ComponentEvent e)
- {
- }
-
- public void componentHidden(ComponentEvent e)
- { }
-
- public void mouseClicked(MouseEvent e)
- {
- if(glj!=null && glj.gljIsInit())
- {
- repaint();
- }
- }
-
- public void mouseEntered(MouseEvent e)
- { }
- public void mouseExited(MouseEvent e)
- {}
- public void mousePressed(MouseEvent e)
- {
- }
- public void mouseReleased(MouseEvent e)
- {
- }
-
- public void windowOpened(WindowEvent e)
- {
- }
-
- /**
- *
- * �windowClosing� is the windowListeners event handler
- * for the topLevelWindow of this Canvas !
- *
- * This methods free�s AND destroy�s
- * the GL Context with �glj.gljDestroy� !
- *
- * @return void
- *
- */
- public void windowClosing(WindowEvent e)
- {
- if(e.getComponent().equals(topLevelWindow))
- {
- cvsDispose();
- }
- }
-
- /**
- *
- * �windowClosed� is the windowListeners event handler.
- *
- * @return void
- *
- */
- public void windowClosed(WindowEvent e)
- {
- if (needCvsDispose) cvsDispose();
- }
-
- public void windowIconified(WindowEvent e)
- {
- }
-
- public void windowDeiconified(WindowEvent e)
- {
- }
-
- public void windowActivated(WindowEvent e)
- {
- if(glj!=null && glj.gljIsInit())
- {
- repaint(100);
- }
- }
-
- public void windowDeactivated(WindowEvent e)
- {
- }
-
- /**
- * You should call this before releasing/dispose this Window !
- * Also you can overwrite this class,
- * to dispose your own elements, e.g. a Frame etc. -
- * but be shure that you call
- * cvsDispose implementation call this one !
- *
- * This function calls gljDestroy of GLContext !
- * The Visibility is set to false !
- * The Enabled is set to false either !
- *
- * To bring this component back to live,
- * you need call setVisible(true) !
- *
- * @see gl4java.GLContext#gljDestroy
- * @see gl4java.awt.GLCanvas#doCleanup
- */
- public void cvsDispose()
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLCanvas cvsDispose (doit="+
- ( (glj != null) && glj.gljIsInit() ) +")");
-
- removeComponentListener(this);
- removeMouseListener(this);
-
- if (glj != null)
- {
- if (glj.gljIsInit())
- {
- /* Sometimes the Microsoft VM calls the
- Applet.stop() method but doesn't have
- permissions to do J/Direct calls, so
- this whole block of code will throw a
- security exception. If this happens,
- however, windowClosing() will still
- call us again later and we will have
- another opportunity to shut down the
- context, so it all works out fine. */
- try
- {
- setVisible(false);
- doCleanup();
-
- glj.gljDestroy();
- needCvsDispose = false;
- }
- catch (Exception ex)
- {
- needCvsDispose = true;
- }
- }
- }
-
- // Setting glj to null will simply cause paint() to re-initialize.
- // We don't want that to happen, so we will leave glj non-null.
- }
-
- /**
- * does nothing than:
- *
- * @see gl4java.awt.GLCanvas#cvsDispose
- */
- protected void finalize()
- throws Throwable
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLCanvas finalize ..");
-
- cvsDispose();
- super.finalize();
- }
-
- /**
- * does nothing than:
- *
- * @see gl4java.awt.GLCanvas#cvsDispose
- *
- * @deprecated Use cvsDispose instead, well finalize is also implemented
- */
- public void destroy()
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLCanvas destroy ..");
-
- cvsDispose();
- }
-
- /**
- * get methods
- */
- public final int cvsGetWidth() {
- return getSize().width;
- }
- public final int cvsGetHeight() {
- return getSize().height;
- }
-}
-
+/**
+ * @(#) GLCanvas.java
+ */
+
+
+package gl4java.awt;
+
+import gl4java.*;
+import gl4java.drawable.*;
+import gl4java.drawable.utils.*;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.EventListener;
+
+/**
+ * This is meant as an base class writing
+ * easy render functions. A clean usage of multi-threading compatible
+ * with JAVA2 is implemented in GLAnimCanvas !
+ *
+ * <p>
+ *
+ * If you are interessting in further Documentation and/or
+ * the history of GL4Java follow the following link.
+ *
+ * <pre>
+ <a href="../../GL4Java.html">The GL4Java Documentation</a>
+ * </pre>
+ * <p>
+ *
+ * There are two ways of using a GLCanvas: the {@link
+ * gl4java.drawable.GLEventListener} model or the subclassing model. Earlier
+ * versions of OpenGL for Java only supported the subclassing model.
+ * The default implementations of {@link #init}, {@link #display},
+ * {@link #reshape} and {@link #doCleanup}
+ * now send events to GLEventListeners; they can
+ * still be overridden as before to support the subclassing model.
+ *
+ * <p>
+ * If using the subclassing model, you should override the following
+ * methods for your needs:
+ * <pre>
+ <a href="GLCanvas.html#init()">preInit - initialisation before creating GLContext</a>
+ <a href="GLCanvas.html#init()">init - 1st initialisation after creating GLContext</a>
+ <a href="GLCanvas.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
+ <a href="GLCanvas.html#display()">display - render your frame</a>
+ <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize), gljResize() is allready invoked !</a>
+ * </pre>
+ *
+ * To check if you can use the GLContext and GL and GLU methods,
+ * use the function
+ * <pre>
+ <a href="GLCanvas.html#cvsIsInit()">cvsIsInit</a>
+ * </pre>
+ * <p>
+ * IF you remove/release a GLCanvas,
+ * e.g. you want to close/dispose it�s Window (which contains this GLCanvas),
+ * you HAVE TO call:
+ *
+ * <pre>
+ <a href="GLCanvas.html#cvsDispose()">cvsDispose</a>
+ * </pre>
+ * You should call this before releasing/dispose this Window !
+ * Also you can overwrite this class,
+ * to dispose your own elements, e.g. a Frame etc. -
+ * but be shure that you call
+ * cvsDispose implementation call this one !
+ *
+ * <p>
+ * We do override the following Canvas methods.
+ *
+ * <pre>
+ <a href="GLCanvas.html#update(java.awt.Graphics)">update</a>
+ <a href="GLCanvas.html#paint(java.awt.Graphics)">paint</a>
+ * </pre>
+ * <p>
+ *
+ * @see gl4java.awt.GLAnimCanvas
+ * @version 2.0, 21. April 1999
+ * @author Sven Goethel
+ * */
+public class GLCanvas extends Canvas
+ implements GLEnum, GLUEnum,
+ ComponentListener, WindowListener, MouseListener,
+ GLDrawable
+{
+ protected GLContext glj = null;
+ public GLFunc gl = null;
+ public GLUFunc glu = null;
+
+ protected Dimension size = null;
+ protected boolean mustResize = false;
+
+ protected boolean needCvsDispose = false;
+
+ /**
+ * Visual pre-set for doubleBuffer, default: true
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected boolean doubleBuffer = true;
+
+ /**
+ * Visual pre-set for stencil-bit number, default: 0
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected int stencilBits = 0;
+
+ /**
+ * Visual pre-set for accumulator buffer size, default: 0
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * This value has a special behavior.
+ * For input - within the contructor,
+ * it is the value for each component !
+ *
+ * The output value, after the constructor returns,
+ * it is the summary of all accumulation bits of all components !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected int accumSize = 0;
+
+ /**
+ * Visual pre-set for stereoView, default: false
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected boolean stereoView = false;
+
+ /**
+ * Visual pre-set for RGBA usage, default: true - of course ;-)
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected boolean rgba = true;
+
+ protected GLCapabilities capabilities = null;
+
+ /**
+ * Visual pre-set for RGBA usage, default: true - of course ;-)
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected boolean createOwnWindow = false;
+
+ /**
+ * The context with wich display lists and textures will be shared.
+ *
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ protected GLContext sharedGLContext;
+
+ // The list of GLEventListeners
+ private GLEventListenerList listeners = new GLEventListenerList();
+
+ static {
+ if(GLContext.loadNativeLibraries(null, null, null)==false)
+ System.out.println("GLCanvas could not load def. native libs.");
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ * @param gl_Name The name of the GLFunc implementation
+ * If gl_Name==null, the default class will be used !
+ *
+ * @param glu_Name The name of the GLUFunc implementation
+ * If gl_LibName==null, the default class will be used !
+ *
+ */
+ public GLCanvas( GLCapabilities capabilities,
+ int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ super( );
+
+ this.capabilities=capabilities;
+
+ if( (gl=GLContext.createGLFunc(gl_Name)) ==null)
+ {
+ System.out.println("GLFunc implementation "+gl_Name+" not created");
+ }
+ if( (glu=GLContext.createGLUFunc(glu_Name)) ==null)
+ {
+ System.out.println("GLUFunc implementation "+glu_Name+" not created");
+ }
+
+ size = new Dimension(width, height);
+
+ setSize(size);
+
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ * @param gl_Name The name of the GLFunc implementation
+ * If gl_Name==null, the default class will be used !
+ *
+ * @param glu_Name The name of the GLUFunc implementation
+ * If gl_LibName==null, the default class will be used !
+ *
+ */
+ public GLCanvas( GLCapabilities capabilities,
+ int width, int height
+ )
+ {
+ this(capabilities, width, height, null, null);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ * @param gl_Name The name of the GLFunc implementation
+ * If gl_Name==null, the default class will be used !
+ *
+ * @param glu_Name The name of the GLUFunc implementation
+ * If gl_LibName==null, the default class will be used !
+ *
+ */
+ public GLCanvas( int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ this(null, width, height, gl_Name, glu_Name);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ */
+ public GLCanvas( int width, int height )
+ {
+ this(width, height, null, null);
+ }
+
+ /**
+ *
+ * Constructor (JDK 1.2 or later)
+ *
+ * @param config the GraphicsConfiguration for this canvas (>= JDK 1.2)
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ * @param gl_Name The name of the GLFunc implementation
+ * If gl_Name==null, the default class will be used !
+ *
+ * @param glu_Name The name of the GLUFunc implementation
+ * If gl_LibName==null, the default class will be used !
+ *
+ */
+ public GLCanvas( GraphicsConfiguration config,
+ GLCapabilities capabilities,
+ int width, int height,
+ String gl_Name,
+ String glu_Name
+ )
+ {
+ super( config );
+
+ this.capabilities=capabilities;
+
+ if( (gl=GLContext.createGLFunc(gl_Name)) ==null)
+ {
+ System.out.println("GLFunc implementation "+gl_Name+" not created");
+ }
+ if( (glu=GLContext.createGLUFunc(glu_Name)) ==null)
+ {
+ System.out.println("GLUFunc implementation "+glu_Name+" not created");
+ }
+
+ size = new Dimension(width, height);
+
+ setSize(size);
+
+ }
+
+ /**
+ *
+ * Constructor (JDK 1.2 or later)
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @param config the GraphicsConfiguration for this canvas (>= JDK 1.2)
+ *
+ * @param width the canvas initial-prefered width
+ * @param height the canvas initial-prefered height
+ *
+ */
+ public GLCanvas( GraphicsConfiguration config,
+ GLCapabilities capabilities,
+ int width, int height )
+ {
+ this(config, capabilities, width, height, null, null);
+ }
+
+ /* GLCanvas AWT classes */
+
+ public Dimension getPreferredSize() {
+ return getMinimumSize();
+ }
+
+ public Dimension getMinimumSize() {
+ return size;
+ }
+
+ /**
+ * Used to return the created GLContext
+ */
+ public final GLContext getGLContext() { return glj; }
+
+ /**
+ *
+ * Overridden update
+ * This one only call's the paint method, without clearing
+ * the background - thats hopefully done by OpenGL ;-)
+ *
+ * @param g the Graphics Context
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ public void update(Graphics g)
+ {
+ /* let's let OpenGL clear the background ... */
+ paint(g);
+ }
+
+ /**
+ * Safe the toplevel window
+ */
+ protected Window topLevelWindow = null;
+
+ /**
+ *
+ * This function returns the found TopLevelWindow,
+ * which contains this Canvas ..
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ */
+ public final Window getTopLevelWindow()
+ { return topLevelWindow; }
+
+ /**
+ * this function overrides the Canvas paint method !
+ *
+ * For the first paint,
+ * the user function preInit is called, a GLContext is created
+ * and the user function init is called !
+ *
+ * Also, if a GL Context exist, GLCanvas's sDisplay-method will be called
+ * to do OpenGL-rendering.
+ *
+ * The sDisplay method itself calls the display-method !
+ * sDisplay is needed to be thread-safe, to manage
+ * the resize functionality and to safe the time per frame.
+ *
+ * To define your rendering, you should overwrite the display-method
+ * in your derivation.
+ *
+ * @see gl4java.GLContext#GLContext
+ * @see gl4java.awt.GLCanvas#cvsIsInit
+ * @see gl4java.awt.GLCanvas#sDisplay
+ * @see gl4java.awt.GLCanvas#display
+ * @see gl4java.awt.GLCanvas#preInit
+ * @see gl4java.awt.GLCanvas#init
+ */
+ public synchronized final void paint( Graphics g )
+ {
+ if(glj == null || ( !glj.gljIsInit() && isGLEnabled() ) )
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLCanvas create GLContext (recreate="+
+ (glj != null) +")");
+ preInit();
+
+ if(glj!=null) glj=null;
+
+ if (capabilities != null )
+ {
+ glj = new GLContext ( this, gl, glu,
+ capabilities,
+ sharedGLContext );
+ } else {
+ glj = new GLContext ( this, gl, glu,
+ createOwnWindow,
+ doubleBuffer, stereoView,
+ rgba, stencilBits, accumSize,
+ sharedGLContext );
+ }
+
+ if(glj!=null)
+ {
+ createOwnWindow = glj.isOwnWindowCreated();
+ doubleBuffer = glj.isDoubleBuffer();
+ stencilBits = glj.getStencilBitNumber();
+ accumSize = glj.getAccumSize();
+ stereoView = glj.isStereoView();
+ rgba = glj.isRGBA();
+ }
+
+ init();
+
+ // fetch the top-level window ,
+ // to add us as the windowListener
+ //
+ Container _c = getParent();
+ Container c = null;
+
+ while(_c!=null)
+ {
+ c = _c;
+ _c = _c.getParent();
+ }
+
+ if(c instanceof Window) {
+ topLevelWindow = (Window)c;
+ topLevelWindow.addComponentListener(this);
+ } else {
+ topLevelWindow = null;
+ System.out.println("toplevel is not a Window: "+c);
+ }
+
+ if(topLevelWindow!=null)
+ {
+ topLevelWindow.addWindowListener(this);
+ } else {
+ System.out.println("no parent found for "+getName());
+ System.out.flush();
+ }
+
+ /* to be able for RESIZE event's */
+ addComponentListener(this);
+ addMouseListener(this);
+
+ /* force a reshape, to be sure .. */
+ mustResize = true;
+ }
+
+ sDisplay();
+ }
+
+ /**
+ *
+ * This is your pre-init method.
+ * preInit is called just BEFORE the GL-Context is created.
+ * You should override preInit, to initialize your visual-stuff,
+ * like the protected vars: doubleBuffer and stereoView
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.awt.GLCanvas#doubleBuffer
+ * @see gl4java.awt.GLCanvas#stereoView
+ * @see gl4java.awt.GLCanvas#rgba
+ * @see gl4java.awt.GLCanvas#stencilBits
+ * @see gl4java.awt.GLCanvas#accumSize
+ */
+ public void preInit()
+ {
+ }
+
+ /**
+ *
+ * init is called right after the GL-Context is initialized.
+ * The default implementation calls init() on all of this
+ * component's GLEventListeners.
+ *
+ * <p>
+ * If using the subclassing model, you can override this to
+ * perform one-time OpenGL initializations such as setting up
+ * lights and display lists.
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.drawable.GLEventListener#init
+ */
+ public void init()
+ {
+ listeners.sendInitEvent(this);
+ }
+
+ /**
+ * This method is used to clean up any OpenGL stuff (delete textures
+ * or whatever) prior to actually deleting the OpenGL context.
+ * You should override this with your own version, if you need to do
+ * any cleanup work at this phase.
+ * This functions is called within cvsDispose
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ * @see gl4java.drawable.GLEventListener#cleanup
+ */
+ public void doCleanup()
+ {
+ listeners.sendCleanupEvent(this);
+ }
+
+ /**
+ * This function returns, if everything is init: the GLContext,
+ * the and the users init function
+ * This value is set in the paint method!
+ *
+ * @return boolean
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.awt.GLCanvas#init
+ */
+ public boolean cvsIsInit()
+ {
+ if(glj!=null)
+ return glj.gljIsInit();
+ return false;
+ }
+
+ /**
+ * This function enables, disables the GL-Context !
+ * If false is given, the openGL renderer/context is
+ * disabled and disconected (gljFree is called, if initialized) !
+ *
+ * If disabled, all GL Functions are disabled but the
+ * Destroy & Free are not !
+ *
+ * @return boolean
+ *
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ * @see gl4java.GLContext#setEnabled
+ * @see gl4java.GLContext#gljMakeCurrent
+ * @see gl4java.GLContext#gljDestroy
+ * @see gl4java.GLContext#gljFree
+ */
+ public void setGLEnabled(boolean b)
+ {
+ if(glj!=null)
+ glj.setEnabled(b);
+ }
+
+ /**
+ * This function enables, disables the GL-Context !
+ * If false is given, the openGL renderer/context is
+ * disabled and disconected (gljFree is called, if initialized) !
+ *
+ * If disabled, all GL Functions are disabled but the
+ * Destroy & Free are not !
+ *
+ * The Visible-Flag of this AWT Component is also set to the given value !
+ * The setVisible(boolean) method of Component is called !
+ *
+ * @return boolean
+ *
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ * @see gl4java.GLContext#setEnabled
+ * @see gl4java.GLContext#gljMakeCurrent
+ * @see gl4java.GLContext#gljDestroy
+ * @see gl4java.GLContext#gljFree
+ */
+ public void setVisible(boolean b)
+ {
+ if(glj!=null)
+ glj.setEnabled(b);
+ super.setVisible(b);
+ }
+
+ /**
+ * This function queries, if the GL-Context is enabled !
+ *
+ * @return boolean
+ *
+ * @see gl4java.GLContext#isEnabled
+ * @see gl4java.GLContext#gljMakeCurrent
+ */
+ public boolean isGLEnabled()
+ {
+ if(glj!=null)
+ return glj.isEnabled();
+ return false;
+ }
+
+ protected long _f_dur = 0;
+
+ /**
+ *
+ * This is the thread save rendering-method called by paint.
+ * The actual thread will be set to highes priority befor calling
+ * 'display'. After 'display' the priority will be reset !
+ *
+ * 'gljFree' will be NOT called after 'display'.
+ *
+ * We tested the above to use multi-threading and
+ * for the demonstration 'glDemos' it works ;-)) !
+ *
+ * BE SURE, if you want to call 'display' by yourself
+ * (e.g. in the run method for animation)
+ * YOU HAVE TO CALL sDisplay -- OR YOU MUST KNOW WHAT YOU ARE DOING THEN !
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.awt.GLCanvas#display
+ */
+ public synchronized final void sDisplay()
+ {
+ boolean ok = true;
+
+ if(!cvsIsInit())
+ {
+ return;
+ }
+
+ if( mustResize )
+ {
+ if( glj.gljMakeCurrent() == true )
+ {
+ size = getSize();
+ glj.gljResize( size.width, size.height ) ;
+ reshape(size.width, size.height);
+ mustResize = false;
+ invalidate();
+ repaint(100);
+ glj.gljFree();
+ }
+ }
+
+ long _s = System.currentTimeMillis();
+
+ if(ok)
+ {
+ display();
+ }
+
+ _f_dur = System.currentTimeMillis()-_s;
+ }
+
+ /**
+ *
+ * This is the rendering-method called by sDisplay
+ * (and sDisplay is called by paint !).
+ *
+ * <p>
+ * The default implementation of display() sends
+ * preDisplay, display and postDisplay events to
+ * all {@link gl4java.GLEventListener}s associated with this
+ * GLCanvas in the above order.
+ *
+ * <p>
+ * <pre>
+ reset timer for frame duration (done by sDisplay)
+
+ for_all(gl4java.GLEventListener)
+ SEND preDisplay
+
+ if( gljMakeCurrent() )
+ {
+ for_all(gl4java.GLEventListener)
+ SEND display
+ gljFree()
+ gljSwap()
+
+ for_all(gl4java.GLEventListener)
+ SEND postDisplay
+ }
+
+ stop timer for frame duration (done by sDisplay)
+ * </pre>
+ *
+ * <p>
+ * If you use the subclassing model (as opposed to the
+ * GLEventListener model), your subclass will redefine this to
+ * perform its OpenGL drawing. In this case you MUST encapsulate
+ * your OpenGL calls within:
+ * <pre>
+ - glj.gljMakeCurrent()
+ YOUR OpenGL commands here !
+ - glj.gljFree()
+ * </pre>
+ *
+ * BE SURE, if you want to call 'display' by yourself
+ * (e.g. in the run method for animation)
+ * YOU HAVE TO CALL sDisplay !
+ *
+ * 'sDisplay' manages a semaphore to avoid reentrance of
+ * the display function !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#sDisplay
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.GLContext#gljMakeCurrent
+ * @see gl4java.GLContext#gljSwap
+ * @see gl4java.drawable.GLEventListener#preDisplay
+ * @see gl4java.drawable.GLEventListener#display
+ * @see gl4java.drawable.GLEventListener#postDisplay
+ */
+ public void display()
+ {
+ listeners.sendPreDisplayEvent(this);
+
+ if (glj.gljMakeCurrent()) {
+ listeners.sendDisplayEvent(this);
+
+ glj.gljSwap();
+ glj.gljCheckGL();
+ glj.gljFree();
+
+ listeners.sendPostDisplayEvent(this);
+ }
+
+ }
+
+ /**
+ *
+ * This �reshape� method will be invoked after the first paint command
+ * after GLCanvas.componentResize is called AND only if �gljMakeCurrent� was
+ * successful (so a call of gljMakeCurrent is redundant).
+ * �reshape� is not an overloading of java.awt.Component.reshape,
+ * �reshape� is more like �glut�-reshape.
+ *
+ * <p>
+ * GLCanvas.reshape already has a simple default implementation,
+ * which calls �gljResize� and �glViewport�. It also sends the
+ * reshape() event to all GLEventListeners. If using the
+ * GLEventListener model, it may not be necessary to do anything
+ * in your event listener's reshape() method; if using the
+ * subclassing model, it may not be necessary to override this.
+ *
+ * <p>
+ * The needed call to �gljResize� is done by the invoker paint !
+ *
+ * @param width the new width
+ * @param height the new height
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.awt.GLCanvas#sDisplay
+ * @see gl4java.drawable.GLEventListener#reshape
+ */
+ public void reshape( int width, int height )
+ {
+ gl.glViewport(0,0, width, height);
+ listeners.sendReshapeEvent(this, width, height);
+ }
+
+ /**
+ *
+ * �componentResized� is the componentListeners event handler.
+ *
+ * This method sets the variable �mustResize� to true,
+ * so the upcoming �paint� method-call will invoke �reshape� !
+ *
+ * This little look-alike complicating thing is done,
+ * to avoid an Exception by using the glContext from more than
+ * one concurrent thread�s !
+ *
+ * You cannot override this implementation, it is final
+ * - override �reshape' instead !
+ *
+ * @param e the element, which is resized
+ * @return void
+ *
+ * @see gl4java.awt.GLCanvas#paint
+ * @see gl4java.awt.GLCanvas#reshape
+ */
+ public void componentResized(ComponentEvent e)
+ {
+ if(glj!=null && glj.gljIsInit() && e.getComponent()==this )
+ {
+ mustResize = true;
+ repaint();
+ }
+ }
+
+ public void componentMoved(ComponentEvent e)
+ {
+ if(glj!=null && glj.gljIsInit())
+ {
+ repaint(100);
+ }
+ }
+
+ public void componentShown(ComponentEvent e)
+ {
+ }
+
+ public void componentHidden(ComponentEvent e)
+ { }
+
+ public void mouseClicked(MouseEvent e)
+ {
+ if(glj!=null && glj.gljIsInit())
+ {
+ repaint();
+ }
+ }
+
+ public void mouseEntered(MouseEvent e)
+ { }
+ public void mouseExited(MouseEvent e)
+ {}
+ public void mousePressed(MouseEvent e)
+ {
+ }
+ public void mouseReleased(MouseEvent e)
+ {
+ }
+
+ public void windowOpened(WindowEvent e)
+ {
+ }
+
+ /**
+ *
+ * �windowClosing� is the windowListeners event handler
+ * for the topLevelWindow of this Canvas !
+ *
+ * This methods free�s AND destroy�s
+ * the GL Context with �glj.gljDestroy� !
+ *
+ * @return void
+ *
+ */
+ public void windowClosing(WindowEvent e)
+ {
+ if(e.getComponent().equals(topLevelWindow))
+ {
+ cvsDispose();
+ }
+ }
+
+ /**
+ *
+ * �windowClosed� is the windowListeners event handler.
+ *
+ * @return void
+ *
+ */
+ public void windowClosed(WindowEvent e)
+ {
+ if (needCvsDispose) cvsDispose();
+ }
+
+ public void windowIconified(WindowEvent e)
+ {
+ }
+
+ public void windowDeiconified(WindowEvent e)
+ {
+ }
+
+ public void windowActivated(WindowEvent e)
+ {
+ if(glj!=null && glj.gljIsInit())
+ {
+ repaint(100);
+ }
+ }
+
+ public void windowDeactivated(WindowEvent e)
+ {
+ }
+
+ /**
+ * You should call this before releasing/dispose this Window !
+ * Also you can overwrite this class,
+ * to dispose your own elements, e.g. a Frame etc. -
+ * but be shure that you call
+ * cvsDispose implementation call this one !
+ *
+ * This function calls gljDestroy of GLContext !
+ * The Visibility is set to false !
+ * The Enabled is set to false either !
+ *
+ * To bring this component back to live,
+ * you need call setVisible(true) !
+ *
+ * @see gl4java.GLContext#gljDestroy
+ * @see gl4java.awt.GLCanvas#doCleanup
+ */
+ public void cvsDispose()
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLCanvas cvsDispose (doit="+
+ ( (glj != null) && glj.gljIsInit() ) +")");
+
+ removeComponentListener(this);
+ removeMouseListener(this);
+
+ if (glj != null)
+ {
+ if (glj.gljIsInit())
+ {
+ /* Sometimes the Microsoft VM calls the
+ Applet.stop() method but doesn't have
+ permissions to do J/Direct calls, so
+ this whole block of code will throw a
+ security exception. If this happens,
+ however, windowClosing() will still
+ call us again later and we will have
+ another opportunity to shut down the
+ context, so it all works out fine. */
+ try
+ {
+ setVisible(false);
+ doCleanup();
+
+ glj.gljDestroy();
+ needCvsDispose = false;
+ }
+ catch (Exception ex)
+ {
+ needCvsDispose = true;
+ }
+ }
+ }
+
+ // Setting glj to null will simply cause paint() to re-initialize.
+ // We don't want that to happen, so we will leave glj non-null.
+ }
+
+ /**
+ * does nothing than:
+ *
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ */
+ protected void finalize()
+ throws Throwable
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLCanvas finalize ..");
+
+ cvsDispose();
+ super.finalize();
+ }
+
+ /**
+ * does nothing than:
+ *
+ * @see gl4java.awt.GLCanvas#cvsDispose
+ *
+ * @deprecated Use cvsDispose instead, well finalize is also implemented
+ */
+ public void destroy()
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLCanvas destroy ..");
+
+ cvsDispose();
+ }
+
+ /**
+ * get methods
+ */
+ public final int cvsGetWidth() {
+ return getSize().width;
+ }
+ public final int cvsGetHeight() {
+ return getSize().height;
+ }
+
+ //----------------------------------------------------------------------
+ // Implementation of GLDrawable
+ //
+
+ public void addGLEventListener(GLEventListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeGLEventListener(GLEventListener listener) {
+ listeners.remove(listener);
+ }
+
+ public EventListener[] getListeners(Class listenerType)
+ throws ClassCastException
+ {
+ EventListener[] evtlst=null;
+ Class _GLEventListener = null;
+
+ try {
+ _GLEventListener = Class.forName("gl4java.drawable.GLEventListener");
+ } catch (Exception ex) {
+ System.out.println(ex);
+ }
+
+ if (_GLEventListener!=null &&
+ listenerType.isAssignableFrom(_GLEventListener) )
+ evtlst = listeners.getListeners();
+
+ EventListener[] t_evtlst = super.getListeners(listenerType);
+
+ if(t_evtlst==null || t_evtlst.length==0)
+ return evtlst;
+
+ if(evtlst==null || evtlst.length==0)
+ return t_evtlst;
+
+ EventListener[] n_evtlst =
+ new EventListener[t_evtlst.length+evtlst.length];
+
+ try {
+ System.arraycopy(evtlst, 0, n_evtlst, 0, evtlst.length);
+ System.arraycopy(t_evtlst, 0, n_evtlst, evtlst.length, t_evtlst.length);
+ } catch (Exception ex)
+ { System.out.println(ex); }
+
+ evtlst = null;
+ t_evtlst = null;
+
+ return n_evtlst;
+ }
+
+ public GLFunc getGL() {
+ return gl;
+ }
+
+ public GLUFunc getGLU() {
+ return glu;
+ }
+}
diff --git a/gl4java/awt/GLImageCanvas.java b/gl4java/awt/GLImageCanvas.java
index 113d589..0a87785 100755
--- a/gl4java/awt/GLImageCanvas.java
+++ b/gl4java/awt/GLImageCanvas.java
@@ -1,402 +1,409 @@
-/**
- * @(#) GLImageCanvas.java
- */
-
-
-package gl4java.awt;
-
-import gl4java.*;
-import gl4java.utils.*;
-import gl4java.utils.textures.*;
-
-import java.awt.*;
-import java.net.*;
-
-/**
- * This Class provides a simple universal
- * Image/Texture OpenGL Canvas !
- *
- * A special demo/application for this class can be found
- * in "demos/MiscDemos/GLImageViewerCanvas.java" !
- *
- * @see TextureLoader
- * @author Sven Goethel
- *
- */
-public class GLImageCanvas extends GLCanvas
-{
- int texName[] = {0};
- TextureLoader txtLoader = null;
- boolean newText = false;
- boolean keepAspect = true;
- boolean zoomImg = true;
-
- TextureGrabber textGrab4Snapshot = null;
- String textGrab4SnapshotFName = null;
- URL textGrab4SnapshotURL = null;
- String textGrab4SnapshotURI = null;
-
- public GLImageCanvas(int w, int h)
- {
- super(w, h);
- }
-
- public void setKeepAspectRatio(boolean v)
- { keepAspect=v; }
-
- public boolean getKeepAspectRatio()
- { return keepAspect; }
-
- public void setZoomAble(boolean v)
- { zoomImg = v; }
-
- public boolean getZoomAble()
- { return zoomImg; }
-
- public TextureLoader getTextureLoader()
- { return txtLoader; }
-
- public void setOriginalSize()
- {
- if(txtLoader!=null && txtLoader.isOk())
- {
- internalSetSize( txtLoader.getImageWidth(),
- txtLoader.getImageHeight() );
- }
- }
-
- /**
- * Creates a snapshot (save texture/image) of the current
- * GL-Context !
- *
- * The snapshot itself is created delayed,
- * so no return value is avaiable.
- * Because this is a non critical path, I hope its enough !
- *
- * @param tg The TextureGrabber
- * @param fname The filename
- * @see TextureGrabber
- */
- public void snapshot(TextureGrabber tg, String fname)
- {
- textGrab4Snapshot=tg;
- textGrab4SnapshotFName=fname;
- repaint();
- }
-
- /**
- * Creates a snapshot (save texture/image) of the current
- * GL-Context !
- *
- * The snapshot itself is created delayed,
- * so no return value is avaiable.
- * Because this is a non critical path, I hope its enough !
- *
- * @param tg The TextureGrabber
- * @param base The base URL
- * @param uri The additional uri for the base URL
- * @see TextureGrabber
- */
- public void snapshot(TextureGrabber tg, URL base, String uri)
- {
- textGrab4Snapshot=tg;
- textGrab4SnapshotURL = base;
- textGrab4SnapshotURI = uri;
- repaint();
- }
-
- public Dimension getPreferredSize() {
- return getMinimumSize();
- }
-
- public Dimension getMinimumSize() {
- return getSize();
- }
-
- protected void internalSetSize(int w, int h)
- {
- setSize( w, h );
- invalidate();
-
- Window holder = Tool.getWindow(this);
-
- if(holder!=null)
- {
- holder.invalidate();
- holder.pack();
- holder.repaint();
- }
- }
-
- public void preInit()
- {
- // createOwnWindow = true;
- }
-
- public void init()
- {
- gl.glEnable(GL_TEXTURE_2D);
-
- gl.glGenTextures(1,texName);
- gl.glBindTexture(GL_TEXTURE_2D,texName[0]);
-
- gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
- gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
- gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- gl.glShadeModel (GL_SMOOTH);
-
- gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
-
- reshape(getSize().width, getSize().height);
- }
-
- /**
- * Loads an Image of the appropiate type,
- * and renders and resizes the complete window !
- *
- * @param fname The filename
- * @param type The type of file, e.g. TextureLoader is used !
- * The following types are currently allowed:
- * "png" for PngTextureLoader,
- * "ppm" for PPMAsciiTextureLoader,
- * "tga" for PPMAsciiTextureLoader,
- * "any" for AWTTextureLoader !
- */
- public boolean loadTexture(String fname, String type)
- {
- return loadTexture(fname, null, null, type);
- }
-
- /**
- * Loads an Image of the appropiate type,
- * and renders and resizes the complete window !
- *
- * @param base The base URL
- * @param uri The additional uri for the base URL
- * @param type The type of file, e.g. TextureLoader is used !
- * The following types are currently allowed:
- * "png" for PngTextureLoader,
- * "ppm" for PPMAsciiTextureLoader,
- * "tga" for PPMAsciiTextureLoader,
- * "any" for AWTTextureLoader !
- */
- public boolean loadTexture(URL base, String uri, String type)
- {
- return loadTexture(null, base, uri, type);
- }
-
- protected boolean loadTexture(String fname,
- URL base, String uri, String type)
- {
- boolean ok = true;
-
- if( glj.gljMakeCurrent() == false )
- {
- System.out.println("problem in use() method");
- return false;
- }
-
- // texture laden
- if(type.equals("png"))
- txtLoader = new PngTextureLoader(gl, glu);
- else if(type.equals("ppm"))
- txtLoader = new PPMAsciiTextureLoader(gl, glu);
- else if(type.equals("tga"))
- txtLoader = new TGATextureLoader(gl, glu);
- else if(type.equals("any"))
- txtLoader = new AWTTextureLoader(this, gl, glu);
- else {
- System.out.println("Imagetype: "+type+" is currently not supported !");
- ok = false;
- }
-
- if(ok)
- {
- try {
- if(fname!=null)
- txtLoader.readTexture(fname);
- else
- txtLoader.readTexture(base, uri);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- if(ok && txtLoader.isOk())
- {
- gl.glEnable(GL_TEXTURE_2D);
-
- txtLoader.texImage2DNonScaled(true);
-
- gl.glDisable(GL_TEXTURE_2D);
- System.out.println("texture succesfully loaded !");
- System.out.println("texture: "+txtLoader);
- }
- glj.gljCheckGL();
- glj.gljFree();
- if(ok) {
- internalSetSize( txtLoader.getImageWidth(),
- txtLoader.getImageHeight() );
- }
- return ok;
- }
-
- public void display()
- {
- int i;
-
- /* Standard GL4Java Init */
- if( glj.gljMakeCurrent() == false )
- {
- System.out.println("problem in use() method");
- return;
- }
-
- SetCamera();
-
- // just render it
- gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- DrawObj(false);
-
- if(textGrab4Snapshot!=null)
- {
- textGrab4Snapshot.grabPixels(GL_BACK,
- 0, 0, cvsGetWidth(), cvsGetHeight());
- if(textGrab4SnapshotFName!=null)
- textGrab4Snapshot.write2File(textGrab4SnapshotFName);
- else
- textGrab4Snapshot.write2File(textGrab4SnapshotURL,
- textGrab4SnapshotURI);
- textGrab4Snapshot =null;
- textGrab4SnapshotFName=null;
- textGrab4SnapshotURL =null;
- textGrab4SnapshotURI =null;
- }
-
- /* For your animation dutys ;-) */
- glj.gljSwap();
- glj.gljCheckGL();
- glj.gljFree();
- }
-
- /**
- * to prevent a deadlock in recursive
- * reshape .. internalSetSize .. pack .. resize -> reshape !
- */
- private int reshape_resize_sema = 1;
-
- public void reshape(int w, int h)
- {
- if(reshape_resize_sema>0 &&
- keepAspect && txtLoader!=null && txtLoader.isOk())
- {
- reshape_resize_sema--;
-
- int rw=w; int rh=h;
- if(zoomImg)
- {
- double iaspect = (double)txtLoader.getImageWidth()/
- (double)txtLoader.getImageHeight();
- if(rw<rh)
- {
- h = (int) ((rw / iaspect)+0.5);
- } else {
- w = (int) ((rh * iaspect)+0.5);
- }
- } else {
- w = txtLoader.getImageWidth();
- h = txtLoader.getImageHeight();
- }
- if(rw!=w || rh!=h)
- {
- internalSetSize( w, h );
- return ; /* the true resize is coming up ... */
- }
- }
- reshape_resize_sema=1;
- gl.glViewport (0, 0, w, h);
- SetCamera();
- }
-
-
- protected void DrawObj(boolean blend)
- {
- gl.glPushMatrix();
- if(blend)
- {
- gl.glEnable(GL_BLEND);
- gl.glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- }
-
- gl.glColor4f(1f,1f,1f,1f);
-
- if(txtLoader!=null && txtLoader.isOk())
- {
- gl.glEnable(GL_TEXTURE_2D);
- gl.glBegin(GL_QUADS);
-
- gl.glNormal3f(0f,0f,1f);
- gl.glTexCoord2f(0f,0f);
- gl.glVertex2f(0f, 0f);
-
- gl.glNormal3f(0f,0f,1f);
- gl.glTexCoord2f(0f,1f);
- gl.glVertex2f(0f, 1f);
-
- gl.glNormal3f(0f,0f,1f);
- gl.glTexCoord2f(1f,1f);
- gl.glVertex2f(1f, 1f);
-
- gl.glNormal3f(0f,0f,1f);
- gl.glTexCoord2f(1f,0f);
- gl.glVertex2f(1f, 0f);
-
- gl.glEnd();
- gl.glDisable(GL_TEXTURE_2D);
- }
-
- if(blend)
- gl.glDisable(GL_BLEND);
-
- gl.glPopMatrix();
- }
-
- protected void SetCamera()
- {
- float imgwidth = 1f;
- float imgheight = 1f;
- float txtdx=0f;
- float txtdy=0f;
-
- if(txtLoader!=null && txtLoader.isOk())
- {
- Dimension idim = new Dimension(txtLoader.getImageWidth(),
- txtLoader.getImageHeight());
- Dimension tdim = new Dimension(txtLoader.getTextureWidth(),
- txtLoader.getTextureHeight());
-
- imgwidth = (float)idim.width/(float)tdim.width;
- imgheight = (float)idim.height/(float)tdim.height;
-
- /*
- System.out.println("image : "+idim);
- System.out.println("text : "+tdim);
- System.out.println("image/text : "+imgwidth+"/"+imgheight);
- */
- }
-
- gl.glMatrixMode (GL_PROJECTION);
- gl.glLoadIdentity ();
- glu.gluOrtho2D(0, imgwidth,
- 0, imgheight);
-
- gl.glMatrixMode (GL_MODELVIEW);
- gl.glLoadIdentity ();
- }
-
-}
-
+/**
+ * @(#) GLImageCanvas.java
+ */
+
+
+package gl4java.awt;
+
+import gl4java.*;
+import gl4java.utils.*;
+import gl4java.utils.textures.*;
+
+import java.awt.*;
+import java.net.*;
+
+/**
+ * This Class provides a simple universal
+ * Image/Texture OpenGL Canvas !
+ *
+ * A special demo/application for this class can be found
+ * in "demos/MiscDemos/GLImageViewerCanvas.java" !
+ *
+ * @see TextureLoader
+ * @author Sven Goethel
+ *
+ */
+public class GLImageCanvas extends GLCanvas
+{
+ int texName[] = {0};
+ TextureLoader txtLoader = null;
+ boolean newText = false;
+ boolean keepAspect = true;
+ boolean zoomImg = true;
+
+ TextureGrabber textGrab4Snapshot = null;
+ String textGrab4SnapshotFName = null;
+ URL textGrab4SnapshotURL = null;
+ String textGrab4SnapshotURI = null;
+
+ public GLImageCanvas(int w, int h)
+ {
+ super(w, h);
+ }
+
+ public GLImageCanvas( GraphicsConfiguration config,
+ GLCapabilities capabilities,
+ int w, int h)
+ {
+ super(config, capabilities, w, h);
+ }
+
+ public void setKeepAspectRatio(boolean v)
+ { keepAspect=v; }
+
+ public boolean getKeepAspectRatio()
+ { return keepAspect; }
+
+ public void setZoomAble(boolean v)
+ { zoomImg = v; }
+
+ public boolean getZoomAble()
+ { return zoomImg; }
+
+ public TextureLoader getTextureLoader()
+ { return txtLoader; }
+
+ public void setOriginalSize()
+ {
+ if(txtLoader!=null && txtLoader.isOk())
+ {
+ internalSetSize( txtLoader.getImageWidth(),
+ txtLoader.getImageHeight() );
+ }
+ }
+
+ /**
+ * Creates a snapshot (save texture/image) of the current
+ * GL-Context !
+ *
+ * The snapshot itself is created delayed,
+ * so no return value is avaiable.
+ * Because this is a non critical path, I hope its enough !
+ *
+ * @param tg The TextureGrabber
+ * @param fname The filename
+ * @see TextureGrabber
+ */
+ public void snapshot(TextureGrabber tg, String fname)
+ {
+ textGrab4Snapshot=tg;
+ textGrab4SnapshotFName=fname;
+ repaint();
+ }
+
+ /**
+ * Creates a snapshot (save texture/image) of the current
+ * GL-Context !
+ *
+ * The snapshot itself is created delayed,
+ * so no return value is avaiable.
+ * Because this is a non critical path, I hope its enough !
+ *
+ * @param tg The TextureGrabber
+ * @param base The base URL
+ * @param uri The additional uri for the base URL
+ * @see TextureGrabber
+ */
+ public void snapshot(TextureGrabber tg, URL base, String uri)
+ {
+ textGrab4Snapshot=tg;
+ textGrab4SnapshotURL = base;
+ textGrab4SnapshotURI = uri;
+ repaint();
+ }
+
+ public Dimension getPreferredSize() {
+ return getMinimumSize();
+ }
+
+ public Dimension getMinimumSize() {
+ return getSize();
+ }
+
+ protected void internalSetSize(int w, int h)
+ {
+ setSize( w, h );
+ invalidate();
+
+ Window holder = Tool.getWindow(this);
+
+ if(holder!=null)
+ {
+ holder.invalidate();
+ holder.pack();
+ holder.repaint();
+ }
+ }
+
+ public void preInit()
+ {
+ // createOwnWindow = true;
+ }
+
+ public void init()
+ {
+ gl.glEnable(GL_TEXTURE_2D);
+
+ gl.glGenTextures(1,texName);
+ gl.glBindTexture(GL_TEXTURE_2D,texName[0]);
+
+ gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
+ gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
+ gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ gl.glShadeModel (GL_SMOOTH);
+
+ gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
+
+ reshape(getSize().width, getSize().height);
+ }
+
+ /**
+ * Loads an Image of the appropiate type,
+ * and renders and resizes the complete window !
+ *
+ * @param fname The filename
+ * @param type The type of file, e.g. TextureLoader is used !
+ * The following types are currently allowed:
+ * "png" for PngTextureLoader,
+ * "ppm" for PPMAsciiTextureLoader,
+ * "tga" for PPMAsciiTextureLoader,
+ * "any" for AWTTextureLoader !
+ */
+ public boolean loadTexture(String fname, String type)
+ {
+ return loadTexture(fname, null, null, type);
+ }
+
+ /**
+ * Loads an Image of the appropiate type,
+ * and renders and resizes the complete window !
+ *
+ * @param base The base URL
+ * @param uri The additional uri for the base URL
+ * @param type The type of file, e.g. TextureLoader is used !
+ * The following types are currently allowed:
+ * "png" for PngTextureLoader,
+ * "ppm" for PPMAsciiTextureLoader,
+ * "tga" for PPMAsciiTextureLoader,
+ * "any" for AWTTextureLoader !
+ */
+ public boolean loadTexture(URL base, String uri, String type)
+ {
+ return loadTexture(null, base, uri, type);
+ }
+
+ protected boolean loadTexture(String fname,
+ URL base, String uri, String type)
+ {
+ boolean ok = true;
+
+ if( glj.gljMakeCurrent() == false )
+ {
+ System.out.println("problem in use() method");
+ return false;
+ }
+
+ // texture laden
+ if(type.equals("png"))
+ txtLoader = new PngTextureLoader(gl, glu);
+ else if(type.equals("ppm"))
+ txtLoader = new PPMAsciiTextureLoader(gl, glu);
+ else if(type.equals("tga"))
+ txtLoader = new TGATextureLoader(gl, glu);
+ else if(type.equals("any"))
+ txtLoader = new AWTTextureLoader(this, gl, glu);
+ else {
+ System.out.println("Imagetype: "+type+" is currently not supported !");
+ ok = false;
+ }
+
+ if(ok)
+ {
+ try {
+ if(fname!=null)
+ txtLoader.readTexture(fname);
+ else
+ txtLoader.readTexture(base, uri);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if(ok && txtLoader.isOk())
+ {
+ gl.glEnable(GL_TEXTURE_2D);
+
+ txtLoader.texImage2DNonScaled(true);
+
+ gl.glDisable(GL_TEXTURE_2D);
+ System.out.println("texture succesfully loaded !");
+ System.out.println("texture: "+txtLoader);
+ }
+ glj.gljCheckGL();
+ glj.gljFree();
+ if(ok) {
+ internalSetSize( txtLoader.getImageWidth(),
+ txtLoader.getImageHeight() );
+ }
+ return ok;
+ }
+
+ public void display()
+ {
+ int i;
+
+ /* Standard GL4Java Init */
+ if( glj.gljMakeCurrent() == false )
+ {
+ System.out.println("problem in use() method");
+ return;
+ }
+
+ SetCamera();
+
+ // just render it
+ gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ DrawObj(false);
+
+ if(textGrab4Snapshot!=null)
+ {
+ textGrab4Snapshot.grabPixels(GL_BACK,
+ 0, 0, cvsGetWidth(), cvsGetHeight());
+ if(textGrab4SnapshotFName!=null)
+ textGrab4Snapshot.write2File(textGrab4SnapshotFName);
+ else
+ textGrab4Snapshot.write2File(textGrab4SnapshotURL,
+ textGrab4SnapshotURI);
+ textGrab4Snapshot =null;
+ textGrab4SnapshotFName=null;
+ textGrab4SnapshotURL =null;
+ textGrab4SnapshotURI =null;
+ }
+
+ /* For your animation dutys ;-) */
+ glj.gljSwap();
+ glj.gljCheckGL();
+ glj.gljFree();
+ }
+
+ /**
+ * to prevent a deadlock in recursive
+ * reshape .. internalSetSize .. pack .. resize -> reshape !
+ */
+ private int reshape_resize_sema = 1;
+
+ public void reshape(int w, int h)
+ {
+ if(reshape_resize_sema>0 &&
+ keepAspect && txtLoader!=null && txtLoader.isOk())
+ {
+ reshape_resize_sema--;
+
+ int rw=w; int rh=h;
+ if(zoomImg)
+ {
+ double iaspect = (double)txtLoader.getImageWidth()/
+ (double)txtLoader.getImageHeight();
+ if(rw<rh)
+ {
+ h = (int) ((rw / iaspect)+0.5);
+ } else {
+ w = (int) ((rh * iaspect)+0.5);
+ }
+ } else {
+ w = txtLoader.getImageWidth();
+ h = txtLoader.getImageHeight();
+ }
+ if(rw!=w || rh!=h)
+ {
+ internalSetSize( w, h );
+ return ; /* the true resize is coming up ... */
+ }
+ }
+ reshape_resize_sema=1;
+ gl.glViewport (0, 0, w, h);
+ SetCamera();
+ }
+
+
+ protected void DrawObj(boolean blend)
+ {
+ gl.glPushMatrix();
+ if(blend)
+ {
+ gl.glEnable(GL_BLEND);
+ gl.glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ gl.glColor4f(1f,1f,1f,1f);
+
+ if(txtLoader!=null && txtLoader.isOk())
+ {
+ gl.glEnable(GL_TEXTURE_2D);
+ gl.glBegin(GL_QUADS);
+
+ gl.glNormal3f(0f,0f,1f);
+ gl.glTexCoord2f(0f,0f);
+ gl.glVertex2f(0f, 0f);
+
+ gl.glNormal3f(0f,0f,1f);
+ gl.glTexCoord2f(0f,1f);
+ gl.glVertex2f(0f, 1f);
+
+ gl.glNormal3f(0f,0f,1f);
+ gl.glTexCoord2f(1f,1f);
+ gl.glVertex2f(1f, 1f);
+
+ gl.glNormal3f(0f,0f,1f);
+ gl.glTexCoord2f(1f,0f);
+ gl.glVertex2f(1f, 0f);
+
+ gl.glEnd();
+ gl.glDisable(GL_TEXTURE_2D);
+ }
+
+ if(blend)
+ gl.glDisable(GL_BLEND);
+
+ gl.glPopMatrix();
+ }
+
+ protected void SetCamera()
+ {
+ float imgwidth = 1f;
+ float imgheight = 1f;
+ float txtdx=0f;
+ float txtdy=0f;
+
+ if(txtLoader!=null && txtLoader.isOk())
+ {
+ Dimension idim = new Dimension(txtLoader.getImageWidth(),
+ txtLoader.getImageHeight());
+ Dimension tdim = new Dimension(txtLoader.getTextureWidth(),
+ txtLoader.getTextureHeight());
+
+ imgwidth = (float)idim.width/(float)tdim.width;
+ imgheight = (float)idim.height/(float)tdim.height;
+
+ /*
+ System.out.println("image : "+idim);
+ System.out.println("text : "+tdim);
+ System.out.println("image/text : "+imgwidth+"/"+imgheight);
+ */
+ }
+
+ gl.glMatrixMode (GL_PROJECTION);
+ gl.glLoadIdentity ();
+ glu.gluOrtho2D(0, imgwidth,
+ 0, imgheight);
+
+ gl.glMatrixMode (GL_MODELVIEW);
+ gl.glLoadIdentity ();
+ }
+
+}
+
diff --git a/gl4java/swing/GLAnimJPanel.java b/gl4java/swing/GLAnimJPanel.java
index a7af76a..bdbdd94 100644
--- a/gl4java/swing/GLAnimJPanel.java
+++ b/gl4java/swing/GLAnimJPanel.java
@@ -24,6 +24,25 @@ import java.lang.Math;
* <pre>
<a href="../../GL4Java.html">The GL4Java Documentation</a>
* </pre>
+ *
+ * <p>
+ * There are two ways of using a GLAnimJPanel: the {@link
+ * gl4java.GLEventListener} model or the subclassing model. Earlier
+ * versions of the system only supported the subclassing model. The
+ * default implementations of {@link #init}, {@link #display},
+ * {@link #reshape} and {@link #doCleanup}
+ * now send events to GLEventListeners; they can
+ * still be overridden as before to support the subclassing model.
+ *
+ * <p>
+ * If using the subclassing model, you should override the following
+ * methods for your needs:
+ * <pre>
+ <a href="GLAnimJPanel.html#init()">init - 1st initialisation</a>
+ <a href="GLAnimJPanel.html#display()">display - render one frame</a>
+ <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize)</a>
+ <a href="GLAnimJPanel.html#ReInit()">ReInit - ReInitialisation after stop for setSuspended(false)</a>
+ * </pre>
* <p>
*
* This code uses repaint() to fire a sDisplay call by the AWT-Event thread !
@@ -93,14 +112,6 @@ import java.lang.Math;
* </pre>
* Like the first animation run, this class renders a view frames (default 10)
* to subtract the render time from the sleep time !
- * <p>
- * You should overwrite the following methods for your needs:
- * <pre>
- <a href="GLAnimJPanel.html#init()">init - 1st initialisation</a>
- <a href="GLAnimJPanel.html#display()">display - render one frame</a>
- <a href="GLCanvas.html#reshape(int, int)">reshape - to reshape (window resize)</a>
- <a href="GLAnimJPanel.html#ReInit()">ReInit - ReInitialisation after stop for setSuspended(false)</a>
- * </pre>
*
* @see gl4java.awt.GLCanvas
* @version 2.0, 21. April 1999
@@ -231,53 +242,6 @@ public class GLAnimJPanel extends GLJPanel
setAnimateFps(FramesPerSec);
}
- /**
- * init should be overwritten by you,
- * to enter your initialisation code
- *
- */
- public void init()
- {
- /* here we should add and initialize our JAVA components */
-
- /* ... and furthet OpenGL init's - like you want to */
-
- glj.gljCheckGL();
-
- ReInit();
-
- /* and start our working thread ... */
- start();
- }
-
- /**
- *
- * This is the rendering-method called by sDisplay
- * (and sDisplay is called by paint, or by the thread directly !).
- * The derived-class (Your Subclass) will redefine this,
- * to draw it's own animation !
- *
- * <p>
- *
- * You should set shallWeRender here,
- * to signalize the animation-loop 'run' to supsend
- * <p>
- * To restart the thread, just call setSuspended(false)
- *
- * @see gl4java.swing.GLAnimJPanel#shallWeRender
- * @see gl4java.swing.GLAnimJPanel#run
- * @see gl4java.swing.GLAnimJPanel#setSuspended
- * @see gl4java.awt.GLAnimCanvas#sDisplay
- * @see gl4java.awt.GLAnimCanvas#paint
- */
- public void display()
- {
- int i;
-
- // ... just render it
-
- }
-
/**
* ReInit should be overwritten by you,
* to enter your re-initialisation within setSuspended(false)
@@ -362,16 +326,6 @@ public class GLAnimJPanel extends GLJPanel
notify();
}
- /**
- * Should be set in display,
- * whether to render or not while the animation loop
- * <p>
- * If shallWeRender is false,
- * this thread will suspend !
- *
- * @see gl4java.swing.GLAnimJPanel#display
- * @see gl4java.swing.GLAnimJPanel#run
- */
protected boolean shallWeRender = true;
private long _fDelay = 0;
@@ -383,7 +337,7 @@ public class GLAnimJPanel extends GLJPanel
* The running loop for animations
* which initiates the call of display
*
- * @see gl4java.swing.GLAnimJPanel#shallWeRender
+ * @see gl4java.swing.GLAnimJPanel#setSuspended
* @see gl4java.swing.GLAnimJPanel#display
*/
public void run()
@@ -563,13 +517,13 @@ public class GLAnimJPanel extends GLJPanel
* fot the getFps* methods
* <p>
* this function is called automatically by
- * run, if the thread is suspended via shallWeRender
+ * run, if the thread is suspended via setSuspended
* <p>
* All data's are print out on System.out
* if verboseFps is set !
*
* @see gl4java.swing.GLAnimJPanel#run
- * @see gl4java.swing.GLAnimJPanel#shallWeRender
+ * @see gl4java.swing.GLAnimJPanel#setSuspended
* @see gl4java.swing.GLAnimJPanel#resetFpsCounter
* @see gl4java.swing.GLAnimJPanel#stopFpsCounter
* @see gl4java.swing.GLAnimJPanel#getFps
@@ -605,7 +559,7 @@ public class GLAnimJPanel extends GLJPanel
* verboseFps is set to true by default !
*
* @see gl4java.swing.GLAnimJPanel#run
- * @see gl4java.swing.GLAnimJPanel#shallWeRender
+ * @see gl4java.swing.GLAnimJPanel#setSuspended
* @see gl4java.swing.GLAnimJPanel#resetFpsCounter
* @see gl4java.swing.GLAnimJPanel#stopFpsCounter
* @see gl4java.swing.GLAnimJPanel#getFps
diff --git a/gl4java/swing/GLJPanel.java b/gl4java/swing/GLJPanel.java
index 1e23110..31ee17f 100644
--- a/gl4java/swing/GLJPanel.java
+++ b/gl4java/swing/GLJPanel.java
@@ -1,866 +1,932 @@
-package gl4java.swing;
-
-import gl4java.*;
-
-import java.awt.*;
-import java.awt.image.*;
-import java.awt.event.*;
-import javax.swing.*;
-
-/**
- * This is meant as an base class writing
- * easy render functions. A clean usage of multi-threading compatible
- * with JAVA2 is implemented in GLAnimJPanel !
- *
- * <p>
- *
- * If you are interessting in further Documentation and/or
- * the history of GL4Java follow the following link.
- *
- * <pre>
- <a href="../../GL4Java.html">The GL4Java Documentation</a>
- * </pre>
- * <p>
- *
- * You should overwrite the following methods for your needs:
- * <pre>
- <a href="GLJPanel.html#init()">preInit - initialisation before creating GLContext</a>
- <a href="GLJPanel.html#init()">init - 1st initialisation after creating GLContext</a>
- <a href="GLJPanel.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
- <a href="GLJPanel.html#display()">display - render your frame</a>
- <a href="GLJPanel.html#reshape(int, int)">reshape - to reshape (window resize), gljResize() is allready invoked !</a>
- * </pre>
- *
- * To check if you can use the GLContext and GL and GLU methods,
- * use the function
- * <pre>
- <a href="GLJPanel.html#cvsIsInit()">cvsIsInit</a>
- * </pre>
- * <p>
- * IF you remove/release a GLJPanel,
- * e.g. you want to close/dispose it�s Window (which contains this GLJPanel),
- * you HAVE TO call:
- *
- * <pre>
- <a href="GLJPanel.html#cvsDispose()">cvsDispose</a>
- * </pre>
- * You should call this before releasing/dispose this Window !
- * Also you can overwrite this class,
- * to dispose your own elements, e.g. a Frame etc. -
- * but be shure that you call
- * cvsDispose implementation call this one !
- *
- * <p>
- * We do override the following Canvas methods.
- *
- * <pre>
- <a href="GLJPanel.html#update(java.awt.Graphics)">update</a>
- <a href="GLJPanel.html#paint(java.awt.Graphics)">paint</a>
- * </pre>
- * <p>
- *
- * @see gl4java.swing.GLAnimJPanel
- * @see gl4java.awt.GLCanvas
- *
- * @version 2.0, 21. April 1999
- * @author Sven Goethel
- *
- */
-public class GLJPanel extends JPanel
- implements GLEnum, GLUEnum,
- ComponentListener, WindowListener, MouseListener
-{
- protected GLContext glj = null;
- public GLFunc gl = null;
- public GLUFunc glu = null;
-
- protected boolean mustResize = false;
-
- protected boolean cvsInitialized=false;
-
- protected boolean needCvsDispose = false;
-
- /**
- * Visual pre-set for stencil-bit number, default: 0
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#paint
- */
- protected int stencilBits = 0;
-
- /**
- * Visual pre-set for accumulator buffer size, default: 0
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#paint
- */
- protected int accumSize = 0;
-
- /**
- * Visual pre-set for stereoView, default: false
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#paint
- */
- protected boolean stereoView = false;
-
- /**
- * Visual pre-set for RGBA usage, default: true - of course ;-)
- * This value is updated after a GLContext is created with the
- * original updated value of GLContext !
- *
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#paint
- */
- protected boolean rgba = true;
-
- /**
- * The context with witch display lists and textures will be shared.
- *
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#paint
- */
- protected GLContext sharedGLContext;
-
- /**
- * The data to hold the offscreen pixels on the java side !
- *
- * @see gl4java.swing.GLJPanel#offImagePixels
- * @see gl4java.swing.GLJPanel#paint
- */
- protected BufferedImage offImage = null;
-
- /**
- * The data to hold the offscreen pixels on the GL side !
- *
- * @see gl4java.swing.GLJPanel#offImage
- * @see gl4java.swing.GLJPanel#paint
- */
- protected byte[] offImagePixels = null;
-
- /**
- * The custom set offscreen Size
- *
- * If this is set to != null,
- * the offscreen pixmap is used in this size,
- * not in the components-size (-> faster if smaller)
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#setOffScreenSize
- * @see gl4java.swing.GLJPanel#getOffScreenSize
- */
- protected Dimension offScrnSize = null;
- protected boolean customOffScrnSize=false;
- protected boolean offScrnSizeChanged=false;
-
- static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
- System.out.println("GLJPanel could not load def. native libs.");
- }
-
- /**
- *
- * Constructor
- *
- * @param gl_Name The name of the GLFunc implementation
- * If gl_Name==null, the default class will be used !
- *
- * @param glu_Name The name of the GLUFunc implementation
- * If gl_LibName==null, the default class will be used !
- *
- * @param layout the layout manager
- * @param isDoubleBuffered the flag indicates,
- * if double buffer should be used
- *
- */
- public GLJPanel( String gl_Name,
- String glu_Name,
- LayoutManager layout, boolean isDoubleBuffered
- )
- {
- super( layout, isDoubleBuffered );
-
- if( (gl=GLContext.createGLFunc(gl_Name)) ==null)
- {
- System.out.println("GLFunc implementation "+gl_Name+" not created");
- }
- if( (glu=GLContext.createGLUFunc(glu_Name)) ==null)
- {
- System.out.println("GLUFunc implementation "+glu_Name+" not created");
- }
-
- /* to be able for RESIZE event's */
- addComponentListener(this);
-
- setOpaque(false);
- }
-
- /**
- *
- * Constructor
- *
- * @param layout the layout manager
- * @param isDoubleBuffered the flag indicates,
- * if double buffer should be used
- *
- */
- public GLJPanel( LayoutManager layout, boolean isDoubleBuffered )
- {
- this(null, null, layout, isDoubleBuffered);
- }
-
- /**
- *
- * Constructor
- *
- * Uses the default GLFunc and GLUFunc implementation !
- *
- * @param isDoubleBuffered the flag indicates,
- * if double buffer should be used
- */
- public GLJPanel( boolean isDoubleBuffered )
- {
- this(null, null, new FlowLayout(), isDoubleBuffered);
- }
-
- /**
- *
- * Constructor
- *
- * Uses the default GLFunc and GLUFunc implementation !
- *
- * @param layout the layout manager
- */
- public GLJPanel(LayoutManager layout)
- {
- this(null, null, layout, true);
- }
-
- /**
- *
- * Constructor
- *
- * Uses the default GLFunc and GLUFunc implementation !
- *
- */
- public GLJPanel( )
- {
- this(null, null, new FlowLayout(), true);
- }
-
- /**
- * Used to return the created GLContext
- */
- public final GLContext getGLContext() { return glj; }
-
- /**
- * Safe the toplevel window
- */
- protected Window topLevelWindow = null;
-
- /**
- *
- * This function returns the found TopLevelWindow,
- * which contains this Canvas ..
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- */
- public final Window getTopLevelWindow()
- { return topLevelWindow; }
-
- /**
- * The customers offscreen Size
- *
- * If this is set,
- * the offscreen pixmap is used in this size,
- * not in the components-size (-> faster if smaller)
- *
- * @see gl4java.swing.GLJPanel#offScrnSize
- * @see gl4java.swing.GLJPanel#setOffScreenSize
- */
- public Dimension getOffScreenSize()
- { return offScrnSize; }
-
- /**
- * The customers offscreen Size
- *
- * If this is set,
- * the offscreen pixmap is used in this size,
- * not in the components-size (-> faster if smaller)
- *
- * @see gl4java.swing.GLJPanel#offScrnSize
- * @see gl4java.swing.GLJPanel#getOffScreenSize
- */
- public void setOffScreenSize(Dimension size)
- {
- if((size!=null && size.equals(offScrnSize)==false) ||
- size!=offScrnSize
- )
- {
- offScrnSizeChanged=true;
- offScrnSize=size;
- customOffScrnSize=offScrnSize!=null;
- }
- }
-
- /**
- * this function overrides the Canvas paint method !
- *
- * For the first paint,
- * the user function preInit is called, a GLContext is created
- * and the user function init is called !
- *
- * Also, if a GL Context exist, GLJPanel's sDisplay-method will be called
- * to do OpenGL-rendering.
- *
- * The sDisplay method itself calls the display-method !
- * sDisplay is needed to be thread-safe, to manage
- * the resize functionality and to safe the time per frame.
- *
- * To define your rendering, you should overwrite the display-method
- * in your derivation.
- *
- * @see gl4java.GLContext#GLContext
- * @see gl4java.swing.GLJPanel#cvsIsInit
- * @see gl4java.swing.GLJPanel#sDisplay
- * @see gl4java.swing.GLJPanel#display
- * @see gl4java.swing.GLJPanel#preInit
- * @see gl4java.swing.GLJPanel#init
- */
- public synchronized final void paintComponent(Graphics g)
- {
- if(glj == null ||
- (mustResize && !customOffScrnSize) || offScrnSizeChanged )
- {
- if(mustResize)
- {
- cvsDispose();
- mustResize=false;
- }
- preInit();
- glj = GLContext.createOffScreenCtx ( this, gl, glu,
- stereoView,
- rgba, stencilBits, accumSize,
- sharedGLContext,
- offScrnSize
- );
-
- if(glj!=null)
- {
- /*
- createOwnWindow = glj.isOwnWindowCreated();
- doubleBuffer = glj.isDoubleBuffer();
- */
- stencilBits = glj.getStencilBitNumber();
- accumSize = glj.getAccumSize();
- stereoView = glj.isStereoView();
- rgba = glj.isRGBA();
- }
- if(offImage!=null)
- offImage.flush();
- offImage=null;
- offScrnSizeChanged=false;
-
- init();
-
- // fetch the top-level window ,
- // to add us as the windowListener
- //
- Container _c = getParent();
- Container c = null;
-
- while(_c!=null)
- {
- c = _c;
- _c = _c.getParent();
- }
-
- if(c instanceof Window) {
- topLevelWindow = (Window)c;
- topLevelWindow.addComponentListener(this);
- topLevelWindow.addMouseListener(this);
- } else {
- topLevelWindow = null;
- System.out.println("toplevel is not a Window: "+c);
- }
-
- if(topLevelWindow!=null)
- {
- topLevelWindow.addWindowListener(this);
- } else {
- System.out.println("no parent found for "+getName());
- System.out.flush();
- }
- if(glj!=null && glj.gljIsInit())
- cvsInitialized=true;
- }
- /*
- if( mustResize ) size = getSize();
- g.setClip(0, 0, size.width, size.height );
- */
- //super.paintComponent(g);
-
- gr = g;
- sDisplay();
- }
-
- Graphics gr = null;
- DataBufferInt dbInt = null;
-
- /**
- *
- * This is the thread save rendering-method called by paint.
- * The actual thread will be set to highes priority befor calling
- * 'display'. After 'display' the priority will be reset !
- *
- * 'gljFree' will be NOT called after 'display'.
- *
- * We tested the above to use multi-threading and
- * for the demonstration 'glDemos' it works ;-)) !
- *
- * BE SURE, if you want to call 'display' by yourself
- * (e.g. in the run method for animation)
- * YOU HAVE TO CALL sDisplay -- OR YOU MUST KNOW WHAT YOU ARE DOING THEN !
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#display
- */
- public synchronized final void sDisplay()
- {
- boolean ok = true;
-
- long _s = System.currentTimeMillis();
-
- if(!cvsIsInit())
- return;
-
- if( glj.gljMakeCurrent() == false ) {
- System.out.println("GLJPanel: problem in use() method");
- return;
- }
-
- if(ok)
- {
- display();
- _f_dur_self = System.currentTimeMillis()-_s;
- if(GLContext.gljClassDebug)
- {
- _f_dur_self_sum+=_f_dur_self;
- glj.gljCheckGL();
- }
-
- int glFormat;
- int glComps;
- int awtFormat;
-
- glFormat = (rgba == true)?GL_RGBA:GL_RGB;
- glComps = (rgba == true)?4:3;
- awtFormat = (rgba == true)?BufferedImage.TYPE_INT_ARGB:
- BufferedImage.TYPE_INT_RGB;
-
- Dimension size = null;
- if(customOffScrnSize)
- size=offScrnSize;
- else
- size=getSize();
- int w=size.width;
- int h=size.height;
-
- long _s_tst = System.currentTimeMillis();
-
- if(offImage==null ||
- offImage.getHeight()!=h || offImage.getWidth()!=w)
- {
- if(offImage!=null)
- offImage.flush();
- offImage = new BufferedImage(w,h,awtFormat);
- offImagePixels=new byte[w*h*glComps];
- dbInt = (DataBufferInt)
- offImage.getRaster().getDataBuffer();
-
- if(GLContext.gljClassDebug)
- {
- System.out.print("set offImage to size: "+size+
- "(hw size: "+w+"x"+h+"), type: ");
- switch(glFormat) {
- case GL_RGB: System.out.println("RGB"); break;
- case GL_RGBA: System.out.println("RGBA"); break;
- case GL_BGR_EXT: System.out.println("BGR"); break;
- case GL_BGRA_EXT: System.out.println("BGRA"); break;
- }
- }
- }
-
- glj.gljReadPixelGL2AWT(0,0,w,h,glFormat,GL_UNSIGNED_BYTE,
- glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
- offImagePixels, dbInt.getData());
-
- //glj.gljSwap(); // no true swapping with offscreen buffers ..
-
- if(GLContext.gljClassDebug)
- _f_dur_tst_sum+=System.currentTimeMillis()-_s_tst;
-
- if(GLContext.gljClassDebug)
- glj.gljCheckGL();
- glj.gljFree(); // enable ctx for threads ...
-
- if(!customOffScrnSize)
- gr.drawImage(offImage, 0, 0, this);
- else {
- size=super.getSize();
- gr.drawImage(offImage, 0, 0, size.width, size.height, this);
- }
-
- _f_dur_total = System.currentTimeMillis()-_s;
- if(GLContext.gljClassDebug)
- {
- _f_dur_total_sum+=_f_dur_total;
- if(++_f_dur_times==100)
- {
- System.out.println("self p 100: "+
- (double)(_f_dur_self_sum/100)/1000.0+" s");
-
- System.out.println("tst p 100: "+
- (double)(_f_dur_tst_sum/100)/1000.0+" s");
-
- System.out.println("gl-bitblit p 100: "+
- (double)((_f_dur_total_sum-_f_dur_self_sum)/100)/1000.0+" s");
- System.out.println("total p 100: "+
- (double)(_f_dur_total_sum/100)/1000.0+" s");
-
- _f_dur_self_sum=0;
- _f_dur_tst_sum=0;
- _f_dur_total_sum=0;
- _f_dur_times=0;
- }
- }
-
- }
-
- }
-
- /**
- *
- * This is the rendering-method called by sDisplay
- * (and sDisplay is called by paint !).
- * The derived-class (Your Subclass) will redefine this, to draw it's own...
- *
- * BE SURE, if you want to call 'display' by yourself
- * (e.g. in the run method for animation)
- * YOU HAVE TO CALL sDisplay !
- *
- * 'sDisplay' manages a semaphore to avoid reentrance of
- * the display function !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#sDisplay
- * @see gl4java.swing.GLJPanel#paint
- */
- public void display()
- {
- }
-
- /**
- *
- * This is your pre-init method.
- * preInit is called just BEFORE the GL-Context is created.
- * You should override preInit, to initialize your visual-stuff,
- * like the protected vars: doubleBuffer and stereoView
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#stereoView
- * @see gl4java.swing.GLJPanel#rgba
- * @see gl4java.swing.GLJPanel#stencilBits
- * @see gl4java.swing.GLJPanel#accumSize
- */
- public void preInit()
- {
- }
-
- /**
- *
- * This is your init method.
- * init is called right after the GL-Context is initialized.
- * You should override init, to initialize your stuff needed
- * by OpenGL an Java !
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- */
- public void init()
- {
- }
-
- /**
- * This method is used to clean up any OpenGL stuff (delete textures
- * or whatever) prior to actually deleting the OpenGL context.
- * You should override this with your own version, if you need to do
- * any cleanup work at this phase.
- * This functions is called within cvsDispose
- *
- * @return void
- *
- * @see gl4java.swing.GLJPanel#cvsDispose
- */
- public void doCleanup()
- {
- }
-
- /**
- * This function returns, if everything is init: the GLContext,
- * the and the users init function
- * This value is set in the paint method!
- *
- * @return boolean
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#init
- */
- public boolean cvsIsInit()
- {
- return cvsInitialized;
- }
-
- protected long _f_dur_self = 0;
- protected long _f_dur_self_sum = 0;
- protected long _f_dur_tst_sum = 0;
- protected long _f_dur_total = 0;
- protected long _f_dur_total_sum = 0;
- protected int _f_dur_times = 0;
-
- /**
- *
- * This is the reshape-method called by paint.
- * The derived-class (Your Subclass) will redefine this,
- * to manage your individual reshape ...
- *
- * This �reshape� method will be invoked after the first paint command
- * after GLJPanel.componentResize is called AND only if �gljUse� was
- * succesfull (so a call of gljUse is redundant).
- * �reshape� is not an overloading of java.awt.Component.reshape,
- * �reshape� is more like �glut�-reshape.
- *
- * GLJPanel.reshape allready has a simple default implementation,
- * which calls �gljResize� and �glViewport� - so you may be can
- * left this one as it is (no need to overload).
- * The needed call to �gljResize� is done by hte invoker paint !
- *
- * @param width the new width
- * @param height the new height
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#sDisplay
- */
- public void reshape( int width, int height )
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLJPanel::reshape bounds("+getBounds()+")");
- gl.glViewport(0,0, width, height);
- }
-
- /**
- *
- * �componentResized� is the componentListeners event handler.
- *
- * This method sets the variable �mustResize� to true,
- * so the upcoming �paint� method-call will invoke �reshape� !
- *
- * This little look-alike complicating thing is done,
- * to avoid an Exception by using the glContext from more than
- * one concurrent thread�s !
- *
- * You cannot override this implementation, it is final
- * - override �reshape' instead !
- *
- * @param e the element, which is resized
- * @return void
- *
- * @see gl4java.swing.GLJPanel#paint
- * @see gl4java.swing.GLJPanel#reshape
- */
- public void componentResized(ComponentEvent e)
- {
- if(GLContext.gljClassDebug)
- System.out.println("GLJPanel::componentResized("+e.getComponent()+")");
- if(glj!=null && glj.gljIsInit() && e.getComponent()==this )
- {
- mustResize = true;
- //repaint();
- }
- }
-
- public void componentMoved(ComponentEvent e)
- {
- /*
- if(GLContext.gljClassDebug)
- System.out.print("GLJPanel::componentMoved("+e.getComponent()+")");
- if(e.getComponent().equals(topLevelWindow))
- {
- repaint();
- }
- */
- }
-
- public void componentShown(ComponentEvent e)
- {
- }
-
- public void componentHidden(ComponentEvent e)
- {
- }
-
- public void mouseClicked(MouseEvent e)
- {
- }
- public void mouseEntered(MouseEvent e)
- {
- /*
- if(GLContext.gljClassDebug)
- System.out.print("GLJPanel::mouseEntered("+e.getComponent()+")");
- if(e.getComponent().equals(topLevelWindow))
- {
- repaint();
- }
- */
- }
- public void mouseExited(MouseEvent e)
- {}
- public void mousePressed(MouseEvent e)
- {
- }
- public void mouseReleased(MouseEvent e)
- {
- }
-
- public void windowOpened(WindowEvent e)
- {
- }
-
- /**
- *
- * �windowClosing� is the windowListeners event handler
- * for the topLevelWindow of this Canvas !
- *
- * This methods free�s AND destroy�s
- * the GL Context with �glj.gljDestroy� !
- *
- * @return void
- *
- */
- public void windowClosing(WindowEvent e)
- {
- if(e.getComponent().equals(topLevelWindow))
- {
- cvsDispose();
- }
- }
-
- /**
- *
- * �windowClosed� is the windowListeners event handler.
- *
- * @return void
- *
- */
- public void windowClosed(WindowEvent e)
- {
- if (needCvsDispose) cvsDispose();
- }
-
- public void windowIconified(WindowEvent e)
- {
- }
-
- public void windowDeiconified(WindowEvent e)
- {
- }
-
- public void windowActivated(WindowEvent e)
- {
- }
-
- public void windowDeactivated(WindowEvent e)
- {
- }
-
- /**
- * You should call this before releasing/dispose this Window !
- * Also you can overwrite this class,
- * to dispose your own elements, e.g. a Frame etc. -
- * but be shure that you call
- * cvsDispose implementation call this one !
- *
- * This function calls gljDestroy of GLContext !
- *
- * @see gl4java.GLContext#gljDestroy
- * @see gl4java.swing.GLJPanel#doCleanup
- */
- public void cvsDispose()
- {
- cvsInitialized = false;
- if (glj != null)
- {
- if (glj.gljIsInit())
- {
- /* Sometimes the Microsoft VM calls the
- Applet.stop() method but doesn't have
- permissions to do J/Direct calls, so
- this whole block of code will throw a
- security exception. If this happens,
- however, windowClosing() will still
- call us again later and we will have
- another opportunity to shut down the
- context, so it all works out fine. */
- try
- {
- glj.gljFree();
- doCleanup();
- //locks and free's GLContext
- glj.setEnabled(false);
- glj.gljDestroy();
- needCvsDispose = false;
- }
- catch (Exception ex)
- {
- needCvsDispose = true;
- }
- }
- }
-
- // Setting glj to null will simply cause paint() to re-initialize.
- // We don't want that to happen, so we will leave glj non-null.
- }
-
- public Dimension getSize()
- {
- if(customOffScrnSize)
- return offScrnSize;
- return super.getSize();
- }
-
- /**
- * get methods
- */
- public final int cvsGetWidth() {
- return getSize().width;
- }
- public final int cvsGetHeight() {
- return getSize().height;
- }
-}
-
+package gl4java.swing;
+
+import gl4java.*;
+import gl4java.drawable.*;
+import gl4java.drawable.utils.*;
+
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+/**
+ * This is meant as an base class writing
+ * easy render functions. A clean usage of multi-threading compatible
+ * with JAVA2 is implemented in GLAnimJPanel !
+ *
+ * <p>
+ *
+ * If you are interessting in further Documentation and/or
+ * the history of GL4Java follow the following link.
+ *
+ * <pre>
+ <a href="../../GL4Java.html">The GL4Java Documentation</a>
+ * </pre>
+ * <p>
+ *
+ * There are two ways of using a GLJPanel: the {@link
+ * gl4java.GLEventListener} model or the subclassing model. Earlier
+ * versions of the system only supported the subclassing model. The
+ * default implementations of {@link #init}, {@link #display},
+ * {@link #reshape} and {@link #doCleanup}
+ * now send events to GLEventListeners; they can
+ * still be overridden as before to support the subclassing model.
+ *
+ * <p>
+ * If using the subclassing model, you should override the following
+ * methods for your needs:
+ * <pre>
+ <a href="GLJPanel.html#init()">preInit - initialisation before creating GLContext</a>
+ <a href="GLJPanel.html#init()">init - 1st initialisation after creating GLContext</a>
+ <a href="GLJPanel.html#doCleanup()">doCleanup - OGL cleanup prior to context deletion</a>
+ <a href="GLJPanel.html#display()">display - render your frame</a>
+ <a href="GLJPanel.html#reshape(int, int)">reshape - to reshape (window resize), gljResize() is allready invoked !</a>
+ * </pre>
+ *
+ * To check if you can use the GLContext and GL and GLU methods,
+ * use the function
+ * <pre>
+ <a href="GLJPanel.html#cvsIsInit()">cvsIsInit</a>
+ * </pre>
+ * <p>
+ * IF you remove/release a GLJPanel,
+ * e.g. you want to close/dispose it�s Window (which contains this GLJPanel),
+ * you HAVE TO call:
+ *
+ * <pre>
+ <a href="GLJPanel.html#cvsDispose()">cvsDispose</a>
+ * </pre>
+ * You should call this before releasing/dispose this Window !
+ * Also you can overwrite this class,
+ * to dispose your own elements, e.g. a Frame etc. -
+ * but be shure that you call
+ * cvsDispose implementation call this one !
+ *
+ * <p>
+ * We do override the following Canvas methods.
+ *
+ * <pre>
+ <a href="GLJPanel.html#update(java.awt.Graphics)">update</a>
+ <a href="GLJPanel.html#paint(java.awt.Graphics)">paint</a>
+ * </pre>
+ * <p>
+ *
+ * @see gl4java.swing.GLAnimJPanel
+ * @see gl4java.awt.GLCanvas
+ *
+ * @version 2.0, 21. April 1999
+ * @author Sven Goethel
+ * */
+public class GLJPanel extends JPanel
+ implements GLEnum, GLUEnum,
+ ComponentListener, WindowListener, MouseListener,
+ GLDrawable
+{
+ protected GLContext glj = null;
+ public GLFunc gl = null;
+ public GLUFunc glu = null;
+
+ protected boolean mustResize = false;
+
+ protected boolean cvsInitialized=false;
+
+ protected boolean needCvsDispose = false;
+
+ /**
+ * Visual pre-set for stencil-bit number, default: 0
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected int stencilBits = 0;
+
+ /**
+ * Visual pre-set for accumulator buffer size, default: 0
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected int accumSize = 0;
+
+ /**
+ * Visual pre-set for stereoView, default: false
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected boolean stereoView = false;
+
+ /**
+ * Visual pre-set for RGBA usage, default: true - of course ;-)
+ * This value is updated after a GLContext is created with the
+ * original updated value of GLContext !
+ *
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected boolean rgba = true;
+
+ /**
+ * The context with witch display lists and textures will be shared.
+ *
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected GLContext sharedGLContext;
+
+ /**
+ * The data to hold the offscreen pixels on the java side !
+ *
+ * @see gl4java.swing.GLJPanel#offImagePixels
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected BufferedImage offImage = null;
+
+ /**
+ * The data to hold the offscreen pixels on the GL side !
+ *
+ * @see gl4java.swing.GLJPanel#offImage
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ protected byte[] offImagePixels = null;
+
+ /**
+ * The custom set offscreen Size
+ *
+ * If this is set to != null,
+ * the offscreen pixmap is used in this size,
+ * not in the components-size (-> faster if smaller)
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#setOffScreenSize
+ * @see gl4java.swing.GLJPanel#getOffScreenSize
+ */
+ protected Dimension offScrnSize = null;
+ protected boolean customOffScrnSize=false;
+ protected boolean offScrnSizeChanged=false;
+
+ // The list of GLEventListeners
+ private GLEventListenerList listeners = new GLEventListenerList();
+
+ static {
+ if(GLContext.loadNativeLibraries(null, null, null)==false)
+ System.out.println("GLJPanel could not load def. native libs.");
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @param gl_Name The name of the GLFunc implementation
+ * If gl_Name==null, the default class will be used !
+ *
+ * @param glu_Name The name of the GLUFunc implementation
+ * If gl_LibName==null, the default class will be used !
+ *
+ * @param layout the layout manager
+ * @param isDoubleBuffered the flag indicates,
+ * if double buffer should be used
+ *
+ */
+ public GLJPanel( String gl_Name,
+ String glu_Name,
+ LayoutManager layout, boolean isDoubleBuffered
+ )
+ {
+ super( layout, isDoubleBuffered );
+
+ if( (gl=GLContext.createGLFunc(gl_Name)) ==null)
+ {
+ System.out.println("GLFunc implementation "+gl_Name+" not created");
+ }
+ if( (glu=GLContext.createGLUFunc(glu_Name)) ==null)
+ {
+ System.out.println("GLUFunc implementation "+glu_Name+" not created");
+ }
+
+ /* to be able for RESIZE event's */
+ addComponentListener(this);
+
+ setOpaque(false);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * @param layout the layout manager
+ * @param isDoubleBuffered the flag indicates,
+ * if double buffer should be used
+ *
+ */
+ public GLJPanel( LayoutManager layout, boolean isDoubleBuffered )
+ {
+ this(null, null, layout, isDoubleBuffered);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @param isDoubleBuffered the flag indicates,
+ * if double buffer should be used
+ */
+ public GLJPanel( boolean isDoubleBuffered )
+ {
+ this(null, null, new FlowLayout(), isDoubleBuffered);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ * @param layout the layout manager
+ */
+ public GLJPanel(LayoutManager layout)
+ {
+ this(null, null, layout, true);
+ }
+
+ /**
+ *
+ * Constructor
+ *
+ * Uses the default GLFunc and GLUFunc implementation !
+ *
+ */
+ public GLJPanel( )
+ {
+ this(null, null, new FlowLayout(), true);
+ }
+
+ /**
+ * Used to return the created GLContext
+ */
+ public final GLContext getGLContext() { return glj; }
+
+ /**
+ * Safe the toplevel window
+ */
+ protected Window topLevelWindow = null;
+
+ /**
+ *
+ * This function returns the found TopLevelWindow,
+ * which contains this Canvas ..
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ */
+ public final Window getTopLevelWindow()
+ { return topLevelWindow; }
+
+ /**
+ * The customers offscreen Size
+ *
+ * If this is set,
+ * the offscreen pixmap is used in this size,
+ * not in the components-size (-> faster if smaller)
+ *
+ * @see gl4java.swing.GLJPanel#offScrnSize
+ * @see gl4java.swing.GLJPanel#setOffScreenSize
+ */
+ public Dimension getOffScreenSize()
+ { return offScrnSize; }
+
+ /**
+ * The customers offscreen Size
+ *
+ * If this is set,
+ * the offscreen pixmap is used in this size,
+ * not in the components-size (-> faster if smaller)
+ *
+ * @see gl4java.swing.GLJPanel#offScrnSize
+ * @see gl4java.swing.GLJPanel#getOffScreenSize
+ */
+ public void setOffScreenSize(Dimension size)
+ {
+ if((size!=null && size.equals(offScrnSize)==false) ||
+ size!=offScrnSize
+ )
+ {
+ offScrnSizeChanged=true;
+ offScrnSize=size;
+ customOffScrnSize=offScrnSize!=null;
+ }
+ }
+
+ /**
+ * this function overrides the Canvas paint method !
+ *
+ * For the first paint,
+ * the user function preInit is called, a GLContext is created
+ * and the user function init is called !
+ *
+ * Also, if a GL Context exist, GLJPanel's sDisplay-method will be called
+ * to do OpenGL-rendering.
+ *
+ * The sDisplay method itself calls the display-method !
+ * sDisplay is needed to be thread-safe, to manage
+ * the resize functionality and to safe the time per frame.
+ *
+ * To define your rendering, you should overwrite the display-method
+ * in your derivation.
+ *
+ * @see gl4java.GLContext#GLContext
+ * @see gl4java.swing.GLJPanel#cvsIsInit
+ * @see gl4java.swing.GLJPanel#sDisplay
+ * @see gl4java.swing.GLJPanel#display
+ * @see gl4java.swing.GLJPanel#preInit
+ * @see gl4java.swing.GLJPanel#init
+ */
+ public synchronized final void paintComponent(Graphics g)
+ {
+ if(glj == null ||
+ (mustResize && !customOffScrnSize) || offScrnSizeChanged )
+ {
+ if(mustResize)
+ {
+ cvsDispose();
+ mustResize=false;
+ }
+ preInit();
+ glj = GLContext.createOffScreenCtx ( this, gl, glu,
+ stereoView,
+ rgba, stencilBits, accumSize,
+ sharedGLContext,
+ offScrnSize
+ );
+
+ if(glj!=null)
+ {
+ /*
+ createOwnWindow = glj.isOwnWindowCreated();
+ doubleBuffer = glj.isDoubleBuffer();
+ */
+ stencilBits = glj.getStencilBitNumber();
+ accumSize = glj.getAccumSize();
+ stereoView = glj.isStereoView();
+ rgba = glj.isRGBA();
+ }
+ if(offImage!=null)
+ offImage.flush();
+ offImage=null;
+ offScrnSizeChanged=false;
+
+ init();
+
+ // fetch the top-level window ,
+ // to add us as the windowListener
+ //
+ Container _c = getParent();
+ Container c = null;
+
+ while(_c!=null)
+ {
+ c = _c;
+ _c = _c.getParent();
+ }
+
+ if(c instanceof Window) {
+ topLevelWindow = (Window)c;
+ topLevelWindow.addComponentListener(this);
+ topLevelWindow.addMouseListener(this);
+ } else {
+ topLevelWindow = null;
+ System.out.println("toplevel is not a Window: "+c);
+ }
+
+ if(topLevelWindow!=null)
+ {
+ topLevelWindow.addWindowListener(this);
+ } else {
+ System.out.println("no parent found for "+getName());
+ System.out.flush();
+ }
+ if(glj!=null && glj.gljIsInit())
+ cvsInitialized=true;
+ }
+ /*
+ if( mustResize ) size = getSize();
+ g.setClip(0, 0, size.width, size.height );
+ */
+ //super.paintComponent(g);
+
+ gr = g;
+ sDisplay();
+ }
+
+ Graphics gr = null;
+ DataBufferInt dbInt = null;
+
+ /**
+ *
+ * This is the thread save rendering-method called by paint.
+ * The actual thread will be set to highes priority befor calling
+ * 'display'. After 'display' the priority will be reset !
+ *
+ * 'gljFree' will be NOT called after 'display'.
+ *
+ * We tested the above to use multi-threading and
+ * for the demonstration 'glDemos' it works ;-)) !
+ *
+ * BE SURE, if you want to call 'display' by yourself
+ * (e.g. in the run method for animation)
+ * YOU HAVE TO CALL sDisplay -- OR YOU MUST KNOW WHAT YOU ARE DOING THEN !
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#display
+ * @see gl4java.drawable.GLEventListener#preDisplay
+ * @see gl4java.drawable.GLEventListener#display
+ * @see gl4java.drawable.GLEventListener#postDisplay
+ */
+ public synchronized final void sDisplay()
+ {
+ boolean ok = true;
+
+ long _s = System.currentTimeMillis();
+
+ if(!cvsIsInit())
+ return;
+
+ listeners.sendPreDisplayEvent(this);
+
+ if( glj.gljMakeCurrent() == false ) {
+ System.out.println("GLJPanel: problem in use() method");
+ return;
+ }
+
+ if(ok)
+ {
+ display();
+ _f_dur_self = System.currentTimeMillis()-_s;
+ if(GLContext.gljClassDebug)
+ {
+ _f_dur_self_sum+=_f_dur_self;
+ glj.gljCheckGL();
+ }
+
+ int glFormat;
+ int glComps;
+ int awtFormat;
+
+ glFormat = (rgba == true)?GL_RGBA:GL_RGB;
+ glComps = (rgba == true)?4:3;
+ awtFormat = (rgba == true)?BufferedImage.TYPE_INT_ARGB:
+ BufferedImage.TYPE_INT_RGB;
+
+ Dimension size = null;
+ if(customOffScrnSize)
+ size=offScrnSize;
+ else
+ size=getSize();
+ int w=size.width;
+ int h=size.height;
+
+ long _s_tst = System.currentTimeMillis();
+
+ if(offImage==null ||
+ offImage.getHeight()!=h || offImage.getWidth()!=w)
+ {
+ if(offImage!=null)
+ offImage.flush();
+ offImage = new BufferedImage(w,h,awtFormat);
+ offImagePixels=new byte[w*h*glComps];
+ dbInt = (DataBufferInt)
+ offImage.getRaster().getDataBuffer();
+
+ if(GLContext.gljClassDebug)
+ {
+ System.out.print("set offImage to size: "+size+
+ "(hw size: "+w+"x"+h+"), type: ");
+ switch(glFormat) {
+ case GL_RGB: System.out.println("RGB"); break;
+ case GL_RGBA: System.out.println("RGBA"); break;
+ case GL_BGR_EXT: System.out.println("BGR"); break;
+ case GL_BGRA_EXT: System.out.println("BGRA"); break;
+ }
+ }
+ }
+
+ glj.gljReadPixelGL2AWT(0,0,w,h,glFormat,GL_UNSIGNED_BYTE,
+ glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
+ offImagePixels, dbInt.getData());
+
+ //glj.gljSwap(); // no true swapping with offscreen buffers ..
+
+ if(GLContext.gljClassDebug)
+ _f_dur_tst_sum+=System.currentTimeMillis()-_s_tst;
+
+ if(GLContext.gljClassDebug)
+ glj.gljCheckGL();
+ glj.gljFree(); // enable ctx for threads ...
+
+ if(!customOffScrnSize)
+ gr.drawImage(offImage, 0, 0, this);
+ else {
+ size=super.getSize();
+ gr.drawImage(offImage, 0, 0, size.width, size.height, this);
+ }
+
+ _f_dur_total = System.currentTimeMillis()-_s;
+ if(GLContext.gljClassDebug)
+ {
+ _f_dur_total_sum+=_f_dur_total;
+ if(++_f_dur_times==100)
+ {
+ System.out.println("self p 100: "+
+ (double)(_f_dur_self_sum/100)/1000.0+" s");
+
+ System.out.println("tst p 100: "+
+ (double)(_f_dur_tst_sum/100)/1000.0+" s");
+
+ System.out.println("gl-bitblit p 100: "+
+ (double)((_f_dur_total_sum-_f_dur_self_sum)/100)/1000.0+" s");
+ System.out.println("total p 100: "+
+ (double)(_f_dur_total_sum/100)/1000.0+" s");
+
+ _f_dur_self_sum=0;
+ _f_dur_tst_sum=0;
+ _f_dur_total_sum=0;
+ _f_dur_times=0;
+ }
+ }
+ }
+
+ listeners.sendPostDisplayEvent(this);
+
+ }
+
+ /**
+ *
+ * This is the rendering-method called by sDisplay
+ * (and sDisplay is called by paint !).
+ *
+ * <p>
+ * The default implementation of display() sends display events to
+ * all {@link gl4java.GLEventListener}s associated with this
+ * GLJPanel, and automatically calls {@link
+ * gl4java.GLContext#gljMakeCurrent} and {@link
+ * gl4java.GLContext#gljFree} as necessary.
+ *
+ * <p>}
+ * If you use the subclassing model (as opposed to the
+ * GLEventListener model), your subclass will redefine this to
+ * perform its OpenGL drawing.
+ *
+ * <p>
+ * BE SURE, if you want to call 'display' by yourself
+ * (e.g. in the run method for animation)
+ * YOU HAVE TO CALL sDisplay !
+ *
+ * 'sDisplay' manages a semaphore to avoid reentrance of
+ * the display function !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#sDisplay
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.drawable.GLEventListener#display
+ */
+ public void display()
+ {
+ listeners.sendDisplayEvent(this);
+ }
+
+ /**
+ *
+ * This is your pre-init method.
+ * preInit is called just BEFORE the GL-Context is created.
+ * You should override preInit, to initialize your visual-stuff,
+ * like the protected vars: doubleBuffer and stereoView
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#stereoView
+ * @see gl4java.swing.GLJPanel#rgba
+ * @see gl4java.swing.GLJPanel#stencilBits
+ * @see gl4java.swing.GLJPanel#accumSize
+ */
+ public void preInit()
+ {
+ }
+
+ /**
+ *
+ * init is called right after the GL-Context is initialized.
+ * The default implementation calls init() on all of this
+ * component's GLEventListeners.
+ *
+ * <p>
+ * If using the subclassing model, you can override this to
+ * perform one-time OpenGL initializations such as setting up
+ * lights and display lists.
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.drawable.GLEventListener#init
+ */
+ public void init()
+ {
+ listeners.sendInitEvent(this);
+ }
+
+ /**
+ * This method is used to clean up any OpenGL stuff (delete textures
+ * or whatever) prior to actually deleting the OpenGL context.
+ * You should override this with your own version, if you need to do
+ * any cleanup work at this phase.
+ * This functions is called within cvsDispose
+ *
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#cvsDispose
+ * @see gl4java.drawable.GLEventListener#cleanup
+ */
+ public void doCleanup()
+ {
+ listeners.sendCleanupEvent(this);
+ }
+
+ /**
+ * This function returns, if everything is init: the GLContext,
+ * the and the users init function
+ * This value is set in the paint method!
+ *
+ * @return boolean
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#init
+ */
+ public boolean cvsIsInit()
+ {
+ return cvsInitialized;
+ }
+
+ protected long _f_dur_self = 0;
+ protected long _f_dur_self_sum = 0;
+ protected long _f_dur_tst_sum = 0;
+ protected long _f_dur_total = 0;
+ protected long _f_dur_total_sum = 0;
+ protected int _f_dur_times = 0;
+
+ /**
+ *
+ * This �reshape� method will be invoked after the first paint command
+ * after GLCanvas.componentResize is called AND only if �gljMakeCurrent� was
+ * successful (so a call of gljMakeCurrent is redundant).
+ * �reshape� is not an overloading of java.awt.Component.reshape,
+ * �reshape� is more like �glut�-reshape.
+ *
+ * <p>
+ * GLCanvas.reshape already has a simple default implementation,
+ * which calls �gljResize� and �glViewport�. It also sends the
+ * reshape() event to all GLEventListeners. If using the
+ * GLEventListener model, it may not be necessary to do anything
+ * in your event listener's reshape() method; if using the
+ * subclassing model, it may not be necessary to override this.
+ *
+ * <p>
+ * The needed call to �gljResize� is done by the invoker paint !
+ *
+ * @param width the new width
+ * @param height the new height
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#sDisplay
+ * @see gl4java.drawable.GLEventListener#reshape
+ */
+ public void reshape( int width, int height )
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLJPanel::reshape bounds("+getBounds()+")");
+ gl.glViewport(0,0, width, height);
+ listeners.sendReshapeEvent(this, width, height);
+ }
+
+ /**
+ *
+ * �componentResized� is the componentListeners event handler.
+ *
+ * This method sets the variable �mustResize� to true,
+ * so the upcoming �paint� method-call will invoke �reshape� !
+ *
+ * This little look-alike complicating thing is done,
+ * to avoid an Exception by using the glContext from more than
+ * one concurrent thread�s !
+ *
+ * You cannot override this implementation, it is final
+ * - override �reshape' instead !
+ *
+ * @param e the element, which is resized
+ * @return void
+ *
+ * @see gl4java.swing.GLJPanel#paint
+ * @see gl4java.swing.GLJPanel#reshape
+ */
+ public void componentResized(ComponentEvent e)
+ {
+ if(GLContext.gljClassDebug)
+ System.out.println("GLJPanel::componentResized("+e.getComponent()+")");
+ if(glj!=null && glj.gljIsInit() && e.getComponent()==this )
+ {
+ mustResize = true;
+ //repaint();
+ }
+ }
+
+ public void componentMoved(ComponentEvent e)
+ {
+ /*
+ if(GLContext.gljClassDebug)
+ System.out.print("GLJPanel::componentMoved("+e.getComponent()+")");
+ if(e.getComponent().equals(topLevelWindow))
+ {
+ repaint();
+ }
+ */
+ }
+
+ public void componentShown(ComponentEvent e)
+ {
+ }
+
+ public void componentHidden(ComponentEvent e)
+ {
+ }
+
+ public void mouseClicked(MouseEvent e)
+ {
+ }
+ public void mouseEntered(MouseEvent e)
+ {
+ /*
+ if(GLContext.gljClassDebug)
+ System.out.print("GLJPanel::mouseEntered("+e.getComponent()+")");
+ if(e.getComponent().equals(topLevelWindow))
+ {
+ repaint();
+ }
+ */
+ }
+ public void mouseExited(MouseEvent e)
+ {}
+ public void mousePressed(MouseEvent e)
+ {
+ }
+ public void mouseReleased(MouseEvent e)
+ {
+ }
+
+ public void windowOpened(WindowEvent e)
+ {
+ }
+
+ /**
+ *
+ * �windowClosing� is the windowListeners event handler
+ * for the topLevelWindow of this Canvas !
+ *
+ * This methods free�s AND destroy�s
+ * the GL Context with �glj.gljDestroy� !
+ *
+ * @return void
+ *
+ */
+ public void windowClosing(WindowEvent e)
+ {
+ if(e.getComponent().equals(topLevelWindow))
+ {
+ cvsDispose();
+ }
+ }
+
+ /**
+ *
+ * �windowClosed� is the windowListeners event handler.
+ *
+ * @return void
+ *
+ */
+ public void windowClosed(WindowEvent e)
+ {
+ if (needCvsDispose) cvsDispose();
+ }
+
+ public void windowIconified(WindowEvent e)
+ {
+ }
+
+ public void windowDeiconified(WindowEvent e)
+ {
+ }
+
+ public void windowActivated(WindowEvent e)
+ {
+ }
+
+ public void windowDeactivated(WindowEvent e)
+ {
+ }
+
+ /**
+ * You should call this before releasing/dispose this Window !
+ * Also you can overwrite this class,
+ * to dispose your own elements, e.g. a Frame etc. -
+ * but be shure that you call
+ * cvsDispose implementation call this one !
+ *
+ * This function calls gljDestroy of GLContext !
+ *
+ * @see gl4java.GLContext#gljDestroy
+ * @see gl4java.swing.GLJPanel#doCleanup
+ */
+ public void cvsDispose()
+ {
+ cvsInitialized = false;
+ if (glj != null)
+ {
+ if (glj.gljIsInit())
+ {
+ /* Sometimes the Microsoft VM calls the
+ Applet.stop() method but doesn't have
+ permissions to do J/Direct calls, so
+ this whole block of code will throw a
+ security exception. If this happens,
+ however, windowClosing() will still
+ call us again later and we will have
+ another opportunity to shut down the
+ context, so it all works out fine. */
+ try
+ {
+ glj.gljFree();
+ doCleanup();
+ //locks and free's GLContext
+ glj.setEnabled(false);
+ glj.gljDestroy();
+ needCvsDispose = false;
+ }
+ catch (Exception ex)
+ {
+ needCvsDispose = true;
+ }
+ }
+ }
+
+ // Setting glj to null will simply cause paint() to re-initialize.
+ // We don't want that to happen, so we will leave glj non-null.
+ }
+
+ public Dimension getSize()
+ {
+ if(customOffScrnSize)
+ return offScrnSize;
+ return super.getSize();
+ }
+
+ /**
+ * get methods
+ */
+ public final int cvsGetWidth() {
+ return getSize().width;
+ }
+ public final int cvsGetHeight() {
+ return getSize().height;
+ }
+
+ //----------------------------------------------------------------------
+ // Implementation of GLDrawable
+ //
+
+ public void addGLEventListener(GLEventListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeGLEventListener(GLEventListener listener) {
+ listeners.remove(listener);
+ }
+
+ public GLFunc getGL() {
+ return gl;
+ }
+
+ public GLUFunc getGLU() {
+ return glu;
+ }
+}