More graphics library stuff…

Here is a quick update on Knights development.

Unfortunately I have still been struggling with graphics libraries for what feels like ages now.

Last time I posted that I was trying out SFML and have been doing quite well with it. Unfortunately I have found what seems to be a fatal problem – SFML is completely unable to detect keypresses of the “backquote” key (that is, the key above TAB). This is important for Knights because we use that key as a chat key. Unfortunately I haven’t found any way to work around this, so it looks like we won’t be able to use SFML for Knights right now.

I also looked into SDL 2. However, I found the rendering performance to be very slow. It seems that to get decent performance out of SDL 2, you have to be making direct OpenGL calls in your code (instead of relying on the so-called “SDL_Renderer” layer). Unfortunately this would be quite a lot of work (especially since I don’t really know any OpenGL at the moment…) so this is not really feasible for me right now.

Therefore I think the plan will have to be:

  1. I will keep Knights as it always was — i.e. using DirectX on modern windows machines, and using SDL (version 1 – which uses software rendering)Β on Linux or older versions of Windows.
  2. I have made a few changes to my DirectX code — in particular I have removed the dependencies on D3DX and D3DCOMPILER. This should mean that the code will run on any modern Windows machine without any “DirectX runtime library” downloads being required. (I have also put in some simple UTF-8 text handling, but that is another story…)
  3. At some point I will get in touch with the author of SFML to see if the keyboard handling can be improved. That would eventually mean that I could switch Knights over to using SFML on all platforms. Not only would this bring hardware accelerated graphics to Linux (finally!), it would also mean that I only have one lot of graphics code to maintain instead of two, which will make things easier. This is a longer-term goal though.

Knights ADF available

I got contacted a couple of months back by someone who said “I would love to play the original Knights on my old Amiga 500 but I can only transfer ADF Files to it“.

I had no idea people still played Knights on old Amigas (anyone remember setting up the piece of cardboard to divide the screen in two? πŸ™‚ ) but I was happy to help, so I made a bootable ADF from the Aminet version of Knights and sent it to him. The ADF file is now available for download. Enjoy πŸ™‚

Note that to use this you will need either a real Amiga or an emulator. Regular users will probably want to check out the PC version available from http://www.knightsgame.org.uk/.

Investigating SFML for graphics…

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’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…

… 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 – in particular, “D3DX” is no longer a supported technology. Unfortunately for me, I had some code that was using D3DX… which now no longer compiles. Grr. (At least on Linux, once you get your code working, it tends to stay working… πŸ™ )

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.)

So, if one is looking for a modern 2D graphics library there seem to be two choices: SDL2 and SFML. 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 – SFML tries to be more modern and object-oriented and so on, while SDL is more “old school” with low-level C-style functions and structs and things. Personally I prefer the former, so I decided to try out SFML.

I have to say, I was not disappointed – 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’s just the overhead of having an extra library in between you and the graphics card; in any event, it’s not that big a deal and I think it’s a price worth paying given how easy to work with SFML is).

I also had some small keyboard handling problems with SFML (e.g. it seems the ` key – the “team chat” key in Knights – is not recognized, but I think I can work around that).

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’t work if you don’t have the right DirectX runtime libraries installed… that should also be fixed by the move to SFML.)

For more information about Knights please visit http://www.knightsgame.org.uk/.