Using Pnuts to script Jogl (java OpenGL)

View: New views
4 Messages — Rating Filter:   Alert me  

Using Pnuts to script Jogl (java OpenGL)

by Sébastien Pierre-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

I was playing with Pnuts and wanted to script Jogl with it, following  
this tutorial <http://www.cs.umd.edu/~meesh/kmconroy/JOGLTutorial/>.

The first lines of the tutorial are like that (in Java)

     import net.java.games.jogl.*
     GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas
(new GLCapabilities());

So, I decided to do this in Pnuts, which gets me an exception:

     > canvas = javax.media.opengl.GLDrawableFactory.getFactory
().createGLCanvas(new javax.media.opengl.GLCapabilities())
     pnuts.lang.PnutsException : javax is not defined

Next, I decided to do this instead, which still doesn't work:

     > import javax.media.opengl.GLDrawableFactory
     null
     > import javax.media.opengl.GLCapabilities
     null
     > canvas = GLDrawableFactory.getFactory().createGLCanvas(new  
GLCapabilities())
     javax.media.opengl.GLDrawableFactory class.getFactory()
     java.lang.NoClassDefFoundError : null

However, doing this shows me that GLDrawableFactory is known:

     > new GLDrawableFactory()
     class javax.media.opengl.GLDrawableFactory()
     pnuts.lang.PnutsException : no constructors match: class  
javax.media.opengl.GLDrawableFactory args: []

So how should I proceed to get these lines working ?
TIA,

  -- Sébastien





Re: Using Pnuts to script Jogl (java OpenGL)

by NateS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried this out. Using this Pnuts code...

import net.java.games.jogl.*
canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities())

I got this exception...

Exception in thread "main" java.lang.NoClassDefFoundError: Could not
initialize class net.java.games.jogl.impl.windows.WindowsOnscreenGLContext
    at
net.java.games.jogl.impl.windows.WindowsGLContextFactory.createGLContext(WindowsGLContextFactory.java:52)
    at net.java.games.jogl.GLCanvas.<init>(GLCanvas.java:68)
    at
net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:117)
    at
net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at pnuts.lang.Runtime._callMethod(Runtime.java:333)

This is the NoClassDefFoundError that you should have been getting. Not
sure why you were getting "java.lang.NoClassDefFoundError : null".

Since I see jogl-win32 came with some DLLs, I assumed
WindowsOnscreenGLContext has a static initializer that tries to load a
native library. When the native library is not found, the exception is
swallowed because it happened in a static initializer and the
NoClassDefFoundError is thrown instead. Thanks Java!

To fix this, the DLLs need to be in your Windows path. You have some
options...

1) You can put them in a directory like "c:\windows\system32".
2) You can add the directory containing the DLLs to your path. Be sure
to restart your IDE if you change your path.
3) You can add this JVM option, where "C:\jogl-win32" is the directory
containing the DLLs...
-Djava.library.path="C:\jogl-win32"

Option #3 is best IMO, since the first two are harder to setup for other
people who might download your code and try to run it. For distribution,
you can use a batch file that figures out the absolute path to the
directory containing the DLLs before launching the JVM. During
development, your IDE should allow you to set JVM options.

Welcome to the crazy/annoying world of JNI!

-Nate

PS
For completeness, I should mention a 4th option, and that is to write
your own classloader and override ClassLoader#findLibrary(String). This
is the only way to dynamically specify the native library paths in Java
code for code you don't control. For code you do control, you can use
"System.load(String)".


Sébastien Pierre wrote:

> Hi there,
>
> I was playing with Pnuts and wanted to script Jogl with it, following
> this tutorial <http://www.cs.umd.edu/~meesh/kmconroy/JOGLTutorial/>.
>
> The first lines of the tutorial are like that (in Java)
>
>     import net.java.games.jogl.*
>     GLCanvas canvas =
> GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
>
> So, I decided to do this in Pnuts, which gets me an exception:
>
>     > canvas =
> javax.media.opengl.GLDrawableFactory.getFactory().createGLCanvas(new
> javax.media.opengl.GLCapabilities())
>     pnuts.lang.PnutsException : javax is not defined
>
> Next, I decided to do this instead, which still doesn't work:
>
>     > import javax.media.opengl.GLDrawableFactory
>     null
>     > import javax.media.opengl.GLCapabilities
>     null
>     > canvas = GLDrawableFactory.getFactory().createGLCanvas(new
> GLCapabilities())
>     javax.media.opengl.GLDrawableFactory class.getFactory()
>     java.lang.NoClassDefFoundError : null
>
> However, doing this shows me that GLDrawableFactory is known:
>
>     > new GLDrawableFactory()
>     class javax.media.opengl.GLDrawableFactory()
>     pnuts.lang.PnutsException : no constructors match: class
> javax.media.opengl.GLDrawableFactory args: []
>
> So how should I proceed to get these lines working ?
> TIA,
>
>  -- Sébastien
>
>
>
>

Re: Using Pnuts to script Jogl (java OpenGL)

by Sébastien Pierre-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Nate !

Le 07-07-05 à 14:01, Nate a écrit :

> I tried this out. Using this Pnuts code...
>
> import net.java.games.jogl.*
> canvas = GLDrawableFactory.getFactory().createGLCanvas(new  
> GLCapabilities())
>
> This is the NoClassDefFoundError that you should have been getting.  
> Not sure why you were getting "java.lang.NoClassDefFoundError : null".
>
> Since I see jogl-win32 came with some DLLs, I assumed  
> WindowsOnscreenGLContext has a static initializer that tries to  
> load a native library. When the native library is not found, the  
> exception is swallowed because it happened in a static initializer  
> and the NoClassDefFoundError is thrown instead. Thanks Java!
>
> To fix this, the DLLs need to be in your Windows path. You have  
> some options...
>
> 1) You can put them in a directory like "c:\windows\system32".
> 2) You can add the directory containing the DLLs to your path. Be  
> sure to restart your IDE if you change your path.
> 3) You can add this JVM option, where "C:\jogl-win32" is the  
> directory containing the DLLs...
> -Djava.library.path="C:\jogl-win32"

I tried to add the directory containing the jogl native libs to a  
directory in my classpath (~/Local/Java), and then doing a  
'System.loadLibrary("jogl")' without success. I then tried to add  
this to the 'java.library.path' using System.setPropery, but it  
failed too.

System.setProperty("java.library.path", "/Users/sebastien/Local/
Java:.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/
lib/java")

I eventually solved the problem by copying the jogl files to " /
Library/Java/Extensions/" (on OSX), and it worked ! Pfeew... Java  
class loading is powerful, but certainly complex !

Thanks a lot for your help,

  -- Sébastien

Re: Using Pnuts to script Jogl (java OpenGL)

by NateS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unfortunately, Java doesn't look for native libs in the classpath.

You have to use the parameter "-Djava.library.path=xxx" when you start
the JVM, you can't use System.setProperty to set this property.

Glad you got it working!

-Nate


Sébastien Pierre wrote:

> Hi Nate !
>
> Le 07-07-05 à 14:01, Nate a écrit :
>
>> I tried this out. Using this Pnuts code...
>>
>> import net.java.games.jogl.*
>> canvas = GLDrawableFactory.getFactory().createGLCanvas(new
>> GLCapabilities())
>>
>> This is the NoClassDefFoundError that you should have been getting.
>> Not sure why you were getting "java.lang.NoClassDefFoundError : null".
>>
>> Since I see jogl-win32 came with some DLLs, I assumed
>> WindowsOnscreenGLContext has a static initializer that tries to load
>> a native library. When the native library is not found, the exception
>> is swallowed because it happened in a static initializer and the
>> NoClassDefFoundError is thrown instead. Thanks Java!
>>
>> To fix this, the DLLs need to be in your Windows path. You have some
>> options...
>>
>> 1) You can put them in a directory like "c:\windows\system32".
>> 2) You can add the directory containing the DLLs to your path. Be
>> sure to restart your IDE if you change your path.
>> 3) You can add this JVM option, where "C:\jogl-win32" is the
>> directory containing the DLLs...
>> -Djava.library.path="C:\jogl-win32"
>
> I tried to add the directory containing the jogl native libs to a
> directory in my classpath (~/Local/Java), and then doing a
> 'System.loadLibrary("jogl")' without success. I then tried to add this
> to the 'java.library.path' using System.setPropery, but it failed too.
>
> System.setProperty("java.library.path",
> "/Users/sebastien/Local/Java:.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java")
>
>
> I eventually solved the problem by copying the jogl files to "
> /Library/Java/Extensions/" (on OSX), and it worked ! Pfeew... Java
> class loading is powerful, but certainly complex !
>
> Thanks a lot for your help,
>
>  -- Sébastien
>
LightInTheBox - Buy quality products at wholesale price!