<p>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 <code>QOpenGLWidget</code> 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.</p>

<p>This will work perfectly fine with other GUI elements.</p>

<p>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.</p>

CC BY-SA 3.0
2017-04-06T10:40:08.937Z
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) ?
Karlovsky120
CC BY-SA 3.0
2017-04-06T13:20:22.720Z
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.
mdkdy
CC BY-SA 3.0
2017-04-06T10:01:55.410Z
2017-04-06T10:13:27.050Z
2017-04-06T10:13:27.050Z
mdkdy
<p>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.</p>

<p>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.</p>

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

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

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

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

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

<p>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 <a href="http://gamedev.stackexchange.com">GameDev Stack Exchange</a> if you don't find a sufficient answer here.</p>

<p><a href="https://i.sstatic.net/jcvYM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jcvYM.png" alt="enter image description here"></a></p>

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

CC BY-SA 3.0
2017-04-08T10:46:11.840Z
2017-04-08T10:46:11.840Z
2017-04-13T12:18:54.697Z
Arjan Singh
<p>Take a look at Qt.  Qt is built on opengl and therefore integrates with it pretty easily.</p>

<p><a href="http://doc.qt.io/qt-5/qtopengl-hellogl2-example.html" rel="nofollow noreferrer">Hello GL2 Example | Qt Documentation</a></p>

CC BY-SA 3.0
2017-04-10T20:33:01.677Z
2018-03-04T00:39:07.157Z
2018-03-04T00:39:07.157Z
default
<p>Some of the easy to use GUI libraries for OpenGL I have come across are (in no specific order):</p>

<ol>
<li><a href="https://github.com/ocornut/imgui" rel="nofollow noreferrer">imGUI</a></li>
<li><a href="https://github.com/wjakob/nanogui" rel="nofollow noreferrer">NanoGUI</a></li>
<li><a href="http://anttweakbar.sourceforge.net/doc/" rel="nofollow noreferrer">AntTweakBar</a></li>
</ol>

<p>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. </p>

<p>Hope this helps. </p>

CC BY-SA 3.0
2017-04-08T06:18:54.387Z
2017-04-08T06:18:54.387Z
TheOrestes
<p>For the fun of it, I've taken up a task of writing a level editor for a voxel game.</p>

<p>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:</p>

<p><a href="https://i.sstatic.net/Z4w4f.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Z4w4f.jpg" alt="enter image description here"></a></p>

<p>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.</p>

<p>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. </p>

<opengl><ui>
Clashes when combining openGL and GUI
Karlovsky120
# Clashes when combining openGL and GUI

(Asked by: username_0 on 2017-04-05)

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](https://i.sstatic.net/Z4w4f.jpg)](https://i.sstatic.net/Z4w4f.jpg)

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.

**Tags:** opengl, ui


---

## 4 answers

### Answer by username_1 on 2017-04-06. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: 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) ?  
> **username_1**: 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.  

---

### Answer by username_2 on 2017-04-08. Score: 2

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](http://gamedev.stackexchange.com) if you don't find a sufficient answer here.

[![enter image description here](https://i.sstatic.net/jcvYM.png)](https://i.sstatic.net/jcvYM.png)

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


---

### Answer by username_4 on 2017-04-08. Score: 2

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

1. [imGUI](https://github.com/ocornut/imgui)
2. [NanoGUI](https://github.com/wjakob/nanogui)
3. [AntTweakBar](http://anttweakbar.sourceforge.net/doc/)

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.


---

### Answer by username_3 on 2017-04-10. Score: 0

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

[Hello GL2 Example | Qt Documentation](http://doc.qt.io/qt-5/qtopengl-hellogl2-example.html)


---

