HelloWorld
From SDL.NET
This tutorial shows how to setup your IDE for use with SDL.NET and then how to write a simple hello world application. The program simply initializes SDL.NET and displays its initial window. All files regarding this tutorial can be downloaded at the bottom of the page and knowledge of either C# or VB.NET is assumed. We'll be using C# in the majority of these tutorials, but converting to VB.NET is easy. It is also assumed that you successfully installed SDL.NET (Help With Installation). You can use any C# IDE, Visual Studio and SharpDevelop being the most popular, but this tutorial will be targeted to those who use Visual Studio. The most important thing is that you know how to use it.
| Table of contents |
Setting Up The IDE
Once you have successfully downloaded/installed SDL.NET, you will be able to use it in your development environment by making reference to it in your project.
- Start up a Windows Application project.
- Add reference to SDL.NET. To do this, you:
- Right click on References in the Solution Explorer.
- Choose Add Reference.
- Right-click on the "Form1.cs" file and select "Delete".
- Double-click on "Program.cs" to open it.
- Delete all code from "Program.cs".
- Paste the "HelloWorld" code shown below into "Program.cs"
- Press "F5" to compile and run the code.
Hello World
We will use a preconstucted code base for the example and then take a closer look at it later. In this section we will use SDL.NET to create a new SDL window.
using System;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
namespace SdlDotNetExamples.SmallDemos
{
public class HelloWorld
{
[STAThread]
public static void Main()
{
HelloWorld app = new HelloWorld();
app.Go();
}
public HelloWorld()
{
Video.SetVideoMode(400, 300);
Video.WindowCaption = "Hello World!";
}
public void Go()
{
Events.Quit += new EventHandler<QuitEventArgs>(this.Quit);
Events.Run();
}
private void Quit(object sender, QuitEventArgs e)
{
Events.QuitApplication();
}
/// <summary>
/// Lesson Title
/// </summary>
public static string Title
{
get
{
return "Hello World: First tutorial";
}
}
}
}
As you can see in this small example we create a new SimpleExample class in main and calls the Run function. If we look closely at the constructor of SimpleExample, we see that it sets up SDL.NET with a window of 400 by 300 and changes the caption of the window to "Hello World!". Now try running your application and see what it gives you.
Dependencies
What happened! If you ran your application, it may have asked for SDL.dll. This is because SDL.NET uses SDL in its background and requires it to run. You're going to have to go into the SDL.NET directory and find the win32 dependancies folder. Copy all (or just the required ones) from that folder into your build directory of your project and try to run it again. Better yet, copy the dll files to 'C:\winnt\system32' so the files will always be available. You should now see the Hello World example run.
Conclusion
This is just a small article showing how to initialize SDL.NET. The example itself is not really that exciting but it shows that you know how to make reference to SDL.NET and initialize a window. On the next tutorial, Surfaces, we'll go over how to get some nice graphics on the screen.

