OpenGL Experience – Space Game
During my second year of study I was really excited, because I was finally able to sing up for one of the computer graphics courses- Graphics Programming. I was really looking forward to it and it did not let me down. In the semester I had to to create a semestral project and I think it was a success!
The course was mainly about OpenGL and 3D space in general. On practical lessons we coded simple tasks in C++ and OpenGL using freeGLUT as a library for windows and input events. It was a lot of fun even though it was a hard work.
I would like to talk more about the final product – the semestral project. I started without any experience in OpenGL and mild knowladge of C++ (even though I knew C and Java pretty good). Luckily the school prepared me mathematicly for the task – so modelling 3D space was not a problem for me.
C++ Math library

During the practical lessons we used GLM (OpenGL Mathematics library) and even though it it very “working” and amaizing library I somehow did not like using it. One time I needed to rotate a 3DVector around arbitrary axis and at that point I found myself having problems with the library (later I discovered the solution …). Basicly I decided to write my own 3D Math library from scratch.
I started with some Vector 2D,3D and 4D definitions and some basic functions – it was actually pretty easy. Interesting stuff came with Matrices. My background knowladge of linear algebra wasn’t bad so I eventually managed to work it all out and complete my own library. It consists of just “.h” file which contains all the definitions and functions. I was and I am satisfied with it – I’m planning to use it in my Bachelor final project.
OpenGL and 3D Engine
At this point I had my math library and I was ready to start implementing my small 3D engine. There are actually some great tutorials concerning OpenGL (it’s quite language independant), so I did not have much trouble learning the basics from the videos and from the lessons.
I started with some basic stuff like buffers, creating classes for Vertex Buffer, Element Buffer and Vertex Array Object (VAO) to contain the buffers. Then it was time for basic Shader loading and representation. Soon enough I had my spinning cube in front of the camera – it felt good! Then I moved to more interesting stuff like representing a 3D object in my engine. I ended up creating class for a Mesh to store the 3D data from .obj files and the VAO. Then I have implemented a Entity class which contained a Mesh, Shader program and
classic 4×4 transformation matrix. I then made a Scene class to contain entities and manage their updates.
I was really happy with my simple engine and as my theme was “space” I decided to create a space game. I knew I wanted a sun, ship you could fly and some planet. The ship and
planets were created in Blender3D. Stearing of the
ship and positioning of the camera took a lot of time around a week – I was not sure how to do it and I discovered that my math library had some issues which I needed to fix. In the end I’ve done it – but there was something missing, the space was just too empty. That’s the time I decided to add asteroids
– procedural asteroids.
Procedural generation – Asteroids
I must say that during the implementation of my little project I got quite good at coding in C++. I needed something to fill the voids and also to do something cool to impress the teacher. There was an amaizing little tutorial on how to do procedural asteroids in Unity3D. So I adopted the idea and created it in my engine. It was actually very simple. I started with a cube which I subdivided multiple times. Then every vertex (point) of the cube is moved by a certain radius along it’s normal – creating a sphere. Now it was just a question of downloading some noise functions and moving every vertex by random value from the noise function. And there it was – procedural asteroids! Another cool thing was the fact that I played around with UV coordinates of the cube in order to match the texture as good as possible. In the end I even ended up doing normal mapping on the asteroids, but I do not think I did a right job.
Conclusion
In conclusion I did a huge amount of work, got much better at C++ and learned OpenGL and GLSL (OpenGL Shader Language). It inspired me very much – I’m actually doing graphics related bachelor project – so I will use all of my experience from this semestral project. It was just so very cool to see something happen from nothing! If anyone reading this wants to do computer games and/or is interested in 3D graphics not only from artist’s point of view, but also from the programmer’s, just go for it! There are many tutorials on youtube and other websites. It really is much fun and great learning experince.