3
$\begingroup$

For the fun of it, I've taken up a task of writing a level editor for a voxel game.

The idea is to have window that contains two main components. First component is openGL viewport placed in lower left or right corner of the window (or anywhere, really). The rest would be occupied with the second component, you guessed it, the GUI. It would consist of the menu bar, status bar and various options to select tools to use. It could also contain dialog boxes to manage metadata contained in the map. The GUI stuff. It would have this general look:

enter image description here

The question here is whether those two would get along. I've been googling for a while and have failed to find any specific info on openGL to GUI interaction and vice versa.

Am I free to just use any GUI library with openGL, limiting the latter to a part of the window, or are there some things I'd have to look out after. I know it's a bit of a general question, but I really didn't manage to find any specific information on this.

$\endgroup$

4 Answers 4

3
$\begingroup$

General answer is that creating a window as a GUI element with some GUI designer library involves subclassing some basic GUI element (like widget in QtCreator for example) with class providing handling GL context in more or less user friendly way (like QOpenGLWidget in QtCreator which provide some user friendly wrapper or on the other hand basic Win32 API handle) and override methods for handling its framebuffer drawing or resizing, swapping buffers etc. with usual gl extensions provided by some lib you use.

This will work perfectly fine with other GUI elements.

I don't know which GUI lib or IDE with GUI designer or language you prefer but most good libs can handle this. You can even do it in Assembler with WinApi GUI elements.

$\endgroup$
2
  • 1
    $\begingroup$ Do you have any recommendation for a library that is simple (can be implemented using only c++ code, no additional software and/or designers), fast, c++ oriented (opposed to written for c, but usable) and lightweight (without non gui modules) ? $\endgroup$ Apr 6, 2017 at 10:40
  • 1
    $\begingroup$ Myself I got used to working with QtDesigner IDE + Qt libs, where I design gui using built in designer and subclass widget to get gl context and then use glew to get gl extensions. It is only c++. There are more compact c++ libs for only gui making, like wxwidgets, maybe you should check that out, I don't have much experience with them though. $\endgroup$
    – mdkdy
    Apr 6, 2017 at 13:20
2
$\begingroup$

Some of the easy to use GUI libraries for OpenGL I have come across are (in no specific order):

  1. imGUI
  2. NanoGUI
  3. AntTweakBar

Although AntTweakBar is bit outdated, it's still pretty easy to use. imGUI is definitely the one you should have a look at once. I personally haven't used NanoGUI but have heard good things about it.

Hope this helps.

$\endgroup$
2
$\begingroup$

At one point I had a similiar issue, however, I was using DirectX as opposed to OpenGL so this may not be very helpful but you might be able to gain some knowledge out of this.

My main objective was to create a level editor with basic functionality such as importing models and postioning. I wanted to use C# and WinForms rather than having to learn another entire framework like Qt. I made my engine available as a DLL and exposed a C-style function that intialized my engine with a provided HWND (a C# panel). This enabled me to render to the panel, so I then expanded upon this 'link' and proceeded to add on additional functionality like importing objects.

// in C++:
extern "C" 
{
  void InitializeMyEngine(HWND window);
}

You can then then use P/Invoke in C# to access that function:

class Engine
{
  [DllImport("engine.dll")]
  public static extern void Initialize(IntPtr window);
}

I then called Engine.Initialize(someWindowHandle) in my C# code to initialize the engine.

Here's a link to where asked how I could do this on the gamedev stack exchange: https://gamedev.stackexchange.com/questions/124249/how-do-i-render-my-directx-c-engine-to-a-c-panel

I got a few answers and I managed to do what I needed to do (which I've of course detailed there). There is much more detail and code available regarding the implementation aswell. I would suggest asking on the GameDev Stack Exchange if you don't find a sufficient answer here.

enter image description here

(photo of the engine rendering a cyan screen when the button is pressed using the method I described)

$\endgroup$
0
$\begingroup$

Take a look at Qt. Qt is built on opengl and therefore integrates with it pretty easily.

Hello GL2 Example | Qt Documentation

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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