Absolutely new to 3D and LWJGL... errors with SpaceInvaders

Hi guys.

I am absolutely totally and in all ways green to everything 3D and LWJGL. That aside, I have nearly as much experience as you can get with Java2D and a large part of Java itself, so I’m not a noob coder in general.

In any case - I recently downloaded LWJGL, installed it on my computer, and am trying to figure it out from the feeble tutorials I’ve located on the net. I just downloaded Space Invaders by Kevin Glass (from CVS), put the source code into a new project, imported everything, put it all in the right folders etc. etc., and sounds do not work.

Here is the error that pops up:


Use -fullscreen for fullscreen mode
java.io.IOException: Stream closed
	at java.io.BufferedInputStream.ensureOpen(BufferedInputStream.java:120)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:199)
	at java.io.DataInputStream.readInt(DataInputStream.java:443)
	at com.sun.media.sound.WaveFileReader.getFMT(WaveFileReader.java:244)
	at com.sun.media.sound.WaveFileReader.getAudioInputStream(WaveFileReader.java:160)
	at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:710)
	at org.lwjgl.util.WaveData.create(WaveData.java:93)
	at SoundManager.addSound(SoundManager.java:153)
	at Game.initialize(Game.java:241)
	at Game.<init>(Game.java:178)
	at Game.main(Game.java:579)
Exception in thread "main" java.lang.NullPointerException
	at SoundManager.addSound(SoundManager.java:156)
	at Game.initialize(Game.java:241)
	at Game.<init>(Game.java:178)
	at Game.main(Game.java:579)

By commenting out various things and looking through the code I’m guessing that it is having some issue streaming the sound file into useable data. I have the sounds in the same folder as the images, which do work. Help would be appreciated.

I personally learn everything I know from looking at source code, so as long as I can get this to work I should be on my merry way.

PS - Is there any reason to convert my game from Java2D to OpenGL 2D? A comparatively small amount of images can make even my G5 choke when using Java2D, and because OpenGL gives direct hardware access I assume it’s faster. Is it reasonable to waste my time doing this?

Thank you very much, guys!

looks like you need to add the sound files to the classpath

If you want hardware acceleration and the potential to do awesome 2d visual effects very cheaply, OpenGL wins hands down over Java2D. In fact the only reason I can think of for chosing Java2D over OpenGL is if you want to target platforms which have no OpenGL.

Okay, I thought it might have something to do with classpath somewhere. Are those the things found in the “native” folder within the LWJGL download folder (ext .dylib && .jnilib)? I think I put all of them into my classpath folder to get LWJGL working at all in the first place. Do I need separate ones for OpenAL?

Thanks a lot.

Good to see OpenGL is a lot faster, because Java2D frankly sucks for making games. I’ll definitely use it for things like windowed utilities and the like, but certainly not for games. Other platforms? Screw 'em. 8)

Okay, let me add a little more info on this…

I have Mac OS X, I’m using Eclipse. I read this page: http://lwjgl.org/installation.php and I think the problem might be that I don’t have any file called “libopenal.dylib” I do have “openal.dylib” however. I went to download it again in case that will help.

I have all the files saved in my java extensions folder (where casspaths are normally read from) and I have also issued the command into the Run… configuration in Eclipse.

The wierd thing is, you must have your actual sound files, the .wav or whatever you are using, in your classpath. I don’t know why it works this way, but it does. However, just adding the folder you run the game from to your classpath should do the trick usually.

NEVER add any lwjgl files to any of the the jre/jdk folders. It will only cause conflict when you get more than one in the classpath.

I just copy the native files to the project in the “Package Explorer” in Eclipse. That way they will be in “current directory” when the application is run. You can try doing the same with the wav files.

Predictably, none if this works.

As for never adding lwjgl into the jre folders, I’m not. It’s where Mac OS X reads classpaths from. Library/Java/Extensions. There was absolutely nothing in the folder until I put these in there, and when I removed them it created errors within eclipse, even if I added them directly to the package explorer. Putting the sounds directly into the package explorer does not work because I already have them in there.

As for adding the wav files to my classpath, what exactly do you mean by this? Like put them in the same place as the lwjgl jar’s or what? Is OpenAL that annoying that you can’t reference a folder from where the executing is like with normal Java sound? It looks like you should be able to from how Kevin Glass coded this…

I don’t know if Eclipse handles this differently on Mac, but I usually use -Djava.library.path=“PathToLWJGLFiles” in the VM arguments bit of an Eclipse Run… config. Then you can add the dir with your resources (sounds etc.) under the classpath bit of the run config.

This has nothing to do with OpenAL, but getting a file using the class loader. Don’t think it goes threw all the classpaths, and the files is not picked up. Or the files is not where they should be.

Can you post a link to the tutorial. The 104 tutorials I found on google (www.cokeandcode.com) don’t contain any sound.

I got it from LWJGL’s source forge.
http://cvs.sourceforge.net/viewcvs.py/java-game-lib/LWJGL/src/java/org/lwjgl/examples/spaceinvaders/#dirlist

Unless people are interested in this for academic purposes, don’t worry about it anymore. I’m just going through the Nehe tutorials instead at this point.

Thanks for all the help.