{"id":8412,"date":"2013-01-09T14:50:14","date_gmt":"2013-01-09T19:50:14","guid":{"rendered":"https:\/\/www.spacesector.com\/blog\/?p=8412"},"modified":"2013-05-03T09:30:11","modified_gmt":"2013-05-03T13:30:11","slug":"making-a-space-4x-game-an-overview-on-graphics-libraries","status":"publish","type":"post","link":"https:\/\/www.spacesector.com\/blog\/2013\/01\/making-a-space-4x-game-an-overview-on-graphics-libraries\/","title":{"rendered":"Making a Space 4X Game: An Overview on Graphics Libraries"},"content":{"rendered":"<p>For my next article, I am going to talk about graphics libraries. This article strays away from the development of my game a bit \u2013 some of the previous comments had questions about graphics. So I decided to write a more generalized entry. My <a  href=\"https:\/\/www.spacesector.com\/blog\/2012\/12\/making-a-space-4x-game-setting-the-stage\/\" target=\"_blank\">first article<\/a>\u00a0covered the basics of developing a space 4X game &#8211; what I called &#8220;setting the stage&#8221;. My next article is going to be about the Empires\/Races, so it will be purely on the game&#8217;s development.<\/p>\n<p>Before I begin, I want to take a brief moment to thank you all for reading and commenting on my first article. I had a lot of fun writing it, and it looks like the readers had fun reading it.<\/p>\n<p><a  href=\"http:\/\/www.opengl.org\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8413 aligncenter\" title=\"opengl\" src=\"https:\/\/www.spacesector.com\/blog\/wp-content\/uploads\/opengl.jpg\" alt=\"\" width=\"220\" height=\"97\" \/><\/a><\/p>\n<h3>Graphics Libraries<\/h3>\n<p>First off, what is a graphics library? In simplest terms, it is a collection of APIs (application programmer interfaces) that allows a programmer to gain access to graphical operations for the display.<\/p>\n<p>The two most well known libraries are: OpenGL (multi-platform) and DirectX (Windows\/Microsoft platforms). These libraries can be used by different programming languages. The exact languages supported vary.<\/p>\n<p>There can be wrapper libraries that sit on top of the graphic library and can make it easier to use the graphical APIs. The benefit of this is that it makes writing graphical code a lot easier. This is due to the fact the wrapper can present easy to use ways for complex activities. An example is, in OpenGL, one would have to manually write code to draw a rectangle(complex). But if a wrapper existed called drawRect(x, y, width, height), it&#8217;d be easy to draw rectangle.<\/p>\n<p>OpenGL <a  href=\"http:\/\/en.wikipedia.org\/wiki\/Java_OpenGL\" target=\"_blank\">example<\/a>:<\/p>\n<blockquote><p>\/\/ Draw A Quad<br \/>\ngl.glBegin(GL2.GL_QUADS);<br \/>\ngl.glColor3f(0.0f, 1.0f, 1.0f); \/\/ set the color of the quad<br \/>\ngl.glVertex3f(-1.0f, 1.0f, 0.0f); \/\/ Top Left<br \/>\ngl.glVertex3f( 1.0f, 1.0f, 0.0f); \/\/ Top Right<br \/>\ngl.glVertex3f( 1.0f,-1.0f, 0.0f); \/\/ Bottom Right<br \/>\ngl.glVertex3f(-1.0f,-1.0f, 0.0f); \/\/ Bottom Left<br \/>\n\/\/ Done Drawing The Quad<br \/>\ngl.glEnd();<br \/>\nSimple wrapper example:<br \/>\ng.drawRect(0, 0, 100, 100); \/\/Draw a rectangle at position (0,0) and the size is 100&#215;100 pixels)<\/p><\/blockquote>\n<p>It should be fairly clear which would be easier to use!<\/p>\n<p>Now, the exact nature and functionality of these wrappers vary. They are all different. So the documentation would need to be referenced.<\/p>\n<h3>Wrapper Libraries<\/h3>\n<p>I have not tried to write an OpenGL or DirectX program in any other language than Java, so my knowledge here is limited. I&#8217;ve done a bit of research and found some wrapper libraries. Maybe some of the readers can chime in on some good ones.<\/p>\n<p><strong><a  href=\"http:\/\/www.sfml-dev.org\/index.php\" target=\"_blank\">Simple and Fast Media Library<\/a><\/strong><\/p>\n<p>From their website: \u201cWelcome to the SFML official website.\u00a0SFML is a free multimedia C++ API that provides you low and high level access to graphics, input, audio, etc.\u201d.<\/p>\n<p><strong><a  href=\"http:\/\/www.libsdl.org\/\" target=\"_blank\">Simple Directmedia Layer<\/a><\/strong><\/p>\n<p>From their website: &#8220;Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of &#8220;Civilization: Call To Power.&#8221;.<\/p>\n<p>SDL is written in C and supports other languages, such as C++.<\/p>\n<p style=\"text-align: center;\"><a  href=\"http:\/\/www.slick2d.org\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8414 aligncenter\" title=\"slick2D\" src=\"https:\/\/www.spacesector.com\/blog\/wp-content\/uploads\/slick2D.png\" alt=\"\" width=\"313\" height=\"92\" srcset=\"https:\/\/www.spacesector.com\/blog\/wp-content\/uploads\/slick2D.png 313w, https:\/\/www.spacesector.com\/blog\/wp-content\/uploads\/slick2D-300x88.png 300w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><\/a><\/p>\n<h3>Wrapper Libraries for Java<\/h3>\n<p>I&#8217;m more familiar with Java so I am going to talk about these wrapper libraries in more detail. There are a lot of different libraries available for use but here are some of them:<\/p>\n<p><strong><a  href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/2d\/index.html\" target=\"_blank\">Java 2D<\/a><\/strong><\/p>\n<p>This is the standard graphical rendering library for 2D graphics in the Java SDK. It is written and maintained by Oracle. Java 2D is mostly software rendering, but hardware acceleration can be turned on (usually Direct3D).<\/p>\n<p>Java 2D should not be used for game development for it has awful performance. Java2D does have very accurate geometric shapes (rectangles, polygons, ellipses and so on), rendering capabilities (consistent drawing of shapes\/lines regardless of hardware), lots of good documentation and fairly easy to learn. If you want to read more about Java 2D, see <a  href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/2d\/index.html\" target=\"_blank\">this site<\/a>.<\/p>\n<p><strong><a  href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/tech\/index-jsp-138252.html\" target=\"_blank\">Java 3D<\/a><\/strong><\/p>\n<p>I have not used Java 3D at all so I&#8217;m not going to talk about it. It is also maintained by Oracle. You can find project&#8217;s website <a  href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/tech\/index-jsp-138252.html\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong><a  href=\"http:\/\/www.lwjgl.org\/\" target=\"_blank\">LWJGL<\/a><\/strong><\/p>\n<p>This stands for Light Weight Java Game Library. LWJGL allows a Java program to gain access to OpenGL via the native interface. This means \u2013 yes \u2013 your Java programs can now use OpenGL! LWJGL is very popular and is used across many different libraries\/wrappers.<\/p>\n<p>A word of caution, this allows for low-level use of OpenGL and it can be complex to learn\/use. I personally don&#8217;t use it because I am not an OpenGL programmer (not yet). However, this is easily remedied by the next library. LWJGL&#8217;s website can be found <a  href=\"http:\/\/www.lwjgl.org\/\" target=\"_blank\">here<\/a>.\u00a0It has a very active community and development is still going on.<\/p>\n<p><strong><a  href=\"http:\/\/libgdx.badlogicgames.com\/\" target=\"_blank\">LibGDX<\/a><\/strong><\/p>\n<p>This graphics library is backed by LWJGL. It is capable of supporting both 2D and 3D games, as well as multiple platforms such as Android. It has an active community, and has many complex OpenGL features present within. It&#8217;s website can be found <a  href=\"http:\/\/libgdx.badlogicgames.com\/\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong><a  href=\"http:\/\/www.slick2d.org\/\" target=\"_blank\">Slick2D<\/a><\/strong><\/p>\n<p>Slick2D is a library backed by LWJGL, like LibGDX. Its main goal is to present a series of APIs that look very similar to Java 2D (in other words, the functionality and way you type the code is similar). But the difference is \u2013 Slick2D is significantly faster than Java 2D. This is because Slick2D uses OpenGL, while Java 2D mostly does software rendering.<\/p>\n<p>Slick2D is very easy to learn if you know Java 2D, or basic graphics programming in general. Its development is fairly active and has a good community (I post on their site). The source is open, and anyone can contribute (I have contributed some code). Finally, Slick2D also allows for easy integration of sound and music files.<\/p>\n<p>Their site can be found <a  href=\"http:\/\/www.slick2d.org\/\" target=\"_blank\">here<\/a>.<\/p>\n<p>They also have a very useful wiki located <a  href=\"http:\/\/www.slick2d.org\/wiki\/index.php\/Main_Page\" target=\"_blank\">here<\/a>.<\/p>\n<p>Slick2D is what I am currently using for my game. The reason for this is because my previous game, SpaceIT, was unfortunately, written in Java 2D. And as mentioned before, due to a host of reasons, which included performance, I needed to switch to something else. Slick2D made sense for me because of it&#8217;s similarity to the Java 2D APIs. This meant that I could quickly get coding and do a conversion of sorts with little time wasted learning something new. This proved to be correct, I was able to quickly get started with a small learning curve.<\/p>\n<p>Previously, I was barely able to run SpaceIT using 30 FPS in Java 2D (using hardware acceleration). With Slick2D, on a huge game, I am easily in the hundreds (~200-500 depending on zoom level), and after I do optimization, I may be able to get close to 750 FPS.<\/p>\n<p>Now, I&#8217;m no graphics expert, and I can&#8217;t really recommend what would suit your project. But I have had great performance and much progress with using LWJGL and Slick 2D. Though LibGDX may be the way to go if you want to use more complex features of OpenGL and\/or deploy on Android. I also have not investigated the possibility of using DirectX through Java. I wanted multi-platform so that wasn\u2019t an option for me.<\/p>\n<p><a  href=\"http:\/\/twl.l33tlabs.org\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8415 aligncenter\" title=\"twl\" src=\"https:\/\/www.spacesector.com\/blog\/wp-content\/uploads\/twl.png\" alt=\"\" width=\"256\" height=\"128\" \/><\/a><\/p>\n<h3>GUI Libraries<\/h3>\n<p>The next part, which I am going to talk about is the GUI Library. This type of library consists of the widgets\/components that are displayed to the user. So functionality exists for things such as labels, tables, panels, windows and so on.<\/p>\n<p>A GUI library can be bound close to a graphic&#8217;s library. For example, Swing (never use Swing for a game), is bound tightly to Java 2D.<\/p>\n<p>There are a few GUI libraries out there that can be used with LWGJL, one being Nifty-GUI and the another being TWL. There could be more, but I haven&#8217;t investigated any others.<\/p>\n<p><strong><a  href=\"http:\/\/qt.digia.com\/\" target=\"_blank\">QT<\/a><\/strong><\/p>\n<p>QT is a library that is quite popular and powerful. It uses C++ but has bindings for other languages. The Wikipedia page goes into <a  href=\"http:\/\/en.wikipedia.org\/wiki\/Qt_%28framework%29\" target=\"_blank\">great detail<\/a> about QT.\u00a0And their main website can be found <a  href=\"http:\/\/qt.digia.com\/\" target=\"_blank\">here<\/a>.<\/p>\n<p>I used QT while in graduate school for a little program to display my results from my detail router. It was fairly easy to install, use, and then program for.<\/p>\n<p><strong><a  href=\"http:\/\/nifty-gui.lessvoid.com\/\" target=\"_blank\">Nifty-GUI<\/a><\/strong><\/p>\n<p>Nifty-GUI is backed by LWJGL, and uses XML in order to perform it&#8217;s configuration (though this is optional). It is quite powerful and looks really nifty. As with the other projects, this is actively being developed.<\/p>\n<p>Some demos can be found <a  href=\"http:\/\/nifty-gui.lessvoid.com\/archives\/427\" target=\"_blank\">here<\/a>.<\/p>\n<p>The main site is found <a  href=\"http:\/\/nifty-gui.lessvoid.com\/\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong><a  href=\"http:\/\/twl.l33tlabs.org\/\" target=\"_blank\">TWL<\/a><\/strong><\/p>\n<p>TWL stands for Themable Widget Library. This library uses LWGJL and can easily intrastate into Slick2D. It also is very powerful in terms of controlling the look and feel of the components through XML. You still have to write code to use the components\/widgets, but there is very little look and feel code. It is all defined in the XML. The XML (or theme file) is extremely powerful. It is significantly easier to use than Swing after you get over the initial learning curve. The author, MatthiasM, also actively supports it. This can be used with Slick2D. The website can be found <a  href=\"http:\/\/twl.l33tlabs.org\/\" target=\"_blank\">here<\/a>.<\/p>\n<p>I am currently using TWL for my UI. I selected TWL because it had good support for heavy components \u2013 I would need to display quite a few tables, trees, windows filled with many labels and so on. It also integrated nicely into Slick. I had a requirement of doing lots of Slick drawing on components and TWL can easily support that.<\/p>\n<p>There were a few hiccups along the way, but MatthiasM, has been very responsive and helpful in my questions and feature requests. TWL is easy to use and write code for (compared to Swing), and it works with very little bugs and issues. In particular, Swing, would behave oddly at times for no apparent reasons. TWL on the other hand, has been very consistent and I&#8217;m pleased. In addition, TWL has great performance.<\/p>\n<h3>Conclusion<\/h3>\n<p>Well, this pretty much wraps up what I wanted to say for this article, which was to give a brief overview of some of the Graphic and GUI libraries that I know and have used before.<\/p>\n<p>Hopefully, you have found this an interesting article and helpful in some way. I know I have made some generalizations which may not hold true for everything &#8211; there are always special and unique cases. But I had to or otherwise this article would be 50 pages and no one would read it :)<\/p>\n<p>I can&#8217;t tell you what libraries to use \u2013 only you can with proper investigation and requirements for your game. Also, there is a learning curve to everything \u2013 it will take time to learn to use these libraries and APIs.<\/p>\n<p>Thanks for reading and I look forward to your comments!<\/p>\n<p><em><span style=\"color: #227dc2;\">dayrinni has been a Space Sector contributor since October 2011. This is his first foray into writing articles for any review site. He is an avid gamer in the genres of 4X, Strategy, MMO&#8217;s and RPGs. Finally, he has been the implementor of several MUDs and is currently working on a space 4X game that offers large scope and complexity. See all dayrinni&#8217;s posts <a  style=\"color: #7a1a99;\" title=\"dayrinni's posts\" href=\"https:\/\/www.spacesector.com\/blog\/tag\/dayrinni\/\" target=\"_blank\">here<\/a>. In particular, check his <a  style=\"color: #7a1a99;\" href=\"https:\/\/www.spacesector.com\/blog\/tag\/what-makes-a-good-game\/\" target=\"_blank\">&#8220;what makes a good game&#8221;<\/a> and <a  style=\"color: #7a1a99;\" href=\"https:\/\/www.spacesector.com\/blog\/tag\/making-a-space-4x-game\/\" target=\"_blank\">&#8220;making a space 4X game&#8221;<\/a> series.<\/span><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article gives a brief overview on some of the Graphic and GUI libraries that I know and have used before to develop my games.<\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"registered_only","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[177,1],"tags":[1502,373,1173],"class_list":["post-8412","post","type-post","status-publish","format-standard","hentry","category-game-design","category-space-strategy-games","tag-game-design","tag-game-development","tag-making-a-space-4x-game"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/posts\/8412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/comments?post=8412"}],"version-history":[{"count":0,"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/posts\/8412\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/media?parent=8412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/categories?post=8412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spacesector.com\/blog\/wp-json\/wp\/v2\/tags?post=8412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}