Salomonsson.se
Mar 10 2015

C++ and openGL... creating a window

Took a short break from the Unity project to go into C++land. Decided I wanted to play around a little with some C++ and openGL.

I wanted to develop on my Linux partition (why make it easy for yourself?) but make the code cross platform so I’ll still be able to run it on my windows machine. I decided I wanted to use glfw for all the window, input and timer hassle. It seems light weight, and it is used in this tutorial by my colleague at Isotop (he named the blog series “I’m not a smart man” for some reason. Trust me that it is very far from being true!)

So, did it go smooth? Not at all. I’ve spent a bit over three days trying to figure out how in *#¤% you manage to tell Code::Blocks how to find and link the libraries I want to use. I’ve covered it in a blog post, mostly for my own convenience. Probably full of incorrectness.

Well, now I have a spinning triangle in a window. Time to make something more interesting!

Mar 10 2015

C++ and openGL - Part 2

Continued with the C++ project. Noticed that the sample code for my triangle was in the older glBegin…glEnd format and changed it to the new opengl 3 standard with shaders, only to get a totally black window. Turned out you need to add the following code to enable opengl 3 and core profile:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

Which gave me a triangle once more.

The rest of the evening was spent re-reading about matrix operations, and the Model-View-Projection matrices. It was a long time since I last played around with this. You quickly forget if you do not keep working with it.