Hacker News new | comments | show | ask | jobs | submit login
LWJGL: Lightweight Java Game Library 3 (lwjgl.org)
122 points by mabynogy on July 18, 2017 | hide | past | web | favorite | 62 comments



Writing Java game applets was what got me started in software development back in the late 90's. Game development in Java was always a huge challenge for several reasons; perceived (and real) slowness, slow startup, distribution, etc.... But putting a game in a web page anyone could play was really cool back then (to me at least). Lwjgl was always one of the marquee projects. The lack of value types[1] in Java has always been a hindrance, in particular when doing vector math calculations for physics simulations. And now all these years later, Java still doesn't have them. It's been many years since I've checked, but once there were several gifted indie game developers using Java, Notch being the biggest success story from that scene. Other than Minecraft, I've not heard of any popular games implemented in Java, has there been any?

[1] https://en.wikipedia.org/wiki/Project_Valhalla_(Java_languag...


Can't forget Runescape, especially since you mentioned putting a game in a web page anyone could play.


The coolest thing I ever did was bundle native libs for Linux, OSX and Windows in an applet, that let me access OpenGL in a Java applet years before WebGL was a thing. We had the technology to do real 3d-accelerated graphics in a type-safe jit-compiled language with a great IDE 15 years ago already.


It is good that it is now dead in the name of security.


Java is dead in the browser... same as flash, or c or any other language. At least until the nightmare that is WebAssembly comes to fruition.

That said... the potential to exploit security holes via GL library calls is, unfortunately, alive and well even with WebGL.


Flash isn't dead yet, through its dying for sure. The only positive thing of unfortunately likely EME is it may put another nail in the coffin.


It bet WebAssembly will bring all those plugins back to life.


How would WebAssembly ever do that?


Easy, it is just a matter of creating a compiler backend for Java, Flash, Silverlight that target WebAssembly instead of their original bytecodes, then bundle it with their own runtime compiled via emscripten.

There are already a few projects doing exactly that.

One could even create a ActiveX compliant library, that via emscripten would be able to target WebAssembly.


This probably does not qualify as "popular game", but talking about Java games I'd like to mention Terasology (https://github.com/MovingBlocks/Terasology). It's an open source voxel game (Minecraft-like) and the LWJGL-based graphics engine looks very impressive to me (some screenshots here: http://terasology.org/gallery.html).


It also performs horribly on a modern Windows PC with a 1070 (wanting to make sure I'm not slandering the game, just double checked with reduced settings, still barely runs). That performance (along with Mincraft's) convinced me personally the JVM isn't a place you want to build a game like that.


The main reason for those game very poor performance is mainly that they rolled out their own 3d engine.

Having programmed several 3d engine, I can say it's really simple to program a 3d engine but it's really hard and time consuming to program one that has reasonnable performance.

Minecraft was especially bad because it used very old version of OpenGL (the 1.5 - 2.0 OpenGL with fixed pipeline) which is really not adapted to modern GPU.


Java, not the jvm may be the issue here. Look at the X10 language for example, which focuses more on array, parallel and numerical performance, but is on the jvm. The issue with Java for voxels is that Java does not have fortran arrays. It because nested objects, so that will give a lot of performance hits for a game built entirely on ndimensional arrays.


That's pretty true for stuff like that you want to use sideways arrays typically, where you decompose the fields in your object to each be in their own array (and sometimes recursively if the fields are themselves objects). With that and avoiding allocation (aka cache invalidation / garbage generation) at all costs you can get things fast.


The java ecosystem offers annotation driven bytecode mangling/generation tools for all kinds of stuff, is there something for "sideways arrays"? The compiler plugin model used by immutables.org (generate a bunch of implementations for the fields implied by an interface) could hopefully make that relatively painless to work with.


It has more to do with the quality of the programmers than with Java.

Actually Java and the JVM are the heroes here, because the guys that took over after Notch, just wrote shitty code allocating several hundred MB per second on the game loop.

Also the majority of Mincraft plugins are written by kids, whose understanding about how to write game code is nonexistent.


Yup. You can write very, very tight code without too much work using Java (I mean, look at financial companies). The programmers working on Minecraft, including Notch, were grinders, and it shows. That's not a criticism of the product; they shipped. But they never really dug out of that hole.


You don't think it has anything to do with the abstraction and indirection levels that java operates at? Where are these well coded java games that look like something from this decade?


Good Java programmers are better payed to write High Performance Trading systems, than working on games with their low salaries and crazy schedules.

Yes, there are some performance issues regarding lack of value types, but not every single game is going to be the next Crysis.

Yet it appears by some in the game community that if language X cannot be used for doing Crysis than it is not worth it, let alone that most likely they will never finish their game.

Unity's runtime is a fossilized version of Mono, with much more performance issues than OpenJDK, yet indies flock to them.

Only because they are deeply committed "to all or nothing", in what concerns advancing the status of doing game development in .NET. Since they created their own AOT compiler (IL2CPP) they have even started to port sub-components from C++ to C#.


I've noted this to be true in regards to salary. I've been writing high-performance Java code since years (chewing a few trillion computer files as fast as possible) and we certainly would have switched to anything else such as C++ if it was faster.

Our internal performance testing is ranking Java on par with the C++ implementations of the same algorithm (performance typically flattens until a bottleneck is reached such as disk read speed) or completing the same tasks faster. In one side this is due to the JVM optimizations done automatically, the other side is having developers that understand how to write efficient code. This does require an experienced developer which understands how his code is impacting performance.

For example, avoiding ArrayLists or String objects and learning to use direct arrays or char objects. I can see LWJGL being useful, most particularly to help keep the infrastructure under the same language so that development and long-term maintenance are not a nightmare.


Unity 2017.1 includes an updated version of Mono supporting .NET 4.6. Still experimental at the moment, but coming out of the deep freeze that it has been in for a while.


> Good Java programmers are better payed to write High Performance Trading systems, than working on games with their low salaries and crazy schedules.

So do good c/c++ programmers, especially now that it's increasingly rarely taught in university and there is less fresh meat coming into the industry, yet games still get made.

> Yes, there are some performance issues regarding lack of value types, but not every single game is going to be the next Crysis.

It's not just value types, it's reference indirection everywhere. You can't declare an array of objects for example, only an array of references to objects, which isn't cache friendly. There are similar issues if you want to actually use many of the features higher level languages come with. It's why java/c# will never be as fast as c.

As far as unity goes, all the heavy lifting in the game engine is still done in c/c++, c# is only used as a scripting language. As far as I understand LWJGL, it is not analogous to unity, it's not a game engine but a low level library to write a game engine with.


> It's why java/c# will never be as fast as c.

C# has value types, added local references and reference returns on C# 7, and they will be adding more features from System C# (Midori) in the 7.1, 7.2 and 8.0 releases.

https://github.com/dotnet/roslyn/blob/master/docs/Language%2...

Microsoft recently did an interview where they admitted they only cared to make their native code compilers for .NET "good enough" and are now planning on changing that.

https://www.infoq.com/articles/high-performance-dotnet

Also .NET Native actually makes use of the same backend as Visual C++.

Java is not yet there with value types, but in about 5 years time, Java 10 will be here with them. They are also available in prototype form today for anyone that wants to play with them.

I wrote my first games on a Timex 2068, since then I have witness and took part in many variations of this subject.

Started with, no serious game programmer would use anything other than Assembly. C, Pascal, Basic, Modula-2 lack the register control, memory layouts, instruction count, ability to self modifying code that Assembly allows for.

Followed by, no serious game programmer would use anything other than C or Pascal. C++ adds too much bloat to make any game worthwhile playing.

Now he are on, no serious game programmer would use anything other than C or C++. Java, C# and other type safe languages will never perform as good as C and C++.

Fact is that the majority of games I see on the stores aren't really AAA pushing the hardware limit, many of which have graphics and gameplay that could have been done with AMOS on an Amiga 500 and people would hardly notice.

> As far as unity goes, all the heavy lifting in the game engine is still done in c/c++, c# is only used as a scripting language

Since IL2CPP got mature some of that C++ code is actually C# code. If you pay attention to the Unite 2016 and 2017 keynotes they are rewriting the not so performance critical components from C++ to C#.

Finally the programming language compilers that come with the games consoles and OS SDKs also play a big role, and games developers tend to stick with what they get with the SDKs.


> I wrote my first games on a Timex 2068, since then I have witness and took part in many variations of this subject.

Ever play text adventures? Even back then a lot of non-critical code was written in higher level scripting languages. I'll even go out on a limb and assume you know what the AGI engine is.

> Followed by, no serious game programmer would use anything other than C or Pascal. C++ adds too much bloat to make any game worthwhile playing.

We haven't moved beyond this point AFAIK, most games will use either c or the zero cost parts of c++ for the core engine.

> Java, C# and other type safe languages will never perform as good as C and C++.

For 20 years now I've been hearing java will match the speed of c one day, yet I'm still waiting. Fool me once shame on you...


> Ever play text adventures?

Lots of them, they were quite common on the Iberian peninsula. Many of them used PAWS.

http://www.worldofspectrum.org/infoseekid.cgi?id=0006825

> For 20 years now I've been hearing java will match the speed of c one day, yet I'm still waiting. Fool me once shame on you..

Just like C will never match the speed of Assembly and people are pretty ok with it. Also C compiled without UB optimization tricks isn't that fast.

C had 40 years of compiler optimizations, so Java still has 20 years to catch up, back in the 8 and 16 bit days junior Assembly coders could write better code than C compilers would generate.

For most people being a few ms slower doesn't matter at all, specially if they aren't playing Crysis, Battlefield or any other AAA game.


The guys that took over after Notch are Microsoft.


No you are skipping the part between Notch stop coding Minecraft, the company hiring new developers and only a couple of years later being bought by Microsoft.

Microsoft's first decision was to port everything into C++, which they finished doing this year.


Didn't realise they had ported it to C++. Looks like they did that to target iOS.


There are still a number of indie devs using Java, as far as I can tell the vast majority using LWJGL. When game jams come around I'll play maybe 100 games that other participants made, and a small but respectable chunk will be JAR files (maybe 10 of those 100?).

It might even be the second most popular way to make indie games, after Unity. Depends on how you count "indie" games.


Starsector is quite performant Java-based 2d space merchant sim. It shows a lot of visual effects and does a lot of processing in the background.


lack of value types makes many games a pain in the ass to do performantly.

basically anyone thinking they might want to use Java could use Monogame instead and have a much better time.


I've used both libgdx/LWJGL and MonoGame extensively. They're both fine. MonoGame has its own set of problems (a byzantine build systems, spotty platform support, etc.).

Practically, not having value types is not really the kind of problem you'd expect it to be. Cache coherence with something like Mono or the JVM is less of a priority (nice-to-have but let's be real here) and a bunch of arrays of primitives looks uglier than C# structs but it mostly comes out in the wash.


Now that the JVM is a multi-programming language platform, I hope things like this become more popular.

Kotlin, Frege, Clojure, Fantom, Ceylon, JRuby, etc. There's a language for everyone. So building more value into the JVM with projects like that would be really great.

The JVM is probably the most advance VM currently, and hopefully it'll just keep getting better, maybe faster startups with the new module system, hopefully in java 9 they add value types, etc. All to say, I think more people should look into the JVM as a platform for the future.


Start up time isn't that bad for the jvm itself. A small clojure app starts up in no time. Java itself has a large library that is included in every application now. Jigsaw should alleviate this though.

I would also add as an aside is that most production Java applications are rather large, with several large dependencies.


I'm not sure the JVM is the most advanced. the CLR has parity for the vast majority of JVM features and has historically had the jump on the JVM with generics, async etc


You're talking about Java I think, as generics and async are language features. I'm talking about the JVM. As far as I know, the performance and portability is unmatched.

That said, reified generics I think are a limit of the JVM bytecode. But type erasure has its own advantages over reification. So one is not clearly better then the other, just offers a different set of trade offs.


More popular? It's already used in the second most popular video game of all time.


Minecraft?


Is anyone really using Ceylon? I really like the look of it, but it just feels like something thats not really going to get much traction


co-sign 100%...we are trying to make that polyglot dream a reality with Solvent (codesolvent.com)...using JSR-223 to allow multiple languages to be used for building web apps...you can see demo videos here: http://codesolvent.com/web-dev/


JSR-223 is nothing, compared to what will come with Graal and Truffle. Also since indy and lmf you can already create a lot of fast implementations for a huge set of languages.


> hopefully in java 9 they add value types

Won't happen in 9. The way it currently looks like there will be a experimental support on the VM-level in 10 and language level support no earlier than 11.


For any unfamiliar, this is the library Minecraft was originally built on. I've used it to develop some graphically intensive programming tools myself, and have always been pleased.


We've all heard the poor story with Java in regards to performance, and the arguments for/against it, so I'm not going to dwell on that. A significant amount of work is being done on the GPU now more than ever anyway.

At least in my experience, I've had a great deal of fun working with LWJGL and it is a pleasure to use. It's very unopinionated and doesn't try to force you into any sort of specific structure. On top of that, Java + LWJGL hide a significant portion of the cross-platform mess that you inherently see in this field. No matter where you stand on the issue, setting up a project to build and run cross platform, and managing its dependencies is a pain point in C/C++. Add a trivial maven configuration once and you're good to go the majority of the time. Having a mature package manager is also something that you shouldn't ignore.

No one should shy away from writing a game if all they're familiar with is Java/some JVM language. It's a gradient between choosing the right tool for the job and premature optimization. Here's a video of what looks to be a dead project, but still serves as a decent tech demo of a nice looking game running on the JVM https://www.youtube.com/watch?v=eM_bABrFERs .


I got into software development through a LWJGL project, and it changed my life.


Serious? If so I'd love to hear the story.


I had a crazy idea re: a multiplayer roguelike engine that would be scriptable. It was a pipe-dream, mostly due to my skill level, and I abandoned it after using it as a hobby for roughly 3 years when it became clear it needed a massive rewrite. However attempting it taught me an insane amount OOP and modern development practices. The Java client rendered with LWJGL, and it was very easy to start playing with basic concepts for graphics and voxel worlds. Without the ease of LWJGL the project wouldn't have taken off at all.

I went from doing general IT to being a professional software developer, and the first thing I ever starting coding was that engine.


Is there any good books or tutorials on how to get started in games development? I would love to take it as a hobby but the tutorial scene is so saturated I find it hard to cut through the chaff, so it would be nice if someone from this community could recommended a good starting place.


handmade hero. https://handmadehero.org/


I wouldn't recommend handmade hero, especially to someone who's just getting started. First two weeks of handmade hero could be skipped by just using SDL, rather than rolling out Windows specific windowing, rendering and audio.


I found the Unity-Tutorials from https://unity3d.com/de/learn/tutorials very insightful. They provide a nice starting point. Plus Unity has a big asset-store, which is handy especially if you're on your own.

A bit simpler and great for getting started is Construct3, which is a HTML5-Game-Editor which runs in the browser. They did a great job with the App. https://www.construct.net/


Great library, particularly for beginners who have done a Java 101 course. But why is it being posted now?


Because version 3 just got released.


Has it not been a while?


A year ago.


Java 101? It seems to require knowledge of 3D math and OpenGL.


Is there a way to use LWJGL for mobile games?


Absolutely. A somewhat higher level library building on lwjgl (2) called libgdx has good documentation and examples on it - The Google Pixel live wallpapers (3D models of places, with some parallax effect) are written using it. There is also a framework called flixel building on top of libgdx, which also has demos for Android.


I think Ingress (by Niantic Labs) is a more prominent project using LibGDX


You would want to use LibGDX which allows you to develop for mobile using a LWJGL backend (if you feel like it) and then simply publishing to Android or iOS.


I've been using LibGDX for a small little thing, and honestly can't recommend it. I had the app for a few years, and whenever I wanted to update things after a few months, so many things would just break. Be it the build-system, the APIs, RoboVM or some randoms project settings - it was always a headache to get it running again. When RoboVM shut down, there wasn't even any clear way to get it running on iOS again for a while, leaving me with an undeployable app.

If you're investing into anything serious, I would strongly recommend going with Unity over this.


Worth checking out LibGDX if you're i to Java game dev also.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: