If you have been over to Humble Bundle recently, you would see there is a really good bundle with a load of programming books in it.
Included is a book called “Computer Graphics Programming in Open GL with Java”. As Java and C#, and I like C# much better than Java or C#, I thought I would knock together a few tutorials on using OpenGL and C#. I thought I would also dig out my seasonal globe and try and redo it using C#, Open GL and OpenTK.
So, first thing is to update Visual Studio, fire it up and create a Windows Forms Project.
Using Nuget, grab Open TK and add it into your project.
Next up, delete the Form1.cs and add a new class called Main.cs, add the following OpenTK usings and make it inherit from GameWindow.
Secondly, let’s create a GameSettings.cs class that will contain our constants:
Alright, rather than me screenshotting the whole class here, let’s review it directly from GitHub:
Firstly, in the constructor, we see we are setting up the standard stuff such as the window size, title, what type of window we use. We are also saying we want to use Open GL 4. We have also said we are using the ForwardCompatible flag. Essentially, if something is deprecated, it will not support that functionality making it “forward compatible” when the deprecated function is removed.
We then override the OnResize. Basically, if a user resizes the window, our viewport will be reset.
We are overriding the Onload method and adding our own LoadContent method. I have purely done this for readability sake and also as someone who came from XNA/MonoGame.
I have done the same with the OnUpdateFrame and OnRenderFrame methods by adding the Update and Draw funcitons that we will actually implement rendering and game logic.
I also wrapped the SetBackColour, mainly because it felt neater.
Finally, Dispose is basically there to unload content.
If you have implemented all of that, then you will see that not everything is compiling.
Go into the Program.cs and add the following:
Here we are creating our Main window and then Running it at 60 FPS (the frame rate we set in Game Settings)
That is the first part done.
If you are totally new to programming, or a uni student etc here for a bit learning then what you should do next is head over to GitHub or Bitbucket, set up a repo and make sure everything is committed. There is a load of different software. I would recommend SourceTree, the GitHub client or TortoiseGit.