Category Archives: GUI

A wonderfully simple GUI for OpenGL

After casting a wide net, I found many C++ UIs, but they are generally bulky and often want to grab the main loop (big no-no).

  • Large: Qt, WxWidgets, cinder, CEGUI, ultimatepp, clutter, IUP, JUCE.
  • Medium: Agar, Fox, FLTK, GWEN (seemed the best of these).
  • Small but not terribly attractive: GLUI2, GLV, Turska, STB imgui, simgui.

Capturing the main loop is unacceptable. In the case of Qt, two QGraphicsScenes will each want to vsync, which halves the framerate. Instead, I have a very nice loop that never(!) blocks the main thread, wakes up immediately after a Windows message is received, and waits for vsync with <1% CPU use. (This is hidden behind the SDL interface for portability.)

The approach of AntTweakBar – providing controls that modify YOUR variables, rather than caching everything inside some deep class hierarchy, looked nice. Unfortunately the code is dense, surprisingly large and has had some scary bugs.

Further research pointed towards IMGUIs – conceptually very simple, easy to use, straightforward to integrate. Great! Most of the ones I found stumble in terms of text rendering (important for UIs) and/or were not portable or easy to integrate into an SDL/OpenGL app. The best one was Nvidia’s now discontinued imgui from their SDK.

I started with that and completely rewrote it with proper text rendering, much simpler and cleaner code, and support for vertex arrays so it will hopefully also run on GL ES 2.

Here’s a screenshot showing various controls (checkbox, slider,  list box, label, combo box, panel, radio button, pushbutton, line edit):

OpenGL UI v2
The best part: it’s all contained within a 340 KB executable with no external dependencies (apart from the usual kernel/user/gdi/opengl). The whole thing is only ~9 KLOC and builds in 2 seconds. This is the kind of simplicity I like – such a joy to develop 😀

Let’s share in the fun. The headers are available here: ui [6 KB]

I’d love to hear your thoughts on the interface, whether anything important is missing, and welcome any discussion here or via email.