OpenGL Retro Voxel Renderer Tutorial

By Harrison B


0.5 - Totally Not Fun GLFW and GLEW Setup

Starting Out

I'm using Sublime Text and MinGW-w64 to write and compile the code for this project. In this tutorial, I will describe the basic setup steps for the compiler and libraries we will be using. To be clear, this portion of the tutorial series is completely optional! You are free to choose whatever compiler and IDE you would like to build the project files with and use whatever precompiled libraries you want. I just can't guarantee that everything will work correctly if you do because I don't understand how compilers work. But you probably know what you're doing. Anyway...

A text editor and a compiler. Okay, what else? Well, it's common for OpenGL projects to reference dependencies like GLFW or GLUT. GLFW and GLUT are windowing libraries that will greatly facilitate the process of opening a window in a cross-platform sort of way, in addition to providing an OpenGL context for us to work inside. I've decided on GLFW for this series. OpenGL projects also commonly reference dependencies like GLEW or GLAD. GLEW and GLAD are libraries that can load OpenGL extensions on the fly. Without a library like this, there is a lot of manual labor to be done to ensure that you can use modern OpenGL functions in your application. I've decided on GLEW for this series. GLM (OpenGL Mathematics) is another extremely useful library I will be including in our list of dependencies because it defines a whole host of classes and functions for doing computer graphics math. Do you feel like writing your own matrix and vector math library? Maybe. But let's keep it simple for now. Lastly, I'm including LodePNG because we'll need a lightweight library for loading textures. That'll be all! Phew. Oh, and make sure you have CMake installed.

Here's everything we'll need to create this project from scratch (if the links are broken, you'll have to pioneer uncharted internet territory by yourself, sorry):

Once you've downloaded all these files, start by creating a project folder for all your future source code. I recommend using a cloud drive so that you don't lose your work unexpectedly. Just speaking from experience.

MinGW Installation

MinGW is easy to install provided you use the link above. Open the archive you've downloaded to reveal the contained folder mingw64. For our purposes, you can install it simply by copying that folder into your C: drive. Add the path C:/mingw64/bin to your system's Path environmental variable. From the folder C:/mingw64/bin, copy libgcc_s_seh-1.dll, libstdc++-6.dll, and libwinpthread-1.dll to your project folder. Done!

GLFW Installation

Do you want to compile GLFW from scratch? Me neither. Let's do it. Download the GLFW 3.3.6 source archive from glfw.org. Open the archive and copy the folder glfw-3.3.6 to your C: drive. Open the CMake GUI and set the field 'Where is the source code' to C:/glfw-3.3.6. Set the field 'Where to build the binaries' to C:/glfw-3.3.6/binaries. Click 'Configure' and then 'Yes' if prompted to create the new directory. For the generator, select 'MinGW Makefiles' and check 'Use default native compilers'. Click 'Finish'. Check the box that says BUILD_SHARED_LIBS. This will instruct the compiler to generate a dynamic link library for GLFW. Click 'Generate'. Navigate to C:/glfw-3.3.6/binaries and open a CMD console in this directory. Run the command mingw32-make. You have now built the GLFW source code! Create a new directory C:/glfw-3.3.6/lib. Copy C:/glfw-3.3.6/binaries/src/libglfw3dll.a to C:/glfw-3.3.6/lib. Copy C:/glfw-3.3.6/binaries/src/glfw3.dll to your project folder. That's all!

GLEW Installation

Alright, same stuff as before. Download the GLEW 2.1.0 source archive from glew.sourceforge.net. Open the archive and copy the folder glfw-3.3.6 to your C: drive. Open the CMake GUI and set the field 'Where is the source code' to C:/glew-2.1.0/build/cmake. Set the field 'Where to build the binaries' to C:/glew-2.1.0/binaries. Click 'Configure' and then 'Yes' if prompted to create the new directory. For the generator, select 'MinGW Makefiles' and check 'Use default native compilers'. Click 'Finish' and then 'Generate'. Navigate to C:/glew-2.1.0/binaries and open a CMD console in this directory. Run the command mingw32-make. GLEW is compiled! From the directory C:/glew-2.1.0/binaries/lib, copy libglew32.a and libglew32.dll.a to C:/glew-2.1.0/lib. Finally, copy C:/glew-2.1.0/binaries/bin/glew32.dll to your project folder. Done and done! You can now relax because the rest of the setup is a breeze.

GLM Installation

Oh how grateful am I that GLM is a header-only library. No compilation required! Download the GLM library from github.com/g-truc/glm. Open the archive and copy the outermost glm folder to your C: drive.

LodePNG Installation

LodePNG installation is super quick. The site lodev.org/lodepng hosts lodepng.h and lodepng.cpp which contain all of the code necessary to load PNG images. Create the directories C:/lodepng/include and C:/lodepng/object. Download the header and source files, placing the header into the include directory and the source file into the object directory. While we could build this source file into our application every time, it makes more sense to precompile it into an object file. Open a CMD console in the C:/lodepng/object directory. Run the command g++ -c -I"../include" lodepng.cpp. This will create an object file called lodepng.o, which can then be statically linked into our application later. Go ahead and delete lodepng.cpp. That's the last of our libraries!