OpenGLTMfor JavaTM Frequently Asked Questions (F.A.Q)

Table Of Contents (TOC)

GL4Java general questions :
What is GL4Java ?
Who makes GL4Java ?
How can I learn using GL4Java ?
Do I have to pay in order to use GL4Java ?
How can I help ?
Where can I download and install the beast ?
What kinda GL4Java applications and applets currently exist ?

JAVA related questions :
Which Java Virtuell Machine (JVM) should I use ?
But isn't Java slow ?
What platforms does GL4Java run on ?
How does GL4Java compare to Java3D ?

GL4Java installation questions :
How to use the Installer ?
GL4Java Installation Check-List (for Java2) !
Please Help - It won't run !

What should I read before you reply with RTFM ? Whom should I ask ?
How-To Complain About Non Working GL4Java ?

GL4Java technical questions :
Does GL4Java has a memory leak (Part 1) ?
Does GL4Java has a memory leak (Part 2) ?

My Canvas renders 1 frame, then stops, what's wrong ?
GLAnimCanvas vs GLJPanel, which should I choose ?
GLJPanel/GLAnimCanvas subclass model vs GLEventListener model, which should I choose ?

Extensions - Does GL4Java support extensions ? How do I load them ?
Tesselation - Does GL4Java support tesselation ? How do I use it ?
Offscreen - How Do I Use Offscreen Rendering with GL4Java ?
Fullscreen - How Do I Use Fullscreen with GL4Java ?
Bump Mapping - How Do I Use Bump Mapping with GL4Java ?

General questions :
Trademarks



What is GL4Java ?



GL4Java is an abbreviation of OpenGLTM for JavaTM,
read the trademarks section ;-)

GL4Java is an OpenGL binding for Java.
The GL4Java API maps native c++ OpenGL functions to the Java language and provides fast access to 3D accelerators from Java.

GL4Java maps the complete OpenGL 1.3 and GLU 1.2 API and implements window handle functions (native and java), while using the Java-Native-Interface (JNI) of Java or the JDirect-Interface of MS-JVM. Win32, X-Window, Mac.

GL4Java has been developed under Open Source Model since 1997 and has become over the years a serious and stable API.
Though, the library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY nor obligation of user support.

Have a look at the Overview !



Who makes GL4Java ?



GL4Java is mainly developed by Sven Gothel from Jausoft but many people have helped/contributed to the development of the project :

  • Aetius,
  • Jean-Yves BRUD,
  • Ron Cemer (www.3dstockcharts.com),
  • Leo Chan,
  • Alban Cousiniť,
  • DESYS (www.desys.com),
  • E3Futura & TeatreSoft,
  • Lee Elson (NASA),
  • Max Gilead,
  • Adam King,
  • Atilla Kolac,
  • Pontus Lidman (Mathcore),
  • Eloi Maduell,
  • Moises Ferrer Ramirez
  • Tommy Reilly,
  • Odell Reynolds (NASA),
  • Kenneth B. Russell (SUN Microsystems),
  • Ervin Vervaet,
  • Leung Yau Wai,
  • Gerard Ziemski,
  • ...

    The companies are only listed here, if the support and help is done by them officially.
    But if the individuals had to do the whole within ther spare time only,
    no company information is provided here !!


    Others we missed to list up here, please email the maintainers.

    Please check out the Thanxs Page also !



    How can I learn using GL4Java ?



    Have a look at the GL4Java Documents !

    If you are completely new to OpenGL, you can check out NeHe's OpenGL Tutorials. It is a good starting point to get a taste of OpenGL. Several NeHe's tutorials have been ported to GL4Java and can be found here (most of them are also included within the demo package)

    Then if you're seriously considering learning OpenGL, we advise you to buy the OpenGL Programming Guide, wich is also commonly refered as the "OpenGL RedBook".
    You can find several digital copies of it online, but we don't know if they are authorized by the authors. If you want to check them out, search fo "OpenGL Redbook" in a search engine.
    Notice the book has more than 600 pages, so it's REALLY worst buying it if you don't want to burn your eyes on the screen ! :)

    Then the next and mandatory step (before you ask a basic or stupid question to Sven which will reply by a RTFM !) is to read the docs and learn the demos provided with GL4Java wich can be found here,



    Do I have to pay in order to use GL4Java ?



    No. The GL4Java library is free software. You can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

    Of course, Sven Gothel spends a lot of time developping GL4Java and a generous donnation to Jausoft would help him continue supporting the development of GL4Java.



    How can I help ?



    Well, GL4Java is OpenSource'd LGPL licensed and lives from your support !
    So, anything you missing within GL4Java may be a good thing to add and maintain.
    Just ask the mailinglist Usergroup Mailinglist !



    Where can I download and install the beast ?



    Well, you can use the last release: GL4Java Homepage
    Press the download/installation button, which leads you to the specific page !
    There you will find all links for automatic and manual installation,
    and the directories from which you can download the sources, demo's, docs and binaries:
  • latest source, docs, demos
  • latest binaries

    Take your time, don't hurry ;-) !

    Here you can find instructions for the manual installation,
    and a checklist for the automatic installation via the installer !

    If you wan't to check out the very latest GL4Java on the edge development release,
    please go to GL4Java @ SOURCEFORGE !


    What kinda GL4Java applications and applets currently exist ?



  • Applications
  • Demos

    and just search the web for GL4Java ;-)


    Which Java Virtuell Machine (JVM) should I use ?



    Since GL4Java Version 2.8.2.0, we do support JVM 1.4's NIO Buffers,
    therefore, you should use the high performance JVM 1.4 !
    If this version is not avaiable for you,
    please use the latest, e.g. 1.3.1, 1.3.0, ...

    If you like to use Java Applet's within your WWW Browser,
    you better your the Java2-Plugin, e.g. a Java2 JRE (Java Runtime Environment) !
    This is the best way to achive a high performance Java VM for your Applets

    Remind that the browsers build-in JVM's are allmost old and maybe unsupported .. !



    But isn't Java slow ?



    No. Check out the demos !

    Java has been arround for more than 6 years now and the speed of execution of the language has been improved dramaticaly. The latest implementation of Java 2.0 (JDK 1.4) is running especially fast. Since programing with GL4Java relies mostly on hardware acceleration, the speed of execution of the Java language doesn't matter much unless you use huge and unoptimized algorithms.

    It is heard that using Java as an Applet in a browser build-in Java Virtual Machine (JVM) reduces the performance considerably though, because the display often goes thrue the browser's window API rather than directly to your Operating System display API. This is especially true with Netscape 6.0 wich cuts down the Java performance by a factor of 2 (using the java plugin !) compared to the AppletViewer.

    There are several papers about optimizing the speed of Java on the Internet :

    Tuning JavaTM I/O Performance on java.sun.com
    Thirteen Great Ways to Increase Java Performance on java.sun.com
    Dirty Java: Optimizing Pure Java on Gamasutra



    What platforms does GL4Java run on ?



    GL4Java runs on GNU/Linux, Win32, Mac OS 9.x, Mac OS X and any Unix/X11/OpenGL.

    We do support precompiled native binaries It should run on any Unix/X11/OpenGL machine, but we sometimes don't have precompiled binaries for those.
    E.g. we had it run also on Solaris, Irix and AIX. But since nobody does create binaries and maintains
    those machines, we cannot provide you with precompiled native libraries.



    How does GL4Java compare to Java3D ?



    GL4Java is an OpenGL binding and provides nothing else than access to OpenGL/GLU commands.
    GUI managment and toolkits like GLUT, texture managment, etc. are also provided.
    For the near future hopefully we can support a higher level scenegraph (SG) API like VRML or 3DS.

    Java3D is a multipurpose closed source scene graph API relying on DirectX and OpenGL.
    Java3D provides parsers for loading objects, functions to manipulate scene objects, such as texturing, morphing and so on... Because of Java3D's multipurpose nature, it contains many functionalities and thus contains an important amount of code, wich many parts of it remain unused because they aren't in the field of your purpose. This makes the API heavy and long to load. But then the display speed performs reasonnably. On the other hand Java 3D is much easier to use because it is a high level API. For example if you want to do a morph in Java3D, you create a morph node, load your geometry targets inside it, and set the morph amount between the targets.

    Using plain OpenGL for a 3D morphing, you have to go thru every vertex of your geometry and compute their x,y,z position yourself. Using plain OpenGL you have to code your own file parser and display your object, polygon per polygon, all this with your little hands ! This is an important work and it takes time. More, OpenGL is very specific and thus it's quite hard to learn, often requiring a good knowledge of math. But in the end you have coded only what you needed and your program is very small and fully optimized (this requires you use OpenGL intelligently, though).

    So if you need to have your project coded very quickly, if performance is not a top priority criteria and if you feel desesparate when doing math, use an avaiable well functional SCENEGRAPH environment, e.g. Java3D. If performance is critical (such as for games), if you have plenty of time, and you feel your shoulders are strong enough to face the big and malicious OpenGL monster, use plain OpenGL !

    CONCLUSION:
    If you don't want to do plain OpenGL use a SCENEGRAPH environment!
    If there is none yet avaiable for GL4Java,
    create some, make it avaiable under the terms of the LGPL !
    GL4Java is OpenSource and lives from your support and contributions.
    GL4Java provides you with it's source code and adding functionality is welcome.
    Look at the benefits !



    Does GL4Java support extensions ? How do I load them ?



    Yes, GL4Java supports numerous extensions. In order to list wich extensions are supported, just do a
    >java gl4java.GLContext -info
    OR press the gl4java button on a demo, e.g. gears.

    The extensions and the regular OpenGL 1.3 functions are dynamically loaded, so you don't have to worry about loading them. They are here, and you just have to use them !

    You can query, if the function exists, while calling e.g.:
    boolean t = GLContext.gljTextGLProc("VertexArrayRangeNV", true /* verbose */);
    that's it !
    Then you can savely call VertexArrayRangeNV(), this works for all supported OpenGL methods !
    If you call the GL4Java wrapper method for an unimplemented OpenGL function, nothing will happen - it is safe !

    Check out the NVidia Demo !



    Does GL4Java support tesselation ? How do I use it ?



    Since GL4Java 2.2.0, tesselation is supported !

    Please look in the sources and/or javadoc
    of:
    	gl4java.GLUTFunc
    

    There exist also many demos:

  • demos/MiscDemos/tess / (source)
  • demos/MiscDemos/tessdemo / (source)
  • demos/MiscDemos/tesswind / (source)

    DETAILS

    The native callback manager of GL4Java seeks the
    callback function with:

  • callback method-type (the "which" argument of the Callback function)
  • the current gl-context

    Because the callback manager functions do not know the
    tessellator/nurbs/quadratics id,
    only ONE callback-method for one gl-context and "which"-method
    is supported !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    
    Jean-Yves BRUD asked:
    
    > What is the meaning of parameter signature ?
    > If my callback method name is myVertexCallBack (for a GLU_TESS_VERTEX
    > callback),
    > what is the value of the signature parameter ?
    
    public void  gluTessCallback(     long tobj, int which,
    			          Object methodClassInstance, 
    			          String methodName, 
    				  String signature,
    				  int voidArrayLen1,
    				  int voidArrayLen2,
    				  int voidArrayLen3,
    				  int voidArrayLen4,
    				  int voidArrayLen5
    				  );
    
    
    Example (tessdemo.java line 337):
    	glu.gluTessCallback ( tobj, GLU_TESS_VERTEX, gl,
    			      "glVertex2fv", "([F)V",
    			      2, 0, 0, 0, 0);
    
    The signature "([F)V" is the original java style signature of the
    argument-list, your callback method takes (here: glVertex2fv) !
    
    	void glVertex2fv( const GLfloat v[2] ) 
    
    	(...) := within the brackets are function arguments signature part
    	[F    := float array
    	V     := void - 
                     the signature part after the brackets 
    		 means the return value
    
    Read SUN's Java Documentation for Java-Callback methods:
             http://java.sun.com/docs/books/tutorial/native1.1/implementing/method.html
    
    Here you can find the mapping of function arguments to its corresponding
    string signature representation !
    
    Jean-Yves BRUD asked:
    
    >
    > What is the meaning of the 5 parameters: voidArrayLen1, voidArrayLen2,
    > voidArrayLen3,
    > voidArrayLen4, voidArrayLen5, and what value do I need to put ?
    >
    
    public void  gluTessCallback(     long tobj, int which,
    			          Object methodClassInstance, 
    			          String methodName, 
    				  String signature,
    				  int voidArrayLen1,
    				  int voidArrayLen2,
    				  int voidArrayLen3,
    				  int voidArrayLen4,
    				  int voidArrayLen5
    				  );
    
    The maximum number of arrays within the argumentlist of 
    a GLU Callback function for Tesselation is 5 !
    
    So, the arguments voidArrayLen[1-5] refines the expected
    size of the arrays, 
    which are passed into and from the java callback funtion.
    
    	OpenGL-Machine <-> GL4Java-Callback-Handler <-> Java-Callback-Method
    
    E.g. (tessdemo.java):
             glu.gluTessCallback ( tobj, GLU_TESS_COMBINE, this,
                                    "combine_callback", "([D[D[F[F)V",
                                    2, 0, 0, 2, 0);
    
            public void combine_callback( double coords[/*3*/],
                                   double vertex_data[/*4xn(=0)*/],
                                   float weight[/*4*/], float[/*m(=2)*/] data )
            {
               data[0] = (float) coords[0];
               data[1] = (float) coords[1];
            }
    
    You can see, we do use the arrays "data" and "coords" with a size of 2 !
    You are not allowed to use nonsense sizes, because this can hurt your
    application with a segementation fault !
    (Well the GL4Java Callback functions checks
     the array sizes to OpenGL's maximum, .. but be kind of ..)
    
    The OpenGL machine calls GL4Java's callback function,
    which dispatches the call (incl. data) to your java callback function !
    
    



    How Do I Use Offscreen Rendering with GL4Java ?



    You can just use it, the way GLJPanel use it for swing integration !

    Since 2.8, I have added a gl4java.awt.GLOffScreenDrawable !

    Here is a little offscreen PNG gl-image renderer, using gl4java.awt.GLOffScreenDrawable:

  • demos/MiscDemos/gearsOffScreen2Tga.java (source)
  • demos/MiscDemos/gearsOffScreenDrawImage.html / (source)



    How Do I Use Fullscreen with GL4Java ?



    Well, for the pre JDK 1.4 aera, i only can recommend the stupid way
    of increasing the window size to screen size like in the
    demos/RonsDemos/FullScreenGears.java demo !

    For the JDK 1.4 machines, we just can use the standard JDK 1.4
    fullscreen mode like this:

  • demos/MiscDemos/gearsFullScreen.java (source)



    How Do I Use Bump Mapping with GL4Java ?



    I do not know ? ;-)

    Somebody should fill this .. please !



    How to use the Installer ?



    For any installation, you should be able to access the web via http,
    therefore you have to setup your firewall/proxy well ;-)

    The Automatic Web Installation, may determine your browser via javascript,
    but to be sure, you better use the force ;-)
    Just click, e.g. for a default Java2 Browser, the related force-link !

    Be sure to setup your Java2 policy file, for a Java2 installation.
    A default Java2 policy file addition is provided on the installation page.
    The Installer can also be downloaded and can be run as a standalone application !
    The Installer then fetches all needed archives from the web, if not allready downloaded,
    and installes them properly !



    GL4Java Installation Check-List (for Java2) !



    First of all, we do use the follwing names here:

    	JAVA_HOME
    

    JAVA_HOME refers to the directory where the runtime software is installed (which is the top-level directory of the JRE or the jre directory in the Java 2 SDK).
    Here are some examples of you JAVA_HOME locations:

    WIN32 JDK:	C:\jdk1.3.1\jre
    WIN32 JRE:	C:\Program Files\JavaSoft\JRE\1.3.1
    UNIX  JDK:	/usr/lib/jdk1.3.1/jre
    


    	DIRECTORY SEPERATOR /
    

    / is our directory seperator. so if you are unlucky and using win32 ;-), you have to use the backslash \, otherwise on any unix flavor, you are fine with the straight slash.


    For the Window's world, I have learned on my win98se machine,
    that you better use the JRE as your default Java2 JRE,
    for the Java2 plugin within your browsers.

    Don't ask me why, but i never ever got the gl4java applets to run
    if using the JDK directory in the Java2 Plugin setup.

    Well, the good thing is, using the JRE Path, is the default ;-)



    First check that you have all the .jar files in the correct locations :

    JAVA_HOME/lib/ext/gl4java.jar
    JAVA_HOME/lib/ext/gl4java-glutfonts.jar
    JAVA_HOME/lib/ext/gl4java-glffonts.jar
    JAVA_HOME/lib/ext/png.jar
    


    Then make sure you have installed the gl4java native dynamic libraries in the right directories :

    the following 5 native dynamic libraries are required:

    	WINDOWS:
    	========
    	JAVA_HOME/bin/GL4JavaGljMSJDirect.dll
    	JAVA_HOME/bin/GL4JavaJauGljJNI.dll
    	JAVA_HOME/bin/GL4JavaJauGljJNI12.dll
    	JAVA_HOME/bin/GL4JavaJauGljJNI13.dll
    	JAVA_HOME/bin/GL4JavaJauGljJNI14.dll
    
    	UNIX X86:
    	========
    	JAVA_HOME/lib/i386/GL4JavaGljMSJDirect.so
    	JAVA_HOME/lib/i386/GL4JavaJauGljJNI.so
    	JAVA_HOME/lib/i386/GL4JavaJauGljJNI12.so
    	JAVA_HOME/lib/i386/GL4JavaJauGljJNI13.so
    	JAVA_HOME/lib/i386/GL4JavaJauGljJNI14.so
    
    	UNIX PPC:
    	========
    	JAVA_HOME/lib/ppc/GL4JavaGljMSJDirect.so
    	JAVA_HOME/lib/ppc/GL4JavaJauGljJNI.so
    	JAVA_HOME/lib/ppc/GL4JavaJauGljJNI12.so
    	JAVA_HOME/lib/ppc/GL4JavaJauGljJNI13.so
    	JAVA_HOME/lib/ppc/GL4JavaJauGljJNI14.so
    

    Some JDK ore JRE's have different locations, e.g. IBM's JDK for Linux, they do use e.g.:
    	JAVA_HOME/bin
    
    for the dynamic libraries !

    You just can search for the libraries, which directory is our destination:
    libjava.so (unix)
    java.dll (win32)


    Then you may want to install the native libraries
    to you system's default library path also.
    Here are several possible default locations.

    	WINDOWS VARIANTS:
    	=================
    	C:/WIN98/SYSTEM 
    	C:/WIN95/SYSTEM 
    	C:/WINNT/SYSTEM32 
    
    	UNIX FLAVORS
    	============
    	/usr/lib
    

    Be sure, that if you do have installed GL4Java in any of the described directories,
    install the same version on all such locations.


    Because of Java2 PrivilegedAction's restriction,
    you should have installed the libraries under the above JAVA_HOME directory,
    to being able to use GL4Java for Java Applet's!

    Finally check out the java.policy files located in :

    	JAVA_HOME/lib/security/java.policy
    

    You should have (by default) :

    grant codeBase "file:${java.home}/lib/ext/*" {
    	permission java.security.AllPermission;
    };
    


    The following issue might be obsolete regarding the GL4Java 2.8 release !
    Some have problems using standalone GL4Java applications,
    because they wouldn't fint jawt.dll and wouldn't load gl4java dependent dlls.
    In this case you have 2 choices:
  • Make sure you have your PATH variable set correctly (don't forget to replace "\jdk1.x\" by your own jdk directory): PATH = your_path_variables;c:\jdk1.x\jre\bin;C:\jdk1.x\bin
  • just start the java application from c:\jdk1.x\jre\bin\java

    You should be up and running now ! That is what I call a seamless installation ! ;)



    Please Help - It won't run !



    Q: I just get a java.lang.RuntimePermission exception !

    Just be sure, you have installed GL4Java properly within the
    JAVA_HOME/lib/ext/gl4java.jar
    
    directory, see the setup notes
    Otherwise, you have to add the gl4java.jar archive to your java2 security policy file !

    Q: I just get the error: java.lang.UnsatisfiedLinkError: loadJAWT0

    Your gl4java.jar archive does not match the native libraries ..
    you have installed !
    loadJAWT0 is a new native lib funtion intro. in 2.8.2 ..

    Just remove all gl4java*.jar and all GL4Java*.dll (or GL4Java*.so* for Unices) files !
    Then re-install the latest version - thats it ;-)



    What should I read before you reply with RTFM ? Whom should I ask ?
    (RTFM = Unix abbreviation for `Read The Fucking Manual')



    Read the Overview !
    and there you will find the JavaDoc GL4Java API and other stuff.

    Download or browse the latest source, docs and demos via CVS GL4Java @ SOURCEFORGE
    and read the README files, the docs and the demos !

    You can also browser them from here: latest release,
    download them from here: latest source, docs, demos,
    but this source might be outdated, since this is not the development release !

    Just ask the mailinglist Usergroup Mailinglist!


    How-To Complain About Non Working GL4Java ?



    Please Read The Following Issues First:

  • What should I read before you reply with RTFM ? Whom should I ask ?
  • How to use the Installer ?
  • GL4Java Installation Check-List (for Java2) !
  • Please Help - It won't run !

  • Please retest with:
  • The latest Java Virtual Machine (JVM)
  • The latest GL4Java Version

  • If this won't help, please send the follwing information to the mailinglist:

  • Operating System
  • Java VM Vendor and Version (in detail)
  • GL4Java Version (in detail)
  • OpenGL (gfx-card and driver) Vendor and Version (in detail)

  • IF possible, the following output within a seperated compressed (e.g. zip, or gzip) textfile:
    	java gl4java.GLContext -infotxt
    

    If you feel, that the above GL4Java self-test info is correct,
    please add the output of the demo/MiscDemos/gears.java demo,
    within a compressed file also (zip or bzip2).

    Be polite ;-)

    Be patient ;-)



    Does GL4Java has a memory leak (Part 1) ?



    Because many complained about a possible memory leak within GL4Java,
    I have double checked GL4Java's native ressource managment
    (with it's verbose printouts ..), and everything seems ok !
    ;-)

    (MY) Win98se machine looks like the only platform with this bug.

    So, because Win98xx is a kinda dead thing ;-),
    and i really do not use it regulary (just to offer you thie win32 binaries),
    we may can forget this issue .. ?!?!

    Tip for Win98 users:
    DONT use Win98, WinME or WinXP ;-)
    Use WinNT, Win2k - or better: switch to a rock solid machine !

    Well it is not recommended to use a WinXP machine,
    since you do not have a special http, smb, or whatever
    content checking firewall, which is able to disallow M$
    to spy you personality and you machine itself !

    don't hesitate, go for it, use at least GNU/Linux ;-)

    ... but this might be offthread ..

    
    TEST RESULTS 1.) win98se, 2) winnt, 3.) linux-ppc, 4.) linux-x86
    ------------------------------------------------------------------
    
    ( All test ran with an NVidia gfx card and its proprietary driver,
      except the linux-ppc one (ATI (DRI driver)) !
    )
    
    win98se + jdk 1.3.1 + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
    summary: after each run 2MB of memory are "lost" !
    
    ---------------
    
    win98se + jdk 1.3.1_01 + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (MB)
            0               167.5 !!!!!!!!!
            1               173.3 !!!!!!!!!
            2               175.4 !!!!!!!!!
            3               177.3 !!!!!!!!!
            4               179.1 !!!!!!!!!
    
    ----------------
    
    winnt 4.0 + 500MByte + jdk 1.3.1 + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (kb)
            0               75404
            1               76028
            2               76028
            3               76028
            4               76028
    
    ----------------
    
    winnt 4.0 + 500MByte + jdk 1.3.1_01+ gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (kb)
            0               68980
            1               69788
            2               69784
            3               69784
            4               69776
    
    ----------------
    
    winnt 4.0 + 500MByte + jdk 1.4.0b3 + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (kb)
            0               70612
            1               71660
            2               71656
            3               71656
            4               71656
    
    test: "java gl4java.GLContext VertexArrayRange" (demos/NVidia)
            test loop       memory used (kb)
            0               70592
            1               70784
            2               70784
            3               70700
            4               70632
    
    ------------
    
    linux 2.4.12 ppc + 256 MB + jdk 1.3.0 (blackdown fcs) + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (MB)
            0               199
            1               199
            2               199
            3               198
            4               198
    
    ------------
    
    linux 2.4.11 x86 + 650 MB + jdk 1.3.1 (blackdown fcs) + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (MB)
            0               616
            1               608
            2               608
            3               607
            4               607
    
    ------------
    
    linux 2.4.11 x86 + 650 MB + jdk 1.4.0b3 (sun) + gl4java 2.8.1.0
    test: "java gl4java.GLContext -infotxt"
            test loop       memory used (MB)
            0               616
            1               604
            2               603
            3               604
            4               604
    
    test: "java gl4java.GLContext VertexArrayRange" (demos/NVidia)
            test loop       memory used (MB)
            0               612
            1               593
            2               592
            3               593
            4               593
    
    




    Does GL4Java has a memory leak (Part 2) ?



    I would like to report a bug in using GL4Java 2.8.2.0, it leaks memory 
    very fast (4k/sec) on PC. I noticed that because I run the exact same 
    java program on Mac OS X without any leaks. You can also try the Swing 
    demo called winOlympicCvs applet, everytime you click on the window you 
    will lose 4k on your Task Manager. Any ideas what may go wrong? Thanks!
    
    -Aaron
    

    I have tested this issue, but could not reproduce his results,
    the memory leak !

    So I guess, it is all about the buggy OS or/and the drivers ... !

    Here are my results:

    My System:
    
    WinNT 4.0,  4.00.1381
    Quadro2 MXR/EX NVidia OpenGL 4.00.1381.2311
    523 636 kByte Ram
    Java 1.3.1_01
    Memory meassured with the TASKMANAGER !
    
    Test1: "java gl4java.GLContext -infotxt"
    4 Runs
    1.) 165552
    2.) 165556
    3.) 165556
    4.) 165556
    
    Test2: "appletviewer glOlympicCvsApplet.html"
    2 Clicks After Animations Stops, and 3 just before
    1.)165564
    2.)195368
    3.)195376
    4.)195372
    5.)195372
    
    Well, looks like no memory leak at all .. hmm..
    



    GLAnimCanvas vs GLJPanel, which should I choose ?



    The GLJPanel implementation currently renders to an off-screen buffer and copies the pixels to the lightweight component. This leads to slowdowns over GLAnimCanvas because the rendering is not hardware-accelerated and because of the copying overhead.

    It is possible that the implementation could be changed to walk the lightweight component hierarchy to find the bounds of the GLJPanel within its parent heavyweight component and clip the OpenGL rendering region to fit (if the GLJPanel itself isn't overlapped by another lightweight component), which should speed it up significantly, though this kind of code is tricky to write.

    But you can use heavyweight components within a swing layout also : these are hardware accelerated but they keep their heavyweight restrictions (no overlapping...)
    have a look at GL4Java/demos/testTextPPM1.java, where swing/awt is mixed ..


    GLJPanel/GLAnimCanvas subclass model vs GLEventListener model, which should I choose ?



    The subclass model is the old mechanism which was used with GL4Java untill now.
    It consists in designing a class inherited from GLAnimCanvas or GLJPanel and overload its init() and display() methods to put your custom code.

    It's recommended to use the new GLEventListener model, even if you're a beginner.

    The listener model allows you to switch easyly between different GLEventListener's init()/display()/etc.. methods without having to destroy your canvas and create a new one.

    With the new model, you have to implement an GLEventListener, which is your selfmade application specific renderer.
    Then you just can attach your GLEventListener ( gearRenderer (source) ) to any GLDrawable, e.g.:

  • gearRenderer attached at an offscreen GLDrawable (source)
  • gearRenderer attached at an direct GLDrawable (source)

    The GLEventListener is the newly implemented listener mechanism which avoids subclassing.
    It offers higher performance, especially for GLAnimCanvas, because in certain circumstances OpenGL context
    switches can be avoided. (The details of this are hidden from the programmer.)

    To use this new mechanism as shown in the gears demo (source):
      - Create a gl4java.GLCapabilities object indicating the use of
        RGBA mode, etc.
      - Pass this capabilities object to gl4java.drawable.GLDrawableFactory.getFactory().
      - Call addGLEventListener on the resulting GLDrawable to set up your listener, which should implement at least init() and display().
    


    For highest performance animations:
      - Call GLDrawableFactory.createGLAnimCanvas()
      - Call setUseRepaint(false), setUseFpsSleep(false), and setUseYield(false) on the resulting GLAnimCanvas
    


    In one of the NVidia demos ported to Java, adding the optimized context handling increased the speed of the demo by 20%. Performance gain is not obvious in every case though, it depends on where the bottleneck is in your application.

    Another simple exemple of using the listener model can be found in the demos :
  • demos/MiscDemos/TriangleRotate.java (source)

    OpenGLTMfor JavaTM / Trademarks
    • Linux is a trademark of Linus Torvald
    • OpenGL is a registered trademark of SGI.
    • Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems,Inc. in the United States and other countries.
    • Solaris is trademark of Sun Microsystems,Inc.
    • Windows and Windows NT are registered trademarks of Microsoft Corporation.
    • IRIX is a registerd trademark of SGI in the United States and other countries.
    • Mac is a registered trademark of Apple Computer, Inc.
    • Netscape is a trademark of Netscape Communications Corp.
    • The names of products and corporations are trademarks or registered trademarks of respective corporation.
    GL4Java was the former project name of OpenGLTM for JavaTM

    GL4Java has no relationship with the Java trademark registered by Sun Microsystems, Inc.


    This FAQ is maintained by Alban Cousiniť and Sven Goethel.
    Last Updated on 4th February 2002