(For those of you unfamiliar, SFML is one of the best alternative libraries to SDL and provides high-level access to graphics, sound, input and networking. It’s perfect for 2D games and other multimedia applications. You can check it out over at their website)
Special thanks to LA and Tyson for pointing out some details in the comments! 🙂
So SFML 2.0 recently went out of RC and is now the official stable version. As I found out about the news I decided to try it out, and since I just installed Visual Studio 2012 I also wanted to see if SFML would work on such an IDE. I saw that the SFML library also had updated bindings for the .NET languages (Visual C++/Basic, C#, etc.) and wanted to take my hand at getting SFML to work with it. It was a bit of a hassle since the tutorials at the main website only listed instructions for getting SFML to work with C++ projects, so I had to do some fuddling around to get it to work with a C# project (it should, since it’s a .NET binding for the library)
Anyway, for those of you still having trouble adding SFML to your C# projects in Visual Studio 2012, here are the steps to get you up and running (before anything else, make sure to download the SFML.Net binaries here (make sure to download the right version for your project, as there are both 32 and 64-bit versions), and extract them somewhere on your drive–it doesn’t matter where.):
- Create a new C# project in Visual Studio 2012. It can either be a Console or Windows Forms project– the difference is that a Console project displays a console when you run the application. If you create a new Windows Forms project, you can safely remove the pre-generated Form1 item in the project.
- Right-click your project in the Solution Explorer and click on ‘Add Reference…’
- When the Reference Manager window appears, browse to the folder where you extracted the SFML.net archive and go to the ‘bin’ ‘lib’ folder. Select the .dll files in the ‘lib’ folder and Click on ‘OK’ in the Reference Manager window to add them to your project.
- Once the .dll files appear in the References section of your project, right-click your project again and click on ‘Add’ > ‘Existing Item…’ Navigate to the ‘extlibs’ folder this time and add the .dll files there (you may have to select .dll files as file filter in the Open dialog box).
- Once these .dll files appear on your Solution Explorer, right-click on them and select ‘Properties’ (or press Alt-Enter). In the Copy to Output Directory property, set it to ‘Copy if newer’.
- That’s it! SFML.net is now set-up for your project.
To test if SFML.net has been fully set up for your project, you can try to run this code snippet (add it to your project’s main file):
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using SFML; using SFML.Graphics; using SFML.Window; namespace SFML_Test { static class Program { static void OnClose(object sender, EventArgs e) { // Close the window when OnClose event is received RenderWindow window = (RenderWindow)sender; window.Close(); } static void Main() { // Create the main window RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML Works!"); app.Closed += new EventHandler(OnClose); Color windowColor = new Color(0, 192, 255); // Start the game loop while (app.IsOpen()) { // Process events app.DispatchEvents(); // Clear screen app.Clear(windowColor); // Update the window app.Display(); } //End game loop } //End Main() } //End Program }
When you run your project the output should be similar to this (see screenshot):
For those of you who still need help, feel free to ask in the comments! 🙂