Posted by: Morten Nobel-Jørgensen | November 25, 2012

Cross-platform desktop OpenGL 3.2 using Qt 4.8


There exists quite a few platform abstraction libraries which allow you to create an OpenGL context. Most of these wrappers (FreeGLUT, GLFW, SDL) are small libraries that only supports the most basic stuff such as simple event loops and mouse/keyboard input. This is great if you want to create a 2D or 3D game without any advanced GUI elements. If you on the other hand want to create a program mixing GUI elements with 3D context (for instance a level editor or a model viewer) you need a more powerful library such as Qt (pronounced “cute”).

Modern cross-platform OpenGL development means using a OpenGL 3.2 core profile, which is the latest version of OpenGL available on OS/X where the OpenGL support is strongly tied to the OS. OpenGL 3.2 core profile means support for geometry shaders, GLSL 1.50 and all the old fixed function pipeline functions are no longer available.

Qt is actually much more that a GUI library. Qt includes build tool (qmake), visual gui designers (Qt Designer), resource management, code editor (Qt Creator) and multimedia support. Qt is dual license (LGPL or commercial) and is available from here: qt-project.org.

Even through Qt supports OpenGL out-of-the-box, it needs to be tweaked a bit to allow full 3.2 supports on all platforms.

On Windows we need a way to access the full OpenGL api – the preferred way to do so is using GLEW – The OpenGL Extension Wrapper.

On OS/X we need to modify the windows creation to support the Open 3.2 context (otherwise you end up with an OpenGL 2.1 context). This technique is described here in the Qt Forums by mcdi and miketopen. For the upcoming version 5.0.0 of Qt this issue has been fixed.

To make the project compile on both platforms, we need to modify both the source code (make conditional compilation using some #ifdef) and the make file (which has the file-ending .pro).

Based of the forum post I have created a small OpenGL 3.2 example, which supports both Qt 4.8 and 5.0. The example compiles and run both under Windows and OS/X. The Windows version depends on the GLEW library being installed – and you might need to update the GLEW library path in the .pro file.

The project is available on GitHub:

https://github.com/mortennobel/QtOpenGL3.2Core 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

%d bloggers like this: