I'm building my own game engine in C++ and I'm currently deciding on what user interface I should use.

Should I use a library? Should I make my own?

closed as not constructive by MichaelHouse, Sean Middleditch, Tetrad Jun 16 '13 at 13:50

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    It's not clear what you mean: In-game GUI? Or GUI for tools? Each one is a very different requirement.. – jacmoe Aug 3 '10 at 11:48
  • 1
    Who needs tools when you have an ENGINE (epic music) – Ricket Aug 3 '10 at 13:48
  • 1
    if you just need modal dialogs, tiny file dialogs on sourceforge is a single C C++ cross-platform file to add to your project. no init, no main loop – tinyfiledialogs May 7 '17 at 4:11

In fact, Qt widgets can be integrated with OpenGL and OpenGL can be easily integrated with Qt (QGLWidget). Of course, the platform native looking widgets might not be exactly what you are looking for, but do not worry, there are ways to customize them, create your own or use something else which would better suit your needs, such as Qt Quick (which you should be able to integrate as well).

If you are interested, do not miss these links: Widgets enter the third dimension: WolfenQt and Accelerate your widgets with OpenGL

I don't think you should write your own, the task of creating a game engine is so huge by itself, if you around there are many many libraries with good licenses that you could use, and modify to your liking.

For a game engine I would go for an Immediate mode GUI. More informations here: http://www.mollyrocket.com/forums/viewtopic.php?t=134

The key idea is to draw the component and control the interaction at the same time:

if (button(id, position, size)) 

For one, Unity uses a similar concept.

You can find an implementation by NVIDIA, used in their demos: http://code.google.com/p/nvidia-widgets/

  • 4
    IM GUI is an interesting concept, but I've found that there are some problems that pop up when you try to do gamey things. If you want the menu elements to animate in/out you either have to do something like modify the individual position of all the widgets, or do something like modify the GUI transform matrix for that call. It would be easier if you had, for example, a Window container whose actions are translated down to its children and such. Also, for some reason, most IMGUI implementations lack "disabled" widget states. – Tetrad Jul 22 '10 at 7:15
  • @Tetrad: It's very easy to implement widget groups with auto-layouts, relative positions or absolute positions (Nvidia widgets does this.) It lets you very easily contain widgets inside windows or panels. For the "disabled" state, I can't see why this would not be trivially implemented. For "gamey things", I think the immediate mode concepts are actually more suitable than retained mode, since the widgets are updated every frame. – Oskar N. Sep 29 '10 at 8:29

Personally, I would recommend CEGUI. It's open source and pretty good. However, what you have to keep in mind is that it can be very, very verbose if you write out everything by hand.

But, on the plus side, it has renderers for both OpenGL and DirectX. I managed to put it on top of the template I normally use, which writes to a texture directly using a VBO (it's kind of hacky).

The game in question was for a networking assignment. The assignment was to have a networked game, with a lobby. I knew the lobby was going to be a pain in the neck to make, so I picked a library that did most of it for me.

  • This is what I'm currently using. I find that it has too much dependency though. And I had trouble linking it to my project (IIRC, the license said that I can only link to the library) – MrValdez Jul 22 '10 at 7:48
  • 6
    It has a ridiculous amount of dependencies. It bloated my tiny demo game to 50 MB! – knight666 Jul 22 '10 at 8:04
  • What? I think you're doing it wrong :) The weight of the CEGUI DLLs in my game is less than 3 MBs. And to MrValdez: CEGUI is under the BSD license.. – jacmoe Aug 3 '10 at 11:48
  • MIT license - sorry. CEGUI is under the MIT license. :) – jacmoe Aug 3 '10 at 14:49

The problem with most GUI libraries (Qt is probably the most popular C++ one that isn't Windows-only) is that most won't integrate well into an engine. Traditionally in a GUI app, the GUI library controls the main loop and you just hook up callbacks to events. In a game engine you generally want to control the loop, so it can be tricky at best. Maybe you are looking for something that will just handle drawing controls and dialogs and such into an 3D context you pass it? Those can be a lot harder to find :-/

  • <pedantic>wxWidgets is also cross-platform</pedantic> though I take your point about engine integration – zebrabox Aug 3 '10 at 21:58
  • 3
    I said "most popular", not "only" :-P wx has even less support for working with 3D contexts last I looked. – coderanger Aug 3 '10 at 22:27

I strongly believe in write your own but then again I'm very oldskool. Fighting with yet another GUI lib to do just that one thing that you want tends to drive me nuts, added to the fact that most game GUIs are quite trivial so you don't have to go all-out on MDI and super OO design where buttons can have scrollviews that highlight when you happen to hover over a taskbar on the side of a checkbox with draggable thumbs - or something like that. Different strokes for different folks I guess.

  • there are situations where "write your own" is not so much out-of-place as one might think. A game where UI is important, like management games, or RPGs with complex items managements; the UI would be a huge part of the experience. joelonsoftware.com/articles/fog0000000007.html If it's a core business function -- do it yourself, no matter what – v.oddou Jan 5 '15 at 3:22

One option that might be worth investigating is using WebKit to render your user interfaces and doing all your UI with CSS/HTML/Javascript.

Here's an open source implementation (Berkelium), and here's a closed source, commercial implemtation (Awesomium)

  • 5
    WebKit and its kin are more geared toward a refresh rate of once or twice a second, might be tricky to do a HUD for an action-oriented game that way. Would be great for menus or slower bits though. – coderanger Jul 22 '10 at 6:50
  • 1
    @coderanger: You can write entire games in JavaScript/HTML5. I've published a commercial action game for the Chrome Web Store that runs at 60 FPS just fine in WebKit/Chrome. – Sean Middleditch Oct 19 '11 at 22:58

I would suggest IUP - Portable User Interface: http://www.tecgraf.puc-rio.br/iup/

I've only used it with the Lua programming language but it was very easy to use. It only comes in C, LED and Lua flavors but you can easily make a wrapper for it.

  • Looks interesting. I'm gonna check it out as soon as I can. – MrValdez Jul 24 '10 at 10:14

I am personally using CEGUI in my game project, and it is a pretty robust solution. Problem is, sometimes it almost feels like to make one tiny change your altering tons of files.

I have not used it, but libRocket just went completely free, removing all license fees and what not. The cool part about this lib is that you write it in html/css syntax. http://librocket.com

Just raising an interesting suggestion, if developing the game for Windows, use the Win32 API. Just use the normal windows controls (I would recommend using the ATL/WTL libraries) but make them owner drawn.

I saw this technique being used in the first Unreal Tournament game, while looking through the publically released headers (for mod makers).

One of the key benefits to doing this is having the whole Windows UI infrastructure at your disposal, as well as maintaining the user's preferences for keyboard repeat rate, mouse sensitivity, double click speed, and other things. Also if you obey the rules the interface will be fast and flicker free.

The drawbacks are that you'll still have to write some code to subclass the windows controls to make them owner draw so that you can apply your own graphics and effects to them.

Just throwing this out as an idea.

  • 1
    I believe win32/COM is emulated on Vista and Win 7. Not recommended for High performance... – Stephen Furlani Nov 8 '10 at 20:17
  • I guess it depends how much of the GUI you'll use in the game. If it's just for the menu system then who really cares, if you're using it extensively in the frame rate crucial section then it needs some work and thought. – Daemin Nov 10 '10 at 0:32
  • @StephenFurlani Win32 / COM is not emulated on Vista and Windows 7, it is native and full speed. Furthermore ATL/WTL doesn't rely on COM, but DirectX does. – Daemin Apr 2 '12 at 23:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.