diff options
-rw-r--r-- | CHANGES.txt | 9 | ||||
-rw-r--r-- | CNativeCode/OpenGL_misc.c | 306 | ||||
-rw-r--r-- | demos/HodglimsNeHe/index.html | 2 | ||||
-rw-r--r-- | demos/HodglimsNeHe/index_plugin13.html | 2 | ||||
-rw-r--r-- | demos/SwingDemos/CrossColorJPanel.java | 14 | ||||
-rw-r--r-- | demos/SwingDemos/GearsJPanel.java | 2 | ||||
-rw-r--r-- | demos/SwingDemos/InternalGLFrameDemo1.java | 5 | ||||
-rw-r--r-- | demos/SwingDemos/TessJPanel.java | 6 | ||||
-rw-r--r-- | gl4java/GLContext.java.skel | 39 | ||||
-rw-r--r-- | gl4java/awt/GLCanvas.java | 7 | ||||
-rw-r--r-- | gl4java/swing/GLJPanel.java | 197 | ||||
-rw-r--r-- | makefile | 2 |
12 files changed, 354 insertions, 237 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index f2cb9a7..030929d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,15 @@ TOP = NEW DOWN = OLD ----------------- +10th April 2001 (Version 2.7.2 - Release 0 ) + o Added setup the glClearColor within GLCanvas/GLJPanel + to the Components background color. + This is done _after_ Context creation and _before_ init ! + + o Added the missing reshape call within GLJPanel (Swing) + + o Simplified and speed up the GL2AWT functions (Swing). + 10th April 2001 (Version 2.7.1 - Release 0 ) o Added a check for NULL Pointer. If the native GL/GLU function pointer are zero (may not exist), diff --git a/CNativeCode/OpenGL_misc.c b/CNativeCode/OpenGL_misc.c index 8d08843..fabd968 100644 --- a/CNativeCode/OpenGL_misc.c +++ b/CNativeCode/OpenGL_misc.c @@ -7,10 +7,10 @@ #include <dlfcn.h> #include "glxtool.h" #endif -
-#ifdef _WIN32_
- #include "wgltool.h"
-#endif
+ +#ifdef _WIN32_ + #include "wgltool.h" +#endif #include <string.h> @@ -511,8 +511,11 @@ Java_gl4java_GLContext_gljGetNativeLibVendorNative(JNIEnv *env, jobject obj ) * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! */ JNIEXPORT void JNICALL -Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B ( +Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIIIIII_3B ( JNIEnv *env, jobject obj, + jint pack_rowlen, + jint pack_x, + jint pack_y, jint xpos, jint ypos, jint width, @@ -560,9 +563,9 @@ Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B ( generated bitmaps too. */ disp__glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE); disp__glPixelStorei(GL_PACK_LSB_FIRST, GL_TRUE); - disp__glPixelStorei(GL_PACK_ROW_LENGTH, width); - disp__glPixelStorei(GL_PACK_SKIP_ROWS, 0); - disp__glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + disp__glPixelStorei(GL_PACK_ROW_LENGTH, pack_rowlen); + disp__glPixelStorei(GL_PACK_SKIP_ROWS, pack_y); + disp__glPixelStorei(GL_PACK_SKIP_PIXELS, pack_x); disp__glPixelStorei(GL_PACK_ALIGNMENT, 1); disp__glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); disp__glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); @@ -599,11 +602,15 @@ Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B ( } /** + * Experimental Code, not done yet ! * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! */ JNIEXPORT void JNICALL -Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B_3I ( +Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIIIIII_3S ( JNIEnv *env, jobject obj, + jint pack_rowlen, + jint pack_x, + jint pack_y, jint xpos, jint ypos, jint width, @@ -611,38 +618,24 @@ Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B_3I ( jint format, jint type, jint bufferName, - jbyteArray pixelGL, - jintArray pixelDest) + jshortArray pixelGLDest) { GLint swapbytes, lsbfirst, rowlength; GLint skiprows, skippixels, alignment; GLint unswapbytes, unlsbfirst, unrowlength; GLint unskiprows, unskippixels, unalignment; - jsize lenPixelSource = 0; - jbyte *pixelGLData = NULL; - jsize lenPixelDest = 0; - jint *pixelDestData = NULL; - int alpha=0; - int red=0; - int green=0; - int blue=0; - int offset=0; - int y_desc; - int x; - - jboolean isCopiedArray0 = JNI_FALSE; - jboolean isCopiedArray1 = JNI_FALSE; - - if(pixelGL==NULL || pixelDest==NULL) + jshort *pixelGLDestData = NULL; + jsize lenPixelGLDest = 0; + + jboolean isCopiedArray = JNI_FALSE; + + if(pixelGLDest==NULL) return; - lenPixelSource = (*env)->GetArrayLength(env, pixelGL); - pixelGLData = (*env)->GetByteArrayElements(env, pixelGL, - &isCopiedArray0); - lenPixelDest = (*env)->GetArrayLength(env, pixelDest); - pixelDestData = (*env)->GetIntArrayElements(env, pixelDest, - &isCopiedArray1); + lenPixelGLDest = (*env)->GetArrayLength(env, pixelGLDest); + pixelGLDestData = (*env)->GetShortArrayElements(env, pixelGLDest, + &isCopiedArray); /* Save current modes. */ disp__glGetIntegerv(GL_PACK_SWAP_BYTES, &swapbytes); @@ -665,20 +658,21 @@ Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B_3I ( generated bitmaps too. */ disp__glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE); disp__glPixelStorei(GL_PACK_LSB_FIRST, GL_TRUE); - disp__glPixelStorei(GL_PACK_ROW_LENGTH, width); - disp__glPixelStorei(GL_PACK_SKIP_ROWS, 0); - disp__glPixelStorei(GL_PACK_SKIP_PIXELS, 0); - disp__glPixelStorei(GL_PACK_ALIGNMENT, 1); + disp__glPixelStorei(GL_PACK_ROW_LENGTH, pack_rowlen); + disp__glPixelStorei(GL_PACK_SKIP_ROWS, pack_y); + disp__glPixelStorei(GL_PACK_SKIP_PIXELS, pack_x); + disp__glPixelStorei(GL_PACK_ALIGNMENT, 2); disp__glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); disp__glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); - disp__glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + disp__glPixelStorei(GL_UNPACK_ROW_LENGTH, width); disp__glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); disp__glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - disp__glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + disp__glPixelStorei(GL_UNPACK_ALIGNMENT, 2); /* Actually read the pixels. */ disp__glReadBuffer(bufferName); - disp__glReadPixels(xpos, ypos, width, height, format, type, pixelGLData); + disp__glReadPixels(xpos, ypos, width, height, format, type, + pixelGLDestData); /* Restore saved modes. */ disp__glPixelStorei(GL_PACK_SWAP_BYTES, swapbytes); @@ -694,152 +688,134 @@ Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIII_3B_3I ( disp__glPixelStorei(GL_UNPACK_SKIP_PIXELS, unskippixels); disp__glPixelStorei(GL_UNPACK_ALIGNMENT, unalignment); - for(y_desc=height-1; y_desc>=0; y_desc--) - { - for(x=0;x<width;x++) - { - red = ( (int)(pixelGLData[offset++]) & 0xff ) << 16; - green = ( (int)(pixelGLData[offset++]) & 0xff ) << 8; - blue = (int)(pixelGLData[offset++]) & 0xff; - - if(format==GL_RGBA) - alpha = ( (int)(pixelGLData[offset++]) & 0xff ) << 24; - else - alpha = ( (int) 0xff ) << 24; - - pixelDestData[y_desc*width + x] = alpha | red | green | blue; - } - } - - (*env)->ReleaseByteArrayElements(env, pixelGL, pixelGLData, - (isCopiedArray0==JNI_TRUE)?0:JNI_ABORT); - - (*env)->ReleaseIntArrayElements(env, pixelDest, pixelDestData, - (isCopiedArray1==JNI_TRUE)?0:JNI_ABORT); -} + disp__glFlush(); + disp__glFinish(); -/** - * Experimental Code, not done yet ! - * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! - */ -JNIEXPORT void JNICALL -Java_gl4java_GLContext_gljCpyOffScrnImg2Buffer__III_3B - (JNIEnv *env, jobject obj, jint width, jint height, jint format, jbyteArray pixelDest) -{ + (*env)->ReleaseShortArrayElements(env, + pixelGLDest, pixelGLDestData, + (isCopiedArray==JNI_TRUE)?0:JNI_ABORT); } /** - * Experimental Code, not done yet ! * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! */ -JNIEXPORT void JNICALL -Java_gl4java_GLContext_gljCpyOffScrnImg2Buffer__III_3I - (JNIEnv *env, jobject obj, jint width, jint height, jint format, jintArray pixelDest) +JNIEXPORT void JNICALL +Java_gl4java_GLContext_gljReadPixelGL2AWT__IIIIIIIIII_3I ( + JNIEnv *env, jobject obj, + jint pack_rowlen, + jint pack_x, + jint pack_y, + jint xpos, + jint ypos, + jint width, + jint height, + jint format, + jint type, + jint bufferName, + jintArray pixelDest) { -#ifdef _X11_ - - jclass cls = 0; - jfieldID fpixmapHandle=0; + GLint swapbytes, lsbfirst, rowlength; + GLint skiprows, skippixels, alignment; + GLint unswapbytes, unlsbfirst, unrowlength; + GLint unskiprows, unskippixels, unalignment; jsize lenPixelDest = 0; jint *pixelDestData = NULL; + jboolean isCopiedArray = JNI_FALSE; - jboolean ret = JNI_TRUE; - int sizemax=0; - int sizepix=0; + if(pixelDest==NULL) + return; + + lenPixelDest = (*env)->GetArrayLength(env, pixelDest); + pixelDestData = (*env)->GetIntArrayElements(env, pixelDest, + &isCopiedArray); + + /* Save current modes. */ + disp__glGetIntegerv(GL_PACK_SWAP_BYTES, &swapbytes); + disp__glGetIntegerv(GL_PACK_LSB_FIRST, &lsbfirst); + disp__glGetIntegerv(GL_PACK_ROW_LENGTH, &rowlength); + disp__glGetIntegerv(GL_PACK_SKIP_ROWS, &skiprows); + disp__glGetIntegerv(GL_PACK_SKIP_PIXELS, &skippixels); + disp__glGetIntegerv(GL_PACK_ALIGNMENT, &alignment); + disp__glGetIntegerv(GL_UNPACK_SWAP_BYTES, &unswapbytes); + disp__glGetIntegerv(GL_UNPACK_LSB_FIRST, &unlsbfirst); + disp__glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unrowlength); + disp__glGetIntegerv(GL_UNPACK_SKIP_ROWS, &unskiprows); + disp__glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &unskippixels); + disp__glGetIntegerv(GL_UNPACK_ALIGNMENT, &unalignment); + + /* Little endian machines (DEC Alpha, Inten X86, PPC(in LSB mode)... + for example) could benefit from setting + GL_PACK_LSB_FIRST to GL_TRUE + instead of GL_FALSE, but this would require changing the + generated bitmaps too. */ + disp__glPixelStorei(GL_PACK_SWAP_BYTES, GL_FALSE); + disp__glPixelStorei(GL_PACK_LSB_FIRST, GL_TRUE); + disp__glPixelStorei(GL_PACK_ROW_LENGTH, pack_rowlen); + disp__glPixelStorei(GL_PACK_SKIP_ROWS, pack_y); + disp__glPixelStorei(GL_PACK_SKIP_PIXELS, pack_x); + disp__glPixelStorei(GL_PACK_ALIGNMENT, 4); + disp__glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + disp__glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE); + disp__glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + disp__glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + disp__glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + disp__glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - jfieldID fdisplayHandle=0; - Display *disp=0; - Pixmap pix=0; - XImage *image; + /* Actually read the pixels. */ + disp__glReadBuffer(bufferName); + disp__glReadPixels(xpos, ypos, width, height, + format, type, pixelDestData); - cls = (*env)->GetObjectClass(env, obj); + /* Restore saved modes. */ + disp__glPixelStorei(GL_PACK_SWAP_BYTES, swapbytes); + disp__glPixelStorei(GL_PACK_LSB_FIRST, lsbfirst); + disp__glPixelStorei(GL_PACK_ROW_LENGTH, rowlength); + disp__glPixelStorei(GL_PACK_SKIP_ROWS, skiprows); + disp__glPixelStorei(GL_PACK_SKIP_PIXELS, skippixels); + disp__glPixelStorei(GL_PACK_ALIGNMENT, alignment); + disp__glPixelStorei(GL_UNPACK_SWAP_BYTES, unswapbytes); + disp__glPixelStorei(GL_UNPACK_LSB_FIRST, unlsbfirst); + disp__glPixelStorei(GL_UNPACK_ROW_LENGTH, unrowlength); + disp__glPixelStorei(GL_UNPACK_SKIP_ROWS, unskiprows); + disp__glPixelStorei(GL_UNPACK_SKIP_PIXELS, unskippixels); + disp__glPixelStorei(GL_UNPACK_ALIGNMENT, unalignment); - fdisplayHandle = (*env)->GetFieldID(env, cls, "displayHandle", "I"); - if (fdisplayHandle == 0) ret= JNI_FALSE; - else disp=(Display *)(*env)->GetIntField(env, obj, fdisplayHandle); + (*env)->ReleaseIntArrayElements(env, pixelDest, pixelDestData, + (isCopiedArray==JNI_TRUE)?0:JNI_ABORT); +} - fpixmapHandle = (*env)->GetFieldID(env, cls, "pixmapHandle", "I"); - if (fpixmapHandle == 0) ret= JNI_FALSE; - else pix = (Pixmap)(*env)->GetIntField(env, obj, fpixmapHandle); - if(pix==0 || pixelDest==NULL) - return; +JNIEXPORT jboolean JNICALL +Java_gl4java_GLContext_gljFetchOSGLFunctions ( + JNIEnv *env, jclass jclass, + jstring gllibname, jstring glulibname, jboolean force ) +{ + const char * gllib; + const char * glulib; - lenPixelDest = (*env)->GetArrayLength(env, pixelDest); - pixelDestData = (*env)->GetIntArrayElements(env, pixelDest, - &isCopiedArray); + gllib = (*env)->GetStringUTFChars(env, gllibname, 0); + glulib = (*env)->GetStringUTFChars(env, glulibname, 0); + + strncpy (libGLName, gllib, 798); + strncpy (libGLUName, glulib, 798); + libGLName[799] = 0; + libGLUName[799] = 0; + + (*env)->ReleaseStringUTFChars(env, gllibname, gllib); + (*env)->ReleaseStringUTFChars(env, glulibname, glulib); + +#ifdef _X11_ + fetch_GLX_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0); +#endif - if(format==GL_RGBA) { - image = XGetImage(disp, pix, 0, 0, width, height, - 0xffffffff, ZPixmap); - printf("format RGBA!!\n"); - } else if(format==GL_RGB) { - image = XGetImage(disp, pix, 0, 0, width, height, - 0x00ffffff, ZPixmap); - printf("format RGB!!\n"); - } else { - image = XGetImage(disp, pix, 0, 0, width, height, - 0xffffffff, ZPixmap); - printf("format not supported - guessing RGBA!!\n"); - } - - if(image!=NULL) - { - printf("width %d height %d\n", (int)width, (int)height); - printf("depth %d, bytes_per_line %d, width %d, height %d\n", - image->depth, image->bytes_per_line, image->width, image->height); - sizemax=(int)(lenPixelDest*sizeof(jint)); - sizepix=image->bytes_per_line*image->height; - - printf("sizeof dest-array: %d bytes\n", sizemax); - printf("sizeof image bpl*height: %d bytes\n", sizepix); - - if(sizepix<sizemax) sizemax=sizepix; - - (*env)->SetIntArrayRegion(env, pixelDest, 0, sizemax/sizeof(jint), - (jint*)image->data); - printf("copied ..\n"); - } else { - printf("invalid image ...\n"); - } - - if(pixelDestData!=NULL) - (*env)->ReleaseIntArrayElements(env, pixelDest, pixelDestData, - JNI_ABORT); +#ifdef _WIN32_ + fetch_WGL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0); #endif + + return JNI_TRUE; } -
-JNIEXPORT jboolean JNICALL
-Java_gl4java_GLContext_gljFetchOSGLFunctions (
- JNIEnv *env, jclass jclass,
- jstring gllibname, jstring glulibname, jboolean force )
-{
- const char * gllib;
- const char * glulib;
-
- gllib = (*env)->GetStringUTFChars(env, gllibname, 0);
- glulib = (*env)->GetStringUTFChars(env, glulibname, 0);
-
- strncpy (libGLName, gllib, 798);
- strncpy (libGLUName, glulib, 798);
- libGLName[799] = 0;
- libGLUName[799] = 0;
-
- (*env)->ReleaseStringUTFChars(env, gllibname, gllib);
- (*env)->ReleaseStringUTFChars(env, glulibname, glulib);
-
-#ifdef _X11_
- fetch_GLX_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0);
-#endif
-
-#ifdef _WIN32_
- fetch_WGL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0);
-#endif
-
- return JNI_TRUE;
-}
JNIEXPORT jboolean JNICALL Java_gl4java_GLContext_gljFetchGLFunctions ( diff --git a/demos/HodglimsNeHe/index.html b/demos/HodglimsNeHe/index.html index f954c58..89c5cf7 100644 --- a/demos/HodglimsNeHe/index.html +++ b/demos/HodglimsNeHe/index.html @@ -28,10 +28,12 @@ especially for the events: <I>mouseEntered</I> and <I>mouseClicked</I> !<br> <p> <a href="Lesson7.html">Lesson 7</a> : Lesson 7 - Texture Filters, Lighting & Keyboard Control <p> <a href="Lesson8.html">Lesson 8</a> : Lesson 8 - Blending <p> <a href="Lesson9.html">Lesson 9</a> : Lesson 9 - Moving Bitmaps In 3D Space + <p> <a href="Lesson10.html">Lesson 10</a> : Lesson 10 - Loading And Moving Through A 3D World <p> <a href="Lesson11.html">Lesson 11</a> : Lesson 11 - OpenGL Flag Effect <p> <a href="Lesson12.html">Lesson 12</a> : Lesson 12 - Display Lists <p> <a href="Lesson16.html">Lesson 16</a> : Lesson 16 - Cool Looking Fog <p> <a href="Lesson18.html">Lesson 18</a> : Lesson 18 - Quadratics +<p> <a href="Lesson19.html">Lesson 19</a> : Lesson 19 - Particle Engine Using Triangle Strips <br> <br> </body> diff --git a/demos/HodglimsNeHe/index_plugin13.html b/demos/HodglimsNeHe/index_plugin13.html index f9e8546..e3d74ab 100644 --- a/demos/HodglimsNeHe/index_plugin13.html +++ b/demos/HodglimsNeHe/index_plugin13.html @@ -31,10 +31,12 @@ especially for the events: <I>mouseEntered</I> and <I>mouseClicked</I> !<br> <p> <a href="Lesson7_plugin13.html">Lesson 7</a> : Lesson 7 - Texture Filters, Lighting & Keyboard Control <p> <a href="Lesson8_plugin13.html">Lesson 8</a> : Lesson 8 - Blending <p> <a href="Lesson9_plugin13.html">Lesson 9</a> : Lesson 9 - Moving Bitmaps In 3D Space + <p> <a href="Lesson10_plugin13.html">Lesson 10</a> : Lesson 10 - Loading And Moving Through A 3D World <p> <a href="Lesson11_plugin13.html">Lesson 11</a> : Lesson 11 - OpenGL Flag Effect <p> <a href="Lesson12_plugin13.html">Lesson 12</a> : Lesson 12 - Display Lists <p> <a href="Lesson16_plugin13.html">Lesson 16</a> : Lesson 16 - Cool Looking Fog <p> <a href="Lesson18_plugin13.html">Lesson 18</a> : Lesson 18 - Quadratics +<p> <a href="Lesson19_plugin13.html">Lesson 19</a> : Lesson 19 - Particle Engine Using Triangle Strips <br> <br> </body> diff --git a/demos/SwingDemos/CrossColorJPanel.java b/demos/SwingDemos/CrossColorJPanel.java index 97ed71f..2c4bdaa 100644 --- a/demos/SwingDemos/CrossColorJPanel.java +++ b/demos/SwingDemos/CrossColorJPanel.java @@ -7,12 +7,11 @@ public class CrossColorJPanel extends GLJPanel { public CrossColorJPanel( ) { - super(); + super(false); } public void init() { - reshape(getSize().width, getSize().height); } public void display() @@ -20,6 +19,7 @@ public class CrossColorJPanel extends GLJPanel int i; gl.glPushMatrix(); + gl.glClear(GL_COLOR_BUFFER_BIT); gl.glBegin(GLEnum.GL_LINES); @@ -43,8 +43,18 @@ public class CrossColorJPanel extends GLJPanel gl.glPopMatrix(); } + public void resize ( int x, int y, int width, int height ) + { + System.out.println("reshape: "+x+"/"+y+": "+width+"x"+height); + gl.glViewport(x, y, width, height); + gl.glMatrixMode(GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0, 10, 0, 10, -50.0,50.0); + gl.glMatrixMode(GL_MODELVIEW); + } public void reshape( int width, int height ) { + System.out.println("reshape: "+width+"x"+height); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); diff --git a/demos/SwingDemos/GearsJPanel.java b/demos/SwingDemos/GearsJPanel.java index 3d03111..f5428c6 100644 --- a/demos/SwingDemos/GearsJPanel.java +++ b/demos/SwingDemos/GearsJPanel.java @@ -37,6 +37,7 @@ public class GearsJPanel extends GLAnimJPanel setAnimateFps(30.0);
mtxfuncs = new MatrixFuncs();
+ setUseRepaint(true);
}
public void init()
@@ -93,6 +94,7 @@ public class GearsJPanel extends GLAnimJPanel public void reshape(int width, int height)
{
+ System.out.println("reshape: "+width+"x"+height);
float h = (float)height / (float)width;
gl.glViewport(0,0,width,height);
diff --git a/demos/SwingDemos/InternalGLFrameDemo1.java b/demos/SwingDemos/InternalGLFrameDemo1.java index ea5cada..627aaff 100644 --- a/demos/SwingDemos/InternalGLFrameDemo1.java +++ b/demos/SwingDemos/InternalGLFrameDemo1.java @@ -19,7 +19,7 @@ public class InternalGLFrameDemo1 extends JFrame { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(inset, inset, screenSize.width/2 - inset*2, - screenSize.height/2*3-inset*2); + screenSize.height/2-inset*2); //Quit this app when the big window closes. addWindowListener(new WindowAdapter() { @@ -28,7 +28,6 @@ public class InternalGLFrameDemo1 extends JFrame { } }); - //Set up the GUI. desktop = new JDesktopPane(); //a specialized layered pane createFrame(); //Create first window setContentPane(desktop); @@ -149,8 +148,10 @@ public class InternalGLFrameDemo1 extends JFrame { canvas.cvsDispose(); } canvas = (GLJPanel)obj; + canvas.setBackground(desktop.getBackground()); canvas.setVisible(true); master.add("Center", canvas); + canvas.setVisible(true); master.invalidate(); master.validate(); master.repaint(); diff --git a/demos/SwingDemos/TessJPanel.java b/demos/SwingDemos/TessJPanel.java index 60005ab..cbdb182 100644 --- a/demos/SwingDemos/TessJPanel.java +++ b/demos/SwingDemos/TessJPanel.java @@ -239,6 +239,10 @@ public class TessJPanel extends GLJPanel gl.glMatrixMode( GL_PROJECTION ); gl.glLoadIdentity(); - glu.gluOrtho2D(0.0f, (double) w, 0.0f, (double) h); + // + // draw this upside down, because of + // the reversed swing orientation + // + glu.gluOrtho2D(0.0f, (double) w, (double) h, 0.0f); } } diff --git a/gl4java/GLContext.java.skel b/gl4java/GLContext.java.skel index b719cfd..0996c23 100644 --- a/gl4java/GLContext.java.skel +++ b/gl4java/GLContext.java.skel @@ -2554,41 +2554,40 @@ public class GLContext extends Object * This functions reads the pixel from the GL frame * and puts it into the pixelDest array, * while converting them correctly to the AWT pixel format, - * using GL_RGB[A] and BufferedImage.TYPE_INT[A]RGB ! + * using GL_BGRA and BufferedImage.TYPE_INT_ARGB ! */ public final static native void gljReadPixelGL2AWT ( + int pack_rowlen, + int pack_x, int pack_y, int x, int y, int width, int height, int format, int type, int bufferName, - byte[] pixelGL, int[] pixelDest); + int[] pixelDest); /** - * Experimental Code, not done yet ! - * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! - * * This functions reads the pixel from the GL frame * and puts it into the pixelDest array, - * while using hardware correct AWT and GL pixel format, - * using GL_BGR[A]_EXT and BufferedImage.TYPE_[34]BYTE_[A]BGR ! - * - * ATTENTION: This functions runs only if hardware supports this, - * e.g. on Win32 platforms !!! + * while converting them correctly to the AWT pixel format, + * using GL_RGB and BufferedImage.TYPE_USHORT_565_RGB ! */ public final static native void gljReadPixelGL2AWT ( + int pack_rowlen, + int pack_x, int pack_y, int x, int y, int width, int height, int format, int type, int bufferName, - byte[] pixelGLDest); - - /** - * Experimental Code, not done yet ! - * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! - */ - public final native void gljCpyOffScrnImg2Buffer(int width, int height, int format, byte[] pixelDest); + short[] pixelDest); /** - * Experimental Code, not done yet ! - * This one is to upspeed the Offscreen rendering engine for e.g. Swing ! + * This functions reads the pixel from the GL frame + * and puts it into the pixelDest array, + * while using hardware correct AWT and GL pixel format, + * using GL_BGR and BufferedImage.TYPE_3BYTE_BGR ! */ - public final native void gljCpyOffScrnImg2Buffer(int width, int height, int format, int[] pixelDest); + public final static native void gljReadPixelGL2AWT ( + int pack_rowlen, + int pack_x, int pack_y, + int x, int y, int width, int height, + int format, int type, int bufferName, + byte[] pixelGLDest); /** * native C function to achieve the native lib vendor ! diff --git a/gl4java/awt/GLCanvas.java b/gl4java/awt/GLCanvas.java index f997bdd..73c9bba 100644 --- a/gl4java/awt/GLCanvas.java +++ b/gl4java/awt/GLCanvas.java @@ -174,7 +174,7 @@ public class GLCanvas extends Canvas private GLEventListenerList listeners = new GLEventListenerList();
static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
+ if(GLContext.doLoadNativeLibraries(null, null, null)==false)
System.out.println("GLCanvas could not load def. native libs.");
}
@@ -443,6 +443,11 @@ public class GLCanvas extends Canvas rgba = glj.isRGBA();
}
+ Color col = getBackground();
+ gl.glClearColor((float)col.getRed()/255.0f,
+ (float)col.getGreen()/255.0f,
+ (float)col.getBlue()/255.0f, 0.0f);
+
init();
// fetch the top-level window ,
diff --git a/gl4java/swing/GLJPanel.java b/gl4java/swing/GLJPanel.java index 31ee17f..bc385c6 100644 --- a/gl4java/swing/GLJPanel.java +++ b/gl4java/swing/GLJPanel.java @@ -5,6 +5,7 @@ import gl4java.drawable.*; import gl4java.drawable.utils.*;
import java.awt.*;
+import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
@@ -143,18 +144,15 @@ public class GLJPanel extends JPanel /**
* 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;
+ protected int glFormat=0;
+ protected int glType=0;
+ protected int glComps=0;
+ protected int awtFormat=0;
+
/**
* The custom set offscreen Size
@@ -175,7 +173,7 @@ public class GLJPanel extends JPanel private GLEventListenerList listeners = new GLEventListenerList();
static {
- if(GLContext.loadNativeLibraries(null, null, null)==false)
+ if(GLContext.doLoadNativeLibraries(null, null, null)==false)
System.out.println("GLJPanel could not load def. native libs.");
}
@@ -213,7 +211,7 @@ public class GLJPanel extends JPanel /* to be able for RESIZE event's */
addComponentListener(this);
- setOpaque(false);
+ setOpaque(true);
}
/**
@@ -349,6 +347,7 @@ public class GLJPanel extends JPanel * @see gl4java.swing.GLJPanel#display
* @see gl4java.swing.GLJPanel#preInit
* @see gl4java.swing.GLJPanel#init
+ public synchronized final void paint(Graphics g)
*/
public synchronized final void paintComponent(Graphics g)
{
@@ -358,7 +357,6 @@ public class GLJPanel extends JPanel if(mustResize)
{
cvsDispose();
- mustResize=false;
}
preInit();
glj = GLContext.createOffScreenCtx ( this, gl, glu,
@@ -384,7 +382,13 @@ public class GLJPanel extends JPanel offImage=null;
offScrnSizeChanged=false;
+ Color col = getBackground();
+ gl.glClearColor((float)col.getRed()/255.0f,
+ (float)col.getGreen()/255.0f,
+ (float)col.getBlue()/255.0f, 0.0f);
init();
+ Dimension size = size=getSize();
+ reshape(size.width, size.height);
// fetch the top-level window ,
// to add us as the windowListener
@@ -417,18 +421,14 @@ public class GLJPanel extends JPanel 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;
+ DataBufferUShort dbUShort = null;
+ DataBufferByte dbByte = null;
/**
*
@@ -469,6 +469,23 @@ public class GLJPanel extends JPanel return;
}
+ if(mustResize)
+ {
+ mustResize=false;
+ Dimension size = null;
+
+ if(customOffScrnSize)
+ size=offScrnSize;
+ else
+ size=getSize();
+
+ reshape(size.width, size.height);
+ /*
+ invalidate();
+ repaint(100);
+ */
+ }
+
if(ok)
{
display();
@@ -479,16 +496,8 @@ public class GLJPanel extends JPanel 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
@@ -501,29 +510,102 @@ public class GLJPanel extends JPanel if(offImage==null ||
offImage.getHeight()!=h || offImage.getWidth()!=w)
{
+ GLCapabilities caps = glj.getGLCapabilities();
+
+ if(caps.getAlphaBits()>0)
+ awtFormat = BufferedImage.TYPE_4BYTE_ABGR;
+ else
+ awtFormat = BufferedImage.TYPE_3BYTE_BGR;
+
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)
+ dbByte=null;
+ dbUShort=null;
+ dbInt=null;
+
+ switch (awtFormat)
{
- 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;
- }
+ case BufferedImage.TYPE_3BYTE_BGR:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=3BYTE_BGR, gl=BGR,UNSIGNED_BYTE");
+ glFormat = GL_BGR;
+ glType = GL_UNSIGNED_BYTE;
+ glComps = 3;
+ dbByte = (DataBufferByte)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_4BYTE_ABGR:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=4BYTE_ABGR, gl=BGRA,UNSIGNED_INT_8_8_8_8");
+ glFormat = GL_BGRA;
+ glType = GL_UNSIGNED_INT_8_8_8_8;
+ glComps = 4;
+ dbByte = (DataBufferByte)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_INT_RGB:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=INT_RGB, gl=BGRA,UNSIGNED_INT_8_8_8_8_REV");
+ glFormat = GL_BGRA;
+ glType = GL_UNSIGNED_INT_8_8_8_8_REV;
+ glComps = 4;
+ dbInt = (DataBufferInt)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_INT_ARGB:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=INT_ARGB, gl=BGRA,INT_8_8_8_8_REV");
+ glFormat = GL_BGRA;
+ glType = GL_UNSIGNED_INT_8_8_8_8_REV;
+ glComps = 4;
+ dbInt = (DataBufferInt)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_INT_BGR:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=INT_BGR, gl=BGRA,UNSIGNED_INT_8_8_8_8");
+ glFormat = GL_BGRA;
+ glType = GL_UNSIGNED_INT_8_8_8_8;
+ glComps = 4;
+ dbInt = (DataBufferInt)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_USHORT_555_RGB:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=USHORT_555_RGB, gl=RGBA,UNSIGNED_INT_5_5_5_1");
+ glFormat = GL_RGBA;
+ glType = GL_UNSIGNED_SHORT_5_5_5_1;
+ glComps = 2;
+ dbUShort = (DataBufferUShort)
+ offImage.getRaster().getDataBuffer();
+ break;
+ case BufferedImage.TYPE_USHORT_565_RGB:
+ if(GLContext.gljClassDebug)
+ System.out.println("awt=USHORT_565_RGB, gl=RGB,UNSIGNED_INT_5_6_5");
+ glFormat = GL_RGB;
+ glType = GL_UNSIGNED_SHORT_5_6_5;
+ glComps = 2;
+ dbUShort = (DataBufferUShort)
+ offImage.getRaster().getDataBuffer();
+ break;
}
- }
-
- glj.gljReadPixelGL2AWT(0,0,w,h,glFormat,GL_UNSIGNED_BYTE,
- glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
- offImagePixels, dbInt.getData());
+ }
+
+ if(dbByte!=null)
+ glj.gljReadPixelGL2AWT(w, 0,0, 0, 0, w, h, glFormat, glType,
+ glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
+ dbByte.getData());
+ else if(dbUShort!=null)
+ glj.gljReadPixelGL2AWT(w, 0,0, 0, 0, w, h, glFormat, glType,
+ glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
+ dbUShort.getData());
+ else if(dbInt!=null)
+ glj.gljReadPixelGL2AWT(w, 0,0, 0, 0, w, h, glFormat,glType,
+ glj.isDoubleBuffer()?GL_BACK:GL_FRONT,
+ dbInt.getData());
//glj.gljSwap(); // no true swapping with offscreen buffers ..
@@ -565,9 +647,7 @@ public class GLJPanel extends JPanel }
}
}
-
listeners.sendPostDisplayEvent(this);
-
}
/**
@@ -929,4 +1009,31 @@ public class GLJPanel extends JPanel public GLUFunc getGLU() {
return glu;
}
+
+ public Point getAbsoluteCoord(JRootPane rp)
+ {
+ Container obj = this;
+ Container next = obj.getParent();
+ Point _absCoord = this.getLocation();
+ Point p = null;
+
+ //System.out.println("\nADDING START :"+obj);
+
+ while ( next instanceof JComponent )
+ {
+ obj = next;
+ next = obj.getParent();
+
+ if ( next instanceof JComponent )
+ {
+ //System.out.println("\nADDING :"+obj);
+ p = obj.getLocation();
+ _absCoord.x+=p.x;
+ _absCoord.y+=p.y;
+ }
+ if(obj==rp) break;
+ }
+ return _absCoord;
+ }
+
}
@@ -98,7 +98,7 @@ CNATIVEDIR = CNativeCode LIBMAJOR = 2 LIBMINOR = 7 -LIBBUGFIX = 1 +LIBBUGFIX = 2 RELEASE = 0 # |