OpenGL via OpenTK

This project was my way to start learning OpenGL systems. I used OpenTK(C# bindings for OpenGL) for this project to enable me to work in a language I’m super comfortable with.

The basics

Of course, the project started out with the basics. The first thing I did was make sure I could render a basic cube onto the screen and move the “camera” around it.

Mesh Loader

Typing out each vertex data for an entire mesh takes way too long so the next step was to set up a mesh loading system. I decided to use AssimpNet to load mesh data from a file and convert the loaded data into my internal mesh systems. The internal mesh system can handle positions, uvs, and normals.

The image shown is a high-resolution sphere mesh with a shader that moves each vertex 1 unit in the direction of the vertex normal.

Materials

I wanted to make a fairly generalized material system, so I built a material loader that could take some provided JSON data, load up the correct shaders and textures, and apply all the required values to the shader at render time.

Basic Transparency

While working on my material system I decided that I wanted to support some basic transparency. To accomplish this I just simply moved all transparent objects to the end of the render queue automatically and then disabled writing to the depth buffer before drawing the transparent objects.

Frustum Culling

I also created a basic frustum culling system. Each mesh is given a bounds size value during load. During the render step any mesh whose origin is found to be outside of the camera frustum by that bounds value gets skipped, providing a basic form of camera frustum culling.

Basic Component/Scene System

All movement shown in any previous gifs was controlled by a component-based system that allows me to attach scripts to otherwise empty objects and perform actions like moving the camera around or moving the object up and down according to a sin wave.

With the use of C#’s reflection tools, I made a simple JSON-based scene system so the entire contents of the scene are defined by a JSON file instead of in code.

Previous
Previous

3D Paddles in OpenGL

Next
Next

Enhanced Tags For Unity