DEV Community

Cover image for OpenGL Game in Clojure CLR (Mono/.Net) - Part2 (The GameWindow)
Pankaj Doharey
Pankaj Doharey

Posted on • Edited on

OpenGL Game in Clojure CLR (Mono/.Net) - Part2 (The GameWindow)

Importing OpenTK assembly.

We will begin with importing the OpenTK dll files into our source.

Update the core.clj with the following code:

In the above code we just added the relative path of OpenTK.dll, a .net assembly wrapper for OpenGL.

The we import the necessary drawing and input libs and classes.

Once the necessary classes are imported we will begin with creating an instance of GameWindow class and àssigning a cornflower blue color to the background.

Important thing to note in the above is (.SwapBuffers game) because OpenGl is double buffered so while one buffer is showing on the screen other can be used to be drawn to.

Once a drawing action has been accomplished we need to instruct the Graphics card to swap the visible buffer with the buffer drawn to this makes the new buffer visible and hides the previous one. Double buffering is essential in creating the illusion of animation by drawing to alternate buffers and swapping them.

Also (.Run game 30.0) is essentially telling OpenGL to refresh the screen at 30 FPS (30 Frames per second)

Now let us compile this program using:

$ ./build.sh c
Compiling core to build/ -- 1796 milliseconds.

And then run it using :

$ ./build.sh r

This should result in a sunflower blue coloured window:

SunFlowerGamewindow

So now we have a simple OpenGL Window Running, but it doesnt handle any inputs as of yet. In the next series lets implement ways to handle keyboard input to close the window.

All Posts:

Part 1 - The Setup
Part 3 - Handling Input

Top comments (0)