Why should I use a Game-Engine like lwjgl or libgdx instead of Swing?

Hey Guys,

I’m new in the game delevopment with java. And now I want to learn more about Game Engines.
Until now, I only heard of Swing. Than I found out, that there are more game engines like lwjgl, libgdx, etc.

Now my problem:
Why should I use lwjgl or something like this? What makes it “better” (better is a bad word for it I think).
And whats the difference about lwjgl / libgdx? Where are the pros and cons?

Hope you can help me there. Please don’t link me to the homepages of the Engines… Yes, there are informations about it… But only generally information, but I want to get a little deeper.
Thanks for help!!

greetz…

LWJGL - Light Weight Java Game Library. Not an engine. LWJGL contains these things - OpenGL binding, OpenAL, Keyboard, Mouse, Controller input and some more ‘tiny’ features. I guess you could say the backbone of the game.
LibGDX is a game framework. It isn’t an engine. It is like LWJGL, but has some higher level features and some more really awesome stuff.

You cannot make 3d games in swing. You can only make really simple 2d games in swing. The reason is performance. opengl is just plain faster…

@SnowOwl

A hearty welcome to the forum. First of all, it’s not impossible to do a game engine in swing, I’ve made one and the author of the book “Game Development in Java”, David Brackeen had even made a 3D engine using just swing. But the main reason is performance.

Swing is designed to be a UI toolkit rather than a library to build games upon. To get the good advantage of graphics card, we need some driver level libraries like OpenGL or DirectX. LWJGL is a java wrapper for OpenGL for graphics and OpenAL for audio along with OpenCL and is not a game engine. LibGdx is a game engine which uses LWJGL as one of it’s backends to run on desktop.

And once again, welcome to the forum.

Though what you’re saying is generally correct, I find this quite misleading. First off, it’s possible to create 3D games in Swing, though impractically difficult. Also, you cannot directly compare the speed of OpenGL and Swing. OpenGL is a low level graphics specification, however Swing is a high-level graphics API.

Op: LWJGL contains an OpenGL binding which allows you to take advantage of the speed of the GPU, by manipulating data at a low level. Doing so allows you to optimise the handling of data to increase the performance of your game. It also makes 3D graphics programming much easier than if you were to have to do it in Swing for many reasons which I can’t be bothered to go into. LibGDX on the other hand is a mid level framework which hides most of the low level code. It is based on OpenGL ES which allows you to develop multi-platform games which work on Desktop, Android and iOS.

Depends on the game you want to make. If you want a simple game, a turn based game or a game with heavy gui, you should go with Swing. I was making this game without external libraries. I had good performance with multiple layers, big scrollable map, collision detection, animated tiles, etc.
Also swing is good to practice in your first projects. Just my opinion. :wink:

@ricardo thanks for your opinion. I still made a game with Swing (The game is called Coloretto - it’s a card game).
And now I’m searching for other ways to develope games. It should be a 2D game for the first. But maybe I want to switch to 3D later.

@SHC and Troubleshoots.
First of all: Thank you!

But now I have more questions.

  1. LWJGL uses OpenGL (for the graphic) and OpenAL ( for the sound). But what is OpenCL for?
  2. Is the only difference between OpenGL and OpenGL ES that OpenGL ES allows you to develop multi-platform games?
  3. Is there a lifecycle how you can show how LWJGL works? (If not, doesnt matter)

Greetz… :slight_smile:

For 2D games there are lots of options… the only real answer is use what works for you.

When talking about lwjgl and libgdx the real trade off is they are wrappers exposing opengl to your java code. If your game will not benefit from opengl then there may not be a compelling reason to use these. On the other had these are both libraries suited to game development and opengl will provide high performance graphics, but they will be harder to work with then pure swing for very basic tasks like making buttons.

OpenCL stands for Open Computing Language which allows you to write programs that are executed by your GPU instead of the CPU. This increases a lot of speed since GPUs are more capable than the CPUs.

No no, you misunderstood the terms OpenGL and OpenGL ES. The former is Open Graphics Library and is a low level specification that interfaces the graphics card. The latter is Open Graphics Library for Embedded Systems. It is a subset of the OpenGL for rendering 2D and 3D computer graphics such as those used by video games, typically hardware-accelerated using a graphics processing unit. It is designed for embedded systems like smartphones, computer tablets, video game consoles and PDAs.

LWJGL basically works by using JNI code to wrap the native libraries and make them available for java. OpenGL is actually a C specification, so LWJGL requires the use of JNI. If you want to learn more about LWJGL, checkout my tutorial series here.

LWJGL Tutorial Series - Contents

Hope this clarifies your doubts.

LWJGL is not a game engine, it’s just a set of libraries.

Why use it? It can do some things that Swing can’t do. It can do some things more efficiently than Swing does them. If you need that, use it. If you don’t, let it be.

A game engine is one level higher than LWJGL though. It’s a framework where you just plug in your functionality.

Ricardo, using Swing is a waste of time when developing games. I would never recommend anyone beyond a new programmer to use Swing because eventually you will have to touch some low level graphics API like OpenGL or DirectX. Why should I spend my time learning a useless API (for game development, Swing is good for other stuff) when I’ll have to learn OpenGL anyway? Swing is easier, yes, but that is no reason to not learn OpenGL. Its just laziness.

[quote=“SnowOwl,post:1,topic:47231”]
When you’re new to Java, you could like the new JavaFX multi-media library, which is part of Java 8 (being released this month). It’s meant as an alternative to or rather successor of Swing, actually. SUN’s Swing veteran Richard Blair is also a key architect in the Fx library.

In contrast to the older Java2D (which you probably mean when you say Swing), the Fx library provides true hardware accelerated 2D and 3D with an easy to learn but solid scene-graph “engine”, also suited for casual games.

I’ve just recently mentioned it here in the other thread: Libraries vs. Pure Java

Maybe you should have looked at existing topics about LibGDX and Swing… LibGDX has several backends, one of them is based on JGLFW, another one is based on LWJGL, another one is based on JogAmp (JOGL, JOAL, JOCL)… LibGDX is a middle level framework, JogAmp and LWJGL are 2 sets of (low level) bindings. I wouldn’t use Swing for games even though GLG2D allows to get a better hardware acceleration with it, except for extremely rudimentary games.