Groovy and Open GL

I’ve been occasionally folling with Groovy and Open GL on the side but I have had any radical success. So far I managed to find a quick start tutorial on JOGL and rewrite the code using Groovy. (The rewrite consisted of a copy and paste and the removal of one anonymous inner class.) While I’m not thrilled at my success I am thrilled at what I found on the net… a tutorial for Space Invaders 2d/3d! Now let me explain. My days of being a video game addict are long gone and I haven’t played any games in over a year. The last time I played anything I didn’t feel the same addiction that would keep me up for hours through the night. I think I’ve out grown video games a little. I said a little. I still love them and I’m still partially interested in creating my own game as I was so many years ago in my youth. More important I believe the aformentioned tutorial is an excellent starting point for someone like me who has little if any knowledge on UI or Open GL. I feel like I really need to sit in front of some text and read up on it as much as possible and the tutorials are inspiring.

Why Open GL? Well I saw a video stream of one of Romain Guys presentations of his Aerith project and I heard him mention that he used Open GL in some Swing components to acheive some of the effects. Let me tell you. I’ve been loosely following this guy’s work and I’d be proud to recreated a small percent of what he has done in Swing. Ever since then I’ve been on a quest to design a spectacular UI using Groovy and Swing. Romain Guy shows us what you can do in Swing so I see what’s possible. I also know how much fun it is to work with Groovy so that’s what has been flaming my passion.

Getting to the point. Let me share a little of what I’ve done so far. (It ain’t much.) I downloaded the JOGL API and it’s native binaries for Linux. I set my library path in the startGroovy script (so I could work from Groovy console) to include my $HOME folder. I placed the JOGL jar in $GROOVY_HOME/lib and expanded the native jar in my $HOME folder. I started Groovy console, copied and tweaked the code from the first Open GL tutorial I found and ended up with this:

import com.sun.opengl.util.*

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestRenderer implements GLEventListener
   private GL              gl;
   private GLDrawable      glDrawable;

   public void init(GLDrawable drawable)
   { = drawable.getGL();
       this.glDrawable = drawable;

       drawable.setGL( new DebugGL(drawable.getGL() ));

       System.out.println("Init GL is " + gl.getClass().getName());

   public void display(GLDrawable drawable)

       gl.glColor3f(1.0f, 0.0f, 0.0f );

       gl.glBegin( GL.GL_TRIANGLES );
           gl.glVertex3f( 0.0f, 0.0f, 0.0f );
           gl.glVertex3f( 1.0f, 0.0f, 0.0f );
           gl.glVertex3f( 1.0f, 1.0f, 0.0f );

   public void reshape(GLDrawable drawable, int x, int y, int width, int height)

   public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)


public class InnerWindowListener extends WindowAdapter {
      def animator
      public InnerWindowListener(def animator) { this.animator = animator }
                public void windowClosing(WindowEvent e) {

           Frame testFrame = new Frame("TestFrame");
           testFrame.setSize( 512, 384 );

           GLCapabilities glCaps = new GLCapabilities();

           GLCanvas canvas = new GLCanvas(glCaps);

           testFrame.add( canvas );

           canvas.addGLEventListener(new TestRenderer());

           final Animator animator = new Animator( canvas);
           testFrame.addWindowListener(new InnerWindowListener(animator));


All I get is a grey screen when I run it. Failed attempt If anyone can decipher what I’ve done wrong then please holla back…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s