Installation

To get started with OpenTK you are probably going to need an IDE (Intergrated Development Environment) which serves as an editor and keeps track of include files (or assemblies as they're called). Essentially this will be MonoDevelop or Visual Studio. There is more information in the official documentation. I am using Visual Studio and doing cross platform testing with Ubuntu.

To make sure things are working right, try this

using System;
using System.IO;
 
class Program
{
  static void Main(string[] args)
  {
    Console.WriteLine("Hello World!");
    Console.WriteLine("This is a C# console application.");
  }
}

On Windows the executable HelloWorld.exe runs immediately by double clicking on the file. On Ubuntu you must execute using

mono HelloWorld.exe

This program should run without recompilation on any platform equipped with Mono or .NET.

You are also probably going to need a GUI. Both Microsoft and Mono offer more than one set of libraries. I am partial to Windows Forms because I'm windows-centric, but GTK is very good and I like it too. Here is a GUI sample

using System;
using System.Windows.Forms;
 
public class HelloWorld : Form
{
  static public void Main()
  {
    Application.Run(new HelloWorld());
  }
 
  public HelloWorld()
  {
    Text = "Hello World";
  }
}

This one ran immediately on Windows. I had to tell Ubuntu to download the Windows Forms package from the Mono depository, then the example worked perfectly.

Now that your IDE is working, you need to install OpenTK. I downloaded a file called opentk-0.9.9-3.zip and expanded it to C:\. Installation very easy. Just tell Visual Studio to use the assembly

C:\opentk-0.9.9-3\Binaries\OpenTK\Release\OpenTK.dll

This is explained in detail in the official documentation.

Now we want to see whether this works at all. Here's the sample code:

using System;
using System.IO;
 
using OpenTK;
 
namespace ConsoleApplication2
{
  class Program
  {
    static void Main(string[] args)
    {
      var devices = OpenTK.DisplayDevice.AvailableDisplays;
      foreach (var device in OpenTK.DisplayDevice.AvailableDisplays)
      {
        Console.WriteLine(device);
      }
    }
  }
}

Yes. It gives the correct output

Primary: {X=0,Y=0,Width=1920,Height=1200}x32@60Hz (41 modes available)
Press any key to continue . . .

You will notice that the official documentation is completely messed up on these function calls. [Fixed now, see note below.] In general the best way to sort these things out is to take a look at the source code which is quite well organized and easy to read. You can find that here

C:\opentk-0.9.9-3\Source\OpenTK

I was lucky and noticed the DisplayDevice class immediately.

Now I will pause here to check this on Ubuntu.

I copied the executable and OpenTK.dll to my Ubuntu system. It worked perfectly. My laptop actually has more video modes than my desktop.

Next step is setting up an OpenGL sample window.