OpenGL Test app + source code

Hi everyone,

I’m just diving into OpenGL now and started learning lwjgl. Really nice library so far and I’m impressed.

Having been part of java-gaming.org for a while I’m finally getting close to releasing some early game prototypes and I want to maximize my chances of having them actually work. I’ve also seen lots of people struggling with getting started, having cross-platform issues (e.g. input doesn’t work), or having trouble building and deploying their game.

To hopefully alleviate some of these difficulties and to scratch a maven itch, I spent the last few days making a small test app and maven project that can be easily built and run from the command-line on Mac, Windows, and Linux.

Web Start: http://laialfa.com/lwjgl/launch.jnlp

Source: http://laialfa.com/lwjgl/opengl.zip (all files except for OSXAdapter.java are released into the public domain)

Original page: http://laialfa.com/lwjgl

Requesting your feedback!

  • If you use maven - please download the source, read the README.txt, and try and build it
  • If you are associated with lwjgl - please download the source and review it (I’m a lwjgl newbie!)
  • Either way - try the webstart link and let me know if it works for you.

http://laialfa.com/lwjgl/opengl-test.png

I’ve spend the last month learning OpenGL and lwjgl. A couple of points I want to share:

Swing and AWT doesn’t mix especially with LWJGL in the picture. I’ll be changing my code so that the Frame that hosts the lwjgl Canvas does not use any Swing.

  • The are performance issues when mixing AWT and Swing components into the same Frame. For example, appending text to a JTextArea in a JScrollPane causes JTextArea.paintComponent to take an exorbitant amount of time (50-200 ms) on my Mac. This really mucks up the framerate when doing passive rendering using the EDT.
  • You’ll need to deal with all the usual headaches of mixing heavyweight (AWT) with lightweight (Swing) components. For example the lwjgl Canvas will overwrite JMenus.

The operational intent behind OpenGL is very different from the event model of Java GUI. This manifests itself as the difference between active and passive rendering as well as polling versus events for input. Some of the problems stemming from this include:

  • Attaching an event listener to the lwjgl Canvas works in OS X and Linux but not Windows.
  • Need to manually translate lwjgl mouse events into presses, releases, clicks, double-clicks, and drags.
  • The lack of a mouse exit event makes it impossible to perform some functionality that purely relies on mouse positioning. For example I want to pan the camera when the cursor is near the edge a.la. StarCraft style. This would work if I was full screen but doesn’t when using a normal window because I have no way of knowing when the cursor has exited the lwjgl Canvas.

Overall I still like LWJGL and it works well as advertised. Just don’t try to treat it as a JPanel because it isn’t!

I’m also a newbie learning lwjgl. The first thing I sure to do is not mixing swing and lwjgl things together. I suggest more attractive animations, letting user choose with a ke or ComboBox.

Do keep in mind that there are options like TWL (a fully fledged OpenGL GUI) or Nifty GUI that can be used instead of AWT. In the next LWJGL release (LWJGL 2.8 ) the native Display window is getting the ability to be resizable, so there will be even less need to use AWT directly.

Why do I get 0 when I press almost any “number” key on my AZERTY keyboard, between letters and F keys (F1 … F12)? Is it the expected behaviour? Pressing these keys with shift returns a different key code per key which seems more logical.

gouessej,

Are you seeing “lwjgl key pressed: 0” for the actual numbers 0-9? Or just for the function keys F1-F12?

The code in question is:


Display.update();
...
while (Keyboard.next()) {
    if (Keyboard.getEventKeyState()) {
        statusLabel.setText("Last input - lwjgl key pressed: " + Keyboard.getEventKey());
    } else {
        statusLabel.setText("Last input - lwjgl key released: " + Keyboard.getEventKey());
    }
}

And so it is indeed a bug if it is reporting 0 for multiple keys.

Hi Kappa,

Thanks for the pointers. I looked at both of the projects and they have pretty sweet GUIs. The problem is that a large portion of my users will be on Mac and they can get pretty finicky if they start seeing Windows or foreign style GUIs in their applications.

What I’ll probably end up doing is create a main Frame that has an embedded lwjgl Canvas and only AWT components in it. The rest of the application will be in modeless dialogs that will be a mix of Swing/AWT. There are a lot of stats in my app and I predict that the best approach will be to have a lot of sub-windows that the user can position and resize to their hearts content.

I get this:

[quote]lwjgl key pressed - Keyboard.getEventKey(): 0
[/quote]
I think it is not your fault, I had the same behavior with JInput, I don’t know why.