OpenGL Gears in Clojure using JOGL

489 views
Skip to first unread message

Dustin Withers

unread,
Jun 15, 2008, 11:09:03 PM6/15/08
to Clojure
Hello fellow Clojurer's!

I've posted a ported version of the OpenGL Gears demo that comes with
JOGL. I hope this is the appropriate place to post code like this. It
was really just something to learn a little bit of OpenGL and Clojure.
I pretty much ported the imperative nature of the original code. The
original Java version is considerably faster. I used Refs for the
global variables and I think that maybe what I'm doing wrong but I
couldn't get mutable access to the variables in a proxy any other way.
If anyone has suggestions on how to make it faster/better I'll make
the changes and repost.

http://clojure.googlegroups.com/web/opengl-gears.clj?gda=gTJ_y0EAAABDIkriCAGxFgqh3JA2kVqHjmUnUmFxkzZFmBPeskNnImG1qiJ7UbTIup-M2XPURDQ2vNdh001Siw0x8QiEtM34WlKsreMtIDAb3JYcIi6O-A&gsc=FWPSYAsAAADf6lsqqJAqFfo_UvfMxMwC

-dustin

Christophe Grand

unread,
Jun 16, 2008, 4:41:20 AM6/16/08
to clo...@googlegroups.com
Dustin Withers a écrit :

> I've posted a ported version of the OpenGL Gears demo that comes with
> JOGL.
> If anyone has suggestions on how to make it faster/better I'll make
> the changes and repost.
>
Hello Dustin,

I can't get it to work (certainly an issue with my JOGL install) but if
you compile your code with *warn-on-reflection* set to true, you'll see
a lot of warnings. You can make them go way by hinting your drawable arg
for each method of the proxy:
(proxy [GLEventListener] []
(display [#^javax.media.opengl.GLAutoDrawable drawable]
...

and by hinting the gl arg in the gear function.
(defn gear
[#^javax.media.opengl.GL gl inner-radius outer-radius width teeth
tooth-depth]

A rule of thumb is that each time you invoke a method on an unhinted arg
you use reflection (unless it's a method of java.lang.Object).

It may help it to run faster.

Christophe

Robert Feldt

unread,
Jun 16, 2008, 4:49:16 AM6/16/08
to Clojure
Nice to have examples of using Clojure and JOGL, thanks. Performance
might increase with type hints.

However, I can't get it to work although I have a fresh JOGL install
and can run the (normal) JOGL demos.

Any hints on how to set things up for it to work properly?

My details:
Mac OS X 10.5.2
Latest clojure from svn

robert_feldt:~/local/java_classpath/jogl-1.1.1-macosx-universal/lib$
java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-
b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)
robert_feldt:~/local/java_classpath/jogl-1.1.1-macosx-universal/lib$
set | grep CLASSP
CLASSPATH=.:/Users/robert_feldt/local/java_classpath/
processing_core.jar:/Users/robert_feldt/local/java_classpath/
jogl-1.1.1-macosx-universal/lib/gluegen-rt.jar:/Users/robert_feldt/
local/java_classpath/jogl-1.1.1-macosx-universal/lib/jogl.jar

Regards,

Robert

Robert Feldt

unread,
Jun 16, 2008, 6:04:17 AM6/16/08
to Clojure
Ok, I got it to work now.

Had to make sure not only the general CLASSPATH was set correct but
the one used in my clj script. Also the DYLD_LIBRARY_PATH env var was
not set correct (not sure why the JOGL demo worked anyway).

The type hints really improves performance noticeably.

Regards,

Robert

Dustin Withers

unread,
Jun 16, 2008, 12:23:34 PM6/16/08
to Clojure
On Jun 16, 3:41 am, Christophe Grand <christo...@cgrand.net> wrote:
> I can't get it to work (certainly an issue with my JOGL install) but if
> you compile your code with *warn-on-reflection* set to true, you'll see
> a lot of warnings.

Christophe,

Thank you very much for the help. The type hints do indeed help with
speed. I have one question though. How do I set *warn-on-reflection*
to true? Using (def *warn-on-reflection* true) I get the following
error:

Name conflict, can't def *warn-on-reflection* because namespace: user
refers to:#'clojure/*warn-on-reflection*
[Thrown class java.lang.Exception]

Thanks,
-dustin

Christophe Grand

unread,
Jun 16, 2008, 12:41:20 PM6/16/08
to clo...@googlegroups.com
Dustin Withers a écrit :

> Thank you very much for the help. The type hints do indeed help with
> speed. I have one question though. How do I set *warn-on-reflection*
> to true? Using (def *warn-on-reflection* true) I get the following
> error:
>
> Name conflict, can't def *warn-on-reflection* because namespace: user
> refers to:#'clojure/*warn-on-reflection*
> [Thrown class java.lang.Exception]
>
In the REPL, (set! *warn-on-reflection* true).
If you are using Script:
(in-ns 'clojure)
(def *warn-on-reflection* true)
(in-ns 'user) ; or whatever is your namespace
(your-code)

Christophe

Dustin Withers

unread,
Jun 16, 2008, 5:30:13 PM6/16/08
to Clojure
I've updated the Gears Demo with hints and a small macro to wrap the
glBegin and glEnd statements. It's working much better now.

Enjoy!
-dustin

On Jun 15, 10:09 pm, Dustin Withers <fadedd...@gmail.com> wrote:
> Hello fellow Clojurer's!
>
> I've posted a ported version of the OpenGL Gears demo that comes with
> JOGL. I hope this is the appropriate place to post code like this. It
> was really just something to learn a little bit of OpenGL and Clojure.
> I pretty much ported the imperative nature of the original code. The
> original Java version is considerably faster. I used Refs for the
> global variables and I think that maybe what I'm doing wrong but I
> couldn't get mutable access to the variables in a proxy any other way.
> If anyone has suggestions on how to make it faster/better I'll make
> the changes and repost.
>
> http://clojure.googlegroups.com/web/opengl-gears.clj?gda=gTJ_y0EAAABD...
>
> -dustin
Reply all
Reply to author
Forward
0 new messages