Migrating from Java2D to LWJGL

Hi!

I’m evaluating the possibility to migrate Mighty Bubbles to LWJGL.

What are the pros and cons of LWJGL?

How easy/user freindly is it for doing 2D?

Is there stablility/compatibility issues (video cards, sound cards, …)?

Does it have support for multiple audio formats with OpenAL? It is probably up to OpenAL itself? I ask this question because the fmod licence is too expensive/risky for a small budget game.

Thanks

Ho! And I’ve already read the About section on the LWJGL web site.

i actually started with the space invaders demo by kevin glass, where he uses java2d and opengl to run the same game, its a good place to see how it sort of works.

Pros:

  • Fast
  • Simple
  • Easy
  • No tricks or crazy workarounds, just OpenGL
  • Loads of OpenGL literature available
  • All-in-one library is very convenient to use and deploy
  • Fullscreen works! Properly!

Cons:

  • Will fail on machines with crap drivers
  • At least 35% of Windows machines don’t have drivers at all, and 50% of Linux machines.
  • You’ll have to sign your code to run it
  • Pain-in-the-arse packing your sprites into legal OpenGL textures
  • Some learning curve. But probably easier than any Java libraries.
  • Requires Java 1.4 or above.

Cas :slight_smile:

OK thanks.

And what about OpenAL if I want to load ogg or mp3 files and mods/midi?

There is a ogg library available wich is very easy to use. Don’t know of mp3, midi or mod libs. But if there are independant libraries then it would be easy to adapt it to OpenAL.

For OGG, use JOrbis. Don’t use MP3.

For MIDI, use JavaSound! OpenAL is purely for playback of PCM data.

FMOD is still an option! Don’t discount it.

Cas :slight_smile:

[quote]There is a ogg library available wich is very easy to use. Don’t know of mp3, midi or mod libs. But if there are independant libraries then it would be easy to adapt it to OpenAL.
[/quote]
About the OGG lib, do you mean there’s an integrated API with LWJGL or what? Also you seem to say that OpenAL is not as rich/integrated as FMOD in terms of features?

[quote]For OGG, use JOrbis. Don’t use MP3.

For MIDI, use JavaSound! OpenAL is purely for playback of PCM data.

FMOD is still an option! Don’t discount it.

Cas :slight_smile:
[/quote]
I’ve already checked JOrbis but it seems to be a rather low level API isn’t? I don’t want to do buffer management because it’s too tricky considering the time I have to develop and I prefer to concentrate on the game content/gameplay. I’d like something high level like the fmod3 package in LWJGL.

The problem with FMOD is the licence price. I can afford it. It’s too risky. Do you use it in Alien Flux or in Super Dudester?

Have a look at my OggPlayer. It’s 3 lines of code to play file. It is played directly from a InputStream so you don’t have to waste memory by decoding it first.

AF & Dudester both use JOrbis and OpenAL. I just load all my oggs on demand, decode them into large bytebuffers, and chuck them straight at openAL and forget about them. When I want to play one, it’s just a case of calling alSource() and playing the buffer. I wrapped it up in a few utility classes and haven’t thought much about it for a couple of years.

Cas :slight_smile:

[quote]AF & Dudester both use JOrbis and OpenAL. I just load all my oggs on demand, decode them into large bytebuffers, and chuck them straight at openAL and forget about them. When I want to play one, it’s just a case of calling alSource() and playing the buffer. I wrapped it up in a few utility classes and haven’t thought much about it for a couple of years.

Cas :slight_smile:
[/quote]
Cool! Could you put it publically in LWJGL please if it’s not already done?

[quote]Have a look at my OggPlayer. It’s 3 lines of code to play file. It is played directly from a InputStream so you don’t have to waste memory by decoding it first.
[/quote]
Thanks! I’ll check that…

I use JavaLayer for all my MP3 playing, it’s only 3 lines of code to get it working and they’ve just released version 1.0

I have a tutorial on my site that shows you how to use it, and you can download the library from here.

http://www.javazoom.net/javalayer/javalayer.html
http://games.swizel-studios.com/tutorials.html

Andy

I use JavaLayer for all my MP3 playing,

The mp3 license is quite expensive and there is no reaon to use mp3 when you can have ogg. Ogg is just better - especially with low bitrates (after all it needs to be downloaded at the end and smaller with equal quaility is really a good thing).

You can go pretty low for most sound effects. Like mono, 22khz and 64kbits (or even less).

Both formats have their own kind of artifacts, which get pretty obvious with really low bitrates. Mp3’s artifacts are very unpleasing to the human ear (hihats=pain) whereas ogg’s is more a damped down thing. It’s just not as crisp as the original anymore, but at least it doesn’t hurt.

I’m probably getting into the conversation too late here (I’ve been hanging out on the lwjgl forums too much I guess). I recently “ported” a couple of my java2D games over to lwjgl. It was pretty painless. In order to help the transition, I wrote a couple of methods that “paint” to the screen (basically, I create a quad of the same size as the graphic asset and paste the graphic onto it as a texture - this works, although I’ve started redoing some of my graphics for openGL since texture memory is always at a premium).

Hope that helps. I’ve been really impressed with lwjgl myself.

Thanks for your feedback!

You guys are claiming that it’s easy to migrate from J2D to LWJGL.

You guys are right to a certain point.

Some of the games mechanics will have to change due to the way OpenGL handles things such as coordinates and camera movement.

What problems are you actually having?

If you’re so inclined you can set up the coord system identical to Java2D (just shove the right params to glOrtho). Equally you can always ignore the matrices and camera stuff and just do things manually like you would for Java2D.

[quote]What problems are you actually having?

If you’re so inclined you can set up the coord system identical to Java2D (just shove the right params to glOrtho). Equally you can always ignore the matrices and camera stuff and just do things manually like you would for Java2D.
[/quote]
I do use a matrix under Java2D, the default matrix which I use as a camera and it centers on my player which moves through the world.

People that keep saying that you can setup a system like J2D with glOrtho have never actually said anythig more than that.

I’ve tried, I’ve failed.
I’ve looked at other people’s code, it doesn’t explain.

I get what the first 4 parameters do under glOrtho but no one has explained what the last 2 parameters do. Under GL docs those last 2 parameters in the glOrtho method are called “near” and “far”.

Great explanation isn’t it? That’s all I know because that’s all what the docs explain.
I’ve looked through the GL red book and couldn’t find an explanation either.

I’ve come to the conclusion that either vague explanations are good because everyone except myself can understand them, or everyone in the world is conspiring against me.

Take your pick.