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.
- Printer-friendly version
- Login or register to post comments


Comments
Re: Installation
Updated and simplified documentation to match the 0.9.9-3 release.
Re: Installation
This is great stuff for a noob like me ;) I'm waiting for the next part of the tutorial, since I need to implement a OpenGL inside a window.
Oh, just a minor note. Could you show how to get GLControl run in a application like this?
I tired out the other tutorial on this subject, but since I am on OSX I couldn't add the glControl as a component to the form (the first part of tutorial).
Re: Installation
Just add the GLControl as a class field:
Of course, you can modify the control's size, dockstyle, anchoring, name, vsync and anything else you'd like. (The simplest approach is to add a
glControl.Dock = DockStyle.Fill;so that it covers the whole form).Re: Installation
Fiddler, that code you pasted doesnt seem to work. It complains about GLControl namespace not being found and when I fix it like this:
Which i think should be correct, it just flashes the window and crashes with the following output:
Using Snow Leopard and the latest versions of Mono and OpenTK :)
Re: Installation
VeliV, I'd suggest creating a new bug report for this issue. I just committed a fix, but I cannot actually test that GLControl is now working correctly.
It would really help if you could install a subversion client and test with OpenTK from SVN.
Re: Installation
Yah, had some problems with subversion, since the solution and project files aren't included in it (couldn't open the project in mono). But I managed around it.
But it still crashes. Here is the output:
I'll go add an issue, altough I am not really sure what to put in it :D
Re: Installation
The stack trace should be enough.
You can generate the missing project files by running Build.exe from a terminal ("mono Build.exe", just press enter). Build the debug version of OpenTK (so that the stack trace will include line numbers) and replace the OpenTK reference in your project with the new one (assembly version should read 0.9.9-4). You might have to remove the current reference before adding the new one to make this work.
If it still crashes, please post the new stack trace, which will contain line numbers instead of [0x00000] values.
Re: Installation
I feel quite dumb for asking this, but how do I draw something in it? :P I got stuff working in GameWindow, but I don't know where to put the GL commands with GLControl :)
Re: Installation
Add a paint event handler after creating the GLControl:
glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);And then add your OpenGL commands there:
Re: Installation
Thanks, works now.