9

Since Java supports OpenGL, what is the best option for developing a game?

  • Java + OpenGL
  • C++ + SDL + OpenGL

I always avoided Java (in game development, of course) because of it's speed. But, I discovered that Java supports OpenGL. So, I think speed can't be the problem anymore. What should you choose? Are there remarks?

Java would be a lot easier for me, because of my experiences in Java and the garbage collector.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
  • 17
    java isn't slow. java programmers write slow code. – Erik Mar 07 '11 at 16:20
  • The availability of a API binding to a language doesn't tell anything about the performance of the language's implementations. Also OpenGL is one of those APIs for which implementing a language binding faces little to no obstacles no matter what the language is. – datenwolf Mar 07 '11 at 16:58
  • 1
    @Erik java is slow. It doesn't have custom value types (only reference) that you could layout in memory consequently. As a result you cannot take meaningful advantage of processor caching when iterating over the objects. Cache misses incur significant slowdown – Coderino Javarino Aug 22 '19 at 05:35

8 Answers8

19

In my opinion, if you have an idea for a game in your head it doesn't matter what you write it with (at first), C/C++, Java, pen & paper... Pick the language you're more comfortable with, prototype and test your game idea, once you have a rough sketch and know what you need to do, throw the prototype out, design the gameplay & architecture and then start coding the actual thing. Don't optimize until after you've got most or all of the functionality working (in general, there's always minor bugs to hunt) and you actually see where the bottlenecks are.

I've seen it happen over and over again, game programmers are among the worst premature optimizers ever, trying to squeeze out a few cycles from something trivial, while missing the biggest bottlenecks and then optimize some more (in the wrong place). I've also found myself guilty of this many times. I'd say don't pick C++ (or Java for that matter) because of the speed, you can get very good performance out from both, if done "right". If need be, you can always switch to another language, if the language itself is really the bottleneck or really preventing you from doing something. Java isn't automatically slow and C++ isn't automatically fast, you can go (very) wrong with both. I used to root for C and C++ in everything, but after having worked with Java for quite a while, I really don't miss all the hassle that much.

There are lots of (already optimized and fairly easy to use) game engines available for both languages, so there's no need to roll your own... unless you really want to. In my experience, most hobbyist "game programmers" tend to be more interested in the technical side of things than in the actual game (myself included) ;) Once all the technical hurdles are done and you get that nice model/bunch of sprites/particle effects running with some shader-effects, the enthusiasm seems to fade away... But don't let me discourage you, game programming is very fun, even if you never actually finish anything (I wouldn't call any of my own projects finished).

I haven't coded any games for a while, but for C++ 2D SDL is a good candidate, other option could be SFML, or if you want a lower level touch with OpenGL, you could try going with GLFW + SOIL + some audio library. For full-blown 3D, I'd say try either OGRE or Irrlicht + Irrklang (there are probably loads of others too).

In Java, there's at least Slick2D, Golden T Game Engine and for lower level access, LWJGL (although I think you can access LWJGL via Slick2D also). For 3D, someone recommended jMonkeyEngine to me, but I've never tried it.

esaj
  • 15,875
  • 5
  • 38
  • 52
16

I would vote for C++ for the simple fact that you have a dependable destructor in your objects. This lets you wrap many of the OpenGL components (buffers, textures, etc.). You can know that when the object is created, the asset is allocated, and when the object is destroyed (or goes out of scope), the asset is cleaned up.

It certainly can be done in Java. Minecraft was made in Java, and it has pulled in over $25 million.

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58
  • But wasn't Minecraft re-written in C++ ? Something called the Bedrock Edition ? I don't know much about games (playing them, I mean) but I think we need to check which fetched more greenback, the C++ one or the Java one. A 2min googling showed me that Bedrock is for many platforms whereas Java one is only for PCs. Logically IMHO, Bedrock might have fetched more . – Aritro Shome May 28 '21 at 15:40
  • 1
    Well, yes. My answer is 10 years old. The world has changed, and my opinions have changed. – TheBuzzSaw May 29 '21 at 18:06
8

Java has been proven to be just as fast if not faster than C++, though granted, you don't achieve such results without a little parameter tweaking and careful monitoring of the garbage collector. If you want to pursue game design with Java, I'd say that's a good choice to make, provided you study up on how to approach it first.

Neil
  • 5,762
  • 24
  • 36
8

I'd go with C++, SDL, and OpenGL.. SDL is getting revamped with 1.3 at the moment, and it will be really good. In my opinion you should do it in C++ as you have stated you would feel more comfortable with Java, being comfortable after making a game in C++ would be very beneficial. You would not only make a game, but learn more at the same time.

Fouf
  • 551
  • 2
  • 4
  • 13
4

If you go down the Java route you may need to ship the JVM along with your game. That's not to say don't do it but many people may not have Java installed or not have a recent enough version for the features and performance that you want. I haven't looked into the licensing requirements for shipping the JVM but that's probably something you'll want to investigate before making the decision.

You should also be aware that when highly tuning an app that although the Java API is the same across platforms that there are differences because the implementations of those often use the underlying OS. So I doubt that using Java would reduce the test burden at all for a game.

Jeremy
  • 607
  • 4
  • 6
2

It really depends on what language your most used to. There's a steeper learning curve with c++ than with java. If you not into none of the languages, and is eager to get some development done I would recommend java.

And a little side note. If you totally new I would also recommend looking at XNA, but it's based on DirectX. And you have to know some C#.

DNRN
  • 2,397
  • 4
  • 30
  • 48
2

It really depends on what kind of games you want to build and which programming language your more comfortable with.

If your planning to make big games in the future , C++ is best for overall experience. Most commercial games are written in C/C++. Microsoft also has XNA framework which uses C#

Id still go with the programming language your more convenient with, they are both great

However, if you dont mind learning a bit more then go with C++

  • 1
    It's worth noting that most games are in C/C++ only because that's all there was for a long time. These days, a lot of games incorporate many different languages in them. They're using python and LUA for scripting, C++ or C# or Java for graphics and engine, most of them are using OpenGL or DirectX for interacting with the graphics card, where it doesn't really matter what language you're doing that in... – corsiKa Mar 07 '11 at 18:34
2

Well I've programmed all my games in SDL and I would definitely recommend using c++. Though you may want to look at SFML!

http://www.sfml-dev.org/

SFML is already integrated with OpenGL, and it's fairly easy to get up and running with game programming.

ultifinitus
  • 1,813
  • 2
  • 19
  • 32