Space Invaders 102 - OpenGL

I’ve just complete the source for the next space invaders tutorial. The JNLP is here:

http://www.cokeandcode.com/spaceinvaders102/si102.jnlp

the source code for those interested can be found here:

http://www.cokeandcode.com/spaceinvaders102/spaceinvaders102.zip

There should be very little difference in the demo to the original version. I’ve not got the ability at the moment to test on Linux and MacOS, so any problems let me know.

The tutorial is going to cover:

a) Seperating rendering from logic
b) Refactoring and using package (aimed at C++ folks who seem to be afraid of using namespaces ;))
c) OpenGL initialisation (JOGL)
d) Using OpenGL for 2D games
e) Discussion of abstracting Java2D/OpenGL, the benefits of rendering with OpenGL
f) Anything else that comes to mind as its written :wink:

Kev

Works fine on linux.

It is also just as jerky in OGL as the original was (especially the player’s ship is jerky, and the invaders less so - nb they also appear to flicker a lot (the invaders) in OGL mode? [windowed, of course]).

So, that would seem to confirm it’s your timer code or else input-event-handling that is causing the jerkiness?

PS that’s one FAT ASS invaders clone! ;D lol

Arse, you mean the old one didn’t sort out the problems on your machine? I thought it had gone away?

I’m really starting to worry about your linux box in particular :wink: I’ve tested the original version on my couple (which are currently dead), smooth a silk. Most confusing. Could you mail me the hardware spec or something?

Kev

PS. Fat ass! Damn right, thats one of the things I want to mention in the tutorial, how much you have to ship to get OpenGL in Java.

If you get a chance, could you try it again. I was seeing a similar sort of lack of control under linux which seems to have been cleaned up now. Seemed to be related to the keypressed/keyreleased issues again.

Kev

Runs fine for me, I’d still like to see that fps counter ;D

[quote]If you get a chance, could you try it again. I was seeing a similar sort of lack of control under linux which seems to have been cleaned up now. Seemed to be related to the keypressed/keyreleased issues again.

Kev
[/quote]

  1. JWS didn’t seem to download any new data (tried twice - maybe it went by REALLY fast?)

  2. No appreciable difference (could have been a very slight improvement, not sure?)

Broken on Mac:

java.lang.UnsatisfiedLinkError: /Users/scottpalmer/Library/Caches/Java Web Start/cache/http/Dwww.cokeandcode.com/P80/DMspaceinvaders102/DMlib/RNjogl-macos-native.jar/libjogl.jnilib:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1469)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at net.java.games.jogl.impl.NativeLibLoader.(NativeLibLoader.java:48)
at net.java.games.jogl.impl.GLContext.(GLContext.java:51)
at net.java.games.jogl.impl.macosx.MacOSXGLContextFactory.createGLContext(MacOSXGLContextFactory.java:49)
at net.java.games.jogl.GLCanvas.(GLCanvas.java:70)
at net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:94)
at net.java.games.jogl.GLDrawableFactory.createGLCanvas(GLDrawableFactory.java:80)
at org.newdawn.spaceinvaders.jogl.JoglGameWindow.startRendering(JoglGameWindow.java:101)
at org.newdawn.spaceinvaders.Game.(Game.java:75)
at org.newdawn.spaceinvaders.Game.main(Game.java:324)
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:324)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:844)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:804)
at com.sun.javaws.Launcher.continueLaunch(Launcher.java:682)
at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:397)
at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:199)
at com.sun.javaws.Launcher.run(Launcher.java:167)
at java.lang.Thread.run(Thread.java:552)

Just uploading new bits:

  • A version number of the title bar so we can be sure we’ve got the same version

  • JNLP with “Mac OS” changed to “MacOS”, could you tell me what the os.name System property is set to on MacOS?

  • Different JOGL libs for macos.

Could you let me know if this makes any difference, I’ve had trouble with webstart on MacOS as long as I’ve been using it. Might be nice to sort them out :slight_smile:

One success, cheers Nonous, frame counter is even more annoying now since to add it for jogl I’d have to go into the details of using text in OpenGL (which might be a bit much).

Kev


            Runtime rt = Runtime.getRuntime();
            
            add( new JLabel( "<html>The latest version of Java is available from<p><a href=\"http://java.sun.com\">http://java.sun.com</a><p>Latest version is 1.4.2 (Nov-2003)" ) );
            
            add( new JLabel( "<html>Java Vendor: "+System.getProperty( "java.vendor" )+"<P>"+"Java Version: "+System.getProperty( "java.version" )+"<P>"+"Free Memory: "+rt.freeMemory()+"<P>"+"Max Memory: "+rt.maxMemory() ) );
            
            add( new JLabel( "<html>OS name: "+System.getProperty( "os.name" )+"<P>"+"OS version: "+System.getProperty( "os.version" )+"<P>"+"OS architecture: "+System.getProperty( "os.arch" )+"<P>"+"Num Processors: "+rt.availableProcessors() ) );

…is copy/pasted code with removal of local lib-specific calls, that should give you all the pertinent info (taken directly from the code that auto-generates the “About Java Version” dialog for our GUI tools; very useful when doing support!).

IIRC, if inserted in a JComponent of some sort, those labels will all work as required.

On a related note, perhaps Kev you could do a followup to your JWS article, one which specifically concentrates on the OS-specific sections, given how many there are to cover, and e.g. lists which JVM (vendor + OS) reports each? (assuming you can get some help from users of esoteric VM’s :))

PS I have v0.1 now, and nothing else has changed.

Ewww, jerk-o-matic! Both versions jerk equally nasty. Are you using some dodgy timing code in there? Sure looks like it!

Cas :slight_smile:

What platform you using Cas? If its old Windows, then the timing doesn’t use a highres timer which might cause the jerkyness.

The code for movement is just standard,

  • Calculate delta since last render
  • Move entities/sprites based on movement-speed * delta
  • Redraw

Kev

Nice and smooth here in OpenGL, mostly smooth in Java2D (very slight juddering). WinXP, GeForce4 Ti. ;D

WinXP Pro, Dual 1Ghz, Radeon 8500, 700Mb RAM. Should be smooth as a baby’s bum, methinks.

Cas :slight_smile:

Erk, I’d agree, it should be as alike to a baby’s bum as the bum of a baby…

Wonder what the flip is going on, I’ll try letting it run as fast as, tonight and hopefully that’ll tidy things up… OOI Cas, have you tried Mini Adventure? If so, is that as jerky as Tony Blair too?

Kev

You had the os.name correct… it did download JNI libs.
os.name = “Mac OS X”
Maybe the new Mac JNI libs will fix it. (But you will have to change back the os name :slight_smile: )

Updated the JNLP for “Mac OS” (I actually ripped the MacOS tag from AlienFlux jnlp?)

I’ve also changed the timing so instead of attempting to wait for 10 milliseconds between frames, we only wait for 1. Maybe this will smooth things out a bit…

Added a FPS counter to the title of window :wink:

Kev

Works great now.

OpenGL 360fps
Java2D 39 fps

Yeah, OpenGL is a bit better :slight_smile:

Fantastic news, thanks for the retest!

Any news on when Apple are going to sort out their graphics pipeline and make Java2D accelerated? Its the only thing stopping me buying a PowerBook.

Kev

Java2D 290-340 fps
OpenGL 78-80 fps

:o

/me turns vsync off

OpenGL 250-270 fps

Odd ???