Skip to content

Instantly share code, notes, and snippets.

@Honghe
Created September 30, 2016 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Honghe/933689f05d1fdbf47c86874e6716484c to your computer and use it in GitHub Desktop.
Save Honghe/933689f05d1fdbf47c86874e6716484c to your computer and use it in GitHub Desktop.
OpenGL Startup

The Travel Guide to OpenGL

This is a pain in my side.

I've figured out several things while trying to extend my knowledge of Computer Graphics.

  1. OpenGL is a bitch.
  2. There is no worse pain than to experience CMake without knowing what you're doing.
  3. When walking to the depths of hell, it would be nice to have a travel guide.

And that's what this is, a travel guide.

These are the important notes that I would like to remember while I'm on my way to the shithole that is OpenGL graphics.

Graphics, amiright?

Editor

I'm using an IDE called CLion, made by JetBrains. It works pretty well as I mainly develop on Unix like platforms and it acts as an alternative to Visual Studio.

Making/Building

The current version of CLion requires the building to be done with CMake. I don't mind enduring this, seeing as how CMake is a decent tool, but it's kinda annoying that it's madatory.

This is my current repository for learning OpenGL. It holds my CMakeLists.txt (Which is the file that CMake looks for to start the building process). You can look it over and try to figure out exactly what it is that I'm actually doing.

The proper way to build your project would be to create a CMake file and go from there. If you don't understand the CMake language at first (don't be ashamed, it's awful) and just want to get into the C++, you can simply compile through the terminal until your project gets unwieldy. At that point, you're going to have to switch. It's gonna happen. Better sooner than later.

Libraries

I'm using several libraries for this. They're largely major ones that plenty of people throughout the internet have suggested.

  • GLFW for window management and input.
  • GML for linear algebra tools.
  • GLEW is a wrapper for OpenGL, written in C++. It's good to make your code compatable across multiple platforms.

####GLFW This is a C library with bindings to window management and input. This is basically a requirement. Without this library, there would be no way to see the output of all of your code. This ain't no WebGL, we don't got no canvas element.

It should be noted that it was a choice between this library and another one called SDL. I chose GLFW because... I don't know.

With that being said, GLFW is fairly easy to set up with CMake. You can follow this tutorial and add that to your CMakeLists.txt or you can just use the one that I already made.

####GLM You're gonna need a matrix library of some sort. This is a common one that many recommend. It is a C++ header library and as such, does not need to be compiled.

If you look at my CMakeLists.txt file, you'll notice that in my dependancy section, there is no mention of GML, that is because it does not need to be included in the building process. You simply include the library within you .cpp file and it just works.

####GLEW This is a wrapper for OpenGL. All that means is that it adds tools for making your code compatible with different environments, e.g. Windows, OS X, Linux, etc.

This is a must if you plan on having your code compile on multiple operating systems or even on different driver setups. Driver companies like Nvidia and AMD write custom software to optimize your GPU's performance. These drivers are often not universal and, as such, need to be dealt with. That is where GLEW comes in handy.

With all of that good stuff being said, GLEW is a merciless fucking bitch to add to CMake. The default repo comes with a different format of make file. That makes it a duck of a fuck and I DO NOT APPROVE.

There are work arounds to this problem, including, but not limited to, remaking the whole make file in CMake format, downloading someone else's remake of the make file and incoorporating it into your code, or the easiest thing, killing yourself.

Getting Started

Begin with a new project in CLion.

You can follow this tutorial for a crash course on GLFW and to create a starting window.

Ending thoughts

This is by no means comprehensive. I will be updating this periodically once I have aquired a greater understanding of what it is that I'm actually doing. Until then...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment