Journal Entry 2 – Getting Started: Windows

I’ve spent the last hour or so committing my OpenGL library to GitHub. I’d like for all of that code to be in the public domain so that anyone following this blog can try out some of the stuff I am working on. I apologize in advance, the OpenGL library is not the best, but it’ll do. It is a stripped down version of what OpenTK provides, eliminating all of the fixed function pipeline.

I only support OpenGL 4 methods, which means you have to go through the whole song and dance of creating VAOs/VBOs and shaders before being able to draw anything. Luckily there is lots of code to deal with math, FBOs, VBOs, etc that are built into the library. There are some examples in the GitHub, and I’m sure some more examples will be appearing here shortly.

In fact, I’ll post the source code (in full) of what I posted on GitHub, and include a screenshot. Here we go:

        private static VAO cube;
        private static int width = 1280, height = 720;
        static void Main(string[] args)
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            // create the shader program
            ShaderProgram program = new ShaderProgram(vertexShader2Source, fragmentShader2Source);
            // set the color to blue
            program["color"].SetValue(new Vector3(0, 0, 1));
            // set up some defaults for the shader program project and modelview matrices
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["modelview_matrix"].SetValue(Matrix4.CreateTranslation(new Vector3(2, 2, -10)) * Matrix4.CreateRotation(new Vector3(1, -1, 0), 0.2f));
            // create a cube
            cube = OpenGL.Geometry.CreateCube(program, new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
        private static void OnRenderFrame2()
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        public static string fragmentShader2Source = @"
uniform vec3 color;
void main(void)
  gl_FragColor = vec4(color, 1);
        public static string vertexShader2Source = @"
uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
attribute vec3 in_position;
void main(void)
  gl_Position = projection_matrix * modelview_matrix * vec4(in_position, 1);

And, of course, the resulting screenshot:

A wireframe cube being rendered using the OpenGL framework and C#/.NET.
A wireframe cube being rendered using the OpenGL framework and C#/.NET.

There may be more to come tonight! Cheers,


6 thoughts on “Journal Entry 2 – Getting Started: Windows

    1. Hi Yanz! Thanks :) Hopefully you find some of the stuff here useful. Feel free to fire me a message if you have any questions, either here, or on twitter. @_giawa_ Cheers!

      1. Thanks!
        I am interested in making a small voxel based game for experience/fun, I’ve read through these first few. Installed Visual Studio 2013, how do I install the openGL library and such? What else do I need?

        1. Hi Yanx – aside from OpenGL.dll (which you can add as a reference to your project), you will also need something that can create an OpenGL context. I use FreeGLUT, and the Tao Framework and OpenTK both have C# bindings to FreeGLUT. Depending on what you prefer, you could create your own context, use SDL, GLFW or another offering out there as well. I’ll try to make a video in the next day or two on how to get an OpenGL window up and running. Cheers – Giawa

          1. That’d be great. I’m a tad lost, unsure what exactly I should be installing. Or if I should go with C++/Java/etc.

            Thanks for being so helpful!

          2. Hi Yanz! Sorry it is taking so long for me to get a video together. In the mean time, there are lots of cool tutorials out there for OpenGL and different languages. You could check out Nehe tutorials ( which, historically, are some of the best tutorials out there. There are also more modern tutorials using the programmable pipeline available ( looks pretty decent). Good luck!

Leave a Reply