#708 JOGL OpenGL in Fan

KevinKelley Fri 7 Aug 2009

FanGL

FanGL

There are several options for 3D graphics in Java. I wanted it in Fan. Above is a simple .png image, mapped 6 times onto a cube, and spinning, running in a Fan window; I implemented a GLCanvas and GLCanvasPeer to provide an OpenGL render context.

Since the Fan's windowing toolkit is built on the Eclipse SWT library, I started there with SWT's GLCanvas. This works with the JOGL low-level GL bindings to give the graphics card direct control of a screen "canvas". This is of course what you want: to offload the graphics processing to the graphics card, let it draw a portion of the screen without you having to copy between memory buffers. It works well, using practically no processor time.

As a nice test case I used the Java port of the NeHe OpenGL Lessons: that's lesson 6, which is how far I've gotten of the 48. They get better.

tompalmer Wed 12 Aug 2009

Sounds great, by the way. Any chance of focusing the API support around OpenGL ES 2.0? I ask because if Mozilla succeeds in building a standard around it for Canvas3D, then it might make it easier to write desktop apps that also work as web apps.

I'm also mentioning because I'm having some potential need to work on a 3D display app in the near future. I'd love to make it web-based, but being able to get around to that web support in the future (due to Fan) could also be a nice option.

Or in other words, this might make Fan a good choice for the display side of the application (if it happens).

Update: Alternatively, I can just try to pay attention to this list of functions in the API.

KevinKelley Wed 12 Aug 2009

Glad to see that Mozilla link; the big issue here is getting cross-platform access to the drivers. If there's a GL-capable canvas in the browser, then that gets easier.

Right now all I'm doing is whatever works in SWT -- they've had a GLCanvas since 3.2; we're using SWT 3.4 in Fan now, and 3.5 is in preview release last I looked. The first GLCanvas versions apparently only supported OpenGL 1.1 - no shaders, etc. They're supposed to be at 2.0 now at least, but I haven't proved yet whether that works.

There seems to be three layers to consider: low-level bindings; UI (canvas); and scene-graph management.

I'm using the JOGL binding (JSR 231), it's got distributions for major platforms and reportedly at least can be used with applets, so getting low-level cross-platform 3D support is mainly a matter of packaging/distributing the appropriate jars/dlls.

OpenGL ES sounds interesting; like they cut out some old legacy stuff. With the iPhone maybe it'll get traction to get implemented everywhere. Part of the problem here is, even if we've got OpenGL, you still have to test for capabilities to find out what the hardware supports, to get the really neat features. A widely-crossplatform, 2.0-level API would be a good thing.

tompalmer Thu 13 Aug 2009

Thanks for the review of the issues. I know a little bit about OpenGL but not a whole lot.

freddy33 Sun 30 Aug 2009

Sounds great! I will like to do some pure JOGL with Fan. Where should I start? I have no SWT! Do you plan on sharing NeHe OpenGL Lessons in Fan :) ?

KevinKelley Sun 30 Aug 2009

My web site's in transition this week, but I'll be putting up the Lessons ports soon.

One way or another, you have to give OpenGL something to draw on, so I chose to use SWT for the GLCanvas, to make it easy to integrate with Fan's user-interface library. (The Fan Widget Toolkit is built on SWT, so actually you do have it in the Fan distro).

For some uses at least, avoiding SWT and going straight to a JFrame (easy to do thru Fan's FFI) could be useful. That way you could use lightweight Swing widgets for a UI overlay on a GL window, for instance, and you'd get easy transparency and effects. I'm planning on experimenting with that, too.

Login or Signup to reply.