{"id":549,"date":"2014-03-01T19:36:50","date_gmt":"2014-03-01T19:36:50","guid":{"rendered":"http:\/\/www.knightsgame.org.uk\/blog\/?p=549"},"modified":"2014-03-01T19:36:50","modified_gmt":"2014-03-01T19:36:50","slug":"investigating-sfml-for-graphics","status":"publish","type":"post","link":"https:\/\/www.knightsgame.org.uk\/blog\/2014\/03\/01\/investigating-sfml-for-graphics\/","title":{"rendered":"Investigating SFML for graphics&#8230;"},"content":{"rendered":"<p>So, recently I bought a new laptop. And with it being a new year and all, I thought this might be a good opportunity to get back to some Knights development (something that, sadly, I haven&#8217;t had much time for these last few months). So, I installed the latest Visual Studio onto the laptop, set up the Knights code directory, and prepared to do some coding&#8230;<\/p>\n<p>&#8230; and immediately hit a problem. The game would not build. Partly this was because the Microsoft compiler now supports C++11 (the latest version of the C++ language), which caused a few incompatibilities with my code (admittedly this was mostly my fault though!). And partly it was because Microsoft have changed the way DirectX works &#8211; in particular, &#8220;D3DX&#8221; is no longer a supported technology. Unfortunately for me, I had some code that was using D3DX&#8230; which now no longer compiles. Grr. (At least on Linux, once you get your code working, it tends to stay working&#8230; \ud83d\ude41 )<\/p>\n<p>Well, I could just fix my DirectX code, but I thought it would be better in the long run to bite the bullet and set up a proper cross-platform solution for graphics. (The initial reason why I added DirectX support to Knights was just as a quick way of testing out hardware-accelerated graphics on Windows; it was never meant as a permanent solution.)<\/p>\n<p>So, if one is looking for a modern 2D graphics library there seem to be two choices: <a href=\"http:\/\/www.libsdl.org\/\">SDL2<\/a> and <a href=\"http:\/\/www.sfml-dev.org\/\">SFML<\/a>. I had a look at both of these, it seems to me that they both do roughly the same thing, but they have different kinds of API &#8211; SFML tries to be more modern and object-oriented and so on, while SDL is more &#8220;old school&#8221; with low-level C-style functions and structs and things. Personally I prefer the former, so I decided to try out SFML.<\/p>\n<p>I have to say, I was not disappointed &#8211; SFML was very easy to set up and integrate into the game and seems to work very well. Performance was much faster than software rendering, although admittedly slightly slower than I got from my DirectX code (not sure why this is; presumably it&#8217;s just the overhead of having an extra library in between you and the graphics card; in any event, it&#8217;s not that big a deal and I think it&#8217;s a price worth paying given how easy to work with SFML is).<\/p>\n<p>I also had some small keyboard handling problems with SFML (e.g. it seems the ` key &#8211; the &#8220;team chat&#8221; key in Knights &#8211; is not recognized, but I think I can work around that).<\/p>\n<p>Overall, therefore, I hope to have the SFML integration work done in the next few days, which means the next version of Knights will support fast hardware-accelerated graphics in both Windows and Linux. (As a side note, there is also a problem on some Windows machines where the Knights DirectX graphics doesn&#8217;t work if you don&#8217;t have the right DirectX runtime libraries installed&#8230; that should also be fixed by the move to SFML.)<\/p>\n<p><em>For more information about Knights please visit <a href=\"http:\/\/www.knightsgame.org.uk\/\">http:\/\/www.knightsgame.org.uk\/<\/a>.<\/em><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, recently I bought a new laptop. And with it being a new year and all, I thought this might be a good opportunity to get back to some Knights development (something that, sadly, I haven&#8217;t had much time for these last few months). So, I installed the latest Visual Studio onto the laptop, set &hellip; <a href=\"https:\/\/www.knightsgame.org.uk\/blog\/2014\/03\/01\/investigating-sfml-for-graphics\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Investigating SFML for graphics&#8230;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-549","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":19,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"predecessor-version":[{"id":568,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions\/568"}],"wp:attachment":[{"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.knightsgame.org.uk\/blog\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}