# OpenGL Adding some GUI to OpenGL

This topic is 1001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have a c++ 3d application based in opengl, sdl and bullets (physics), now i want to add a simple GUI (for example a buttom), the problem is that I don't know how to aproach this situation:

2 - Should I add the GUI to my openGL window, or Add the openGL window to my GUI project?

Another thing, i have been seeing profesional software (for example : unreal engine 4 , unity , cubase , 3ds max , etc ... ) and all of those uses the same buttoms, the same menus, like the one windows have. My question--> what GUI use these software?

Thanks and sorry for the english

Edited by lightbug

##### Share on other sites

OMG is that simple:

// Setup ImGui binding
ImGui_ImplGlfw_Init(window, true);


then i can start drawing GUI things

where did you find this library? I was going to start with wxwidget, but now i got to see more of ImGUI

Thanks!

##### Share on other sites

where did you find this library? I was going to start with wxwidget, but now i got to see more of ImGUI

I had a 3D viewer and needed some simple controls to adjust values.  Not sure how I stumbled upon it.

##### Share on other sites

I was searching about this new concept (for me) of "immediate GUI". Some people says it's not good, some people says that this is "the" solution against the classic method (called "Retained GUI")

I really don't understand anything about GUI, so I will keep investigating

##### Share on other sites

My 2cents:

Immediate mode UIs are great to quickly get simple UIs up and running, specially if you are a lone programmer.

They are usually not so great when the UI complexity increases, and if you have designers in the team.

##### Share on other sites

This is the original video, which started the idea of IMGUI: http://mollyrocket.com/861

The Nay-sayers in that thread on stackexchange only seem hung up on some supposedly bad bundling of logic and rendering from their view of only knowing entangled RMGUI, cause one person answering called his example functions RenderButton and so on. They are not considering how these are implemented internally (probably only the clicking and positioning logic and then calling into some helper function to put drawitems into a renderqueue).

Both do basically the same drawing, but the RMGUI tries to only update changed parts.Then if some of your game objects changes you have to find the right GUI objects which you have to update, calculate update rectangles (and inevitably forget some) to invalidate some parts and hope that the listeners are set up to propagate all changes to the subobjects. RMGUI is an entangled mess of observer-objects which never know when/if their listener methods get called. If you are lucky all necessary draw methods get called timely and necessary parts of the screen updated, though nowadays all that complicated logic is useless, you redraw the whole game window for the game world and a few extra rectangles for the GUI wont kill a modern GPU. If you would just invalidate everything to ease your work an avalanche of update events would ripple back and forth through all GUI objects.

With IMGUI you most likely just do a little setup each frame, no update checking needed, just call the functions for the GUI elements you need and check for results returned from them. The generated drawitems can then be rendered however you like when you think its a good time (for example after rendering the game world). At least thats how I did it when I wrote a little IMGUI library for myself some time ago.

##### Share on other sites

I used to be a naysayer but now i am pro it after many discussions and looking at ocornuts implementation. I've converted my level editor to use my own IMGUI and there is nothing i've been unable to do with it. The original discussion never specified what happens behind the scenes but you can actually do a hell of a lot of "clever stuff". This mostly involves checking against the last frames state.

##### Share on other sites

I guess I'll put in a few more cents.

There is a lot of crappy RMGUIs out there, so I understand peoples frustration and need for something new.

But RMGUIs doesn't have to be that crappy, and IMGUIs, while solving some problems, overlook others.

There is no reason an RMGUI would have to have complicated observers or invalidation logic.

In the RMGUI I'm currently writing, if you change something, vertex buffers will be invalidated and rebuilt before the next draw.

If not, well, then we reuse the vertex buffers from last frame. (normal case for 99% of the frames)

Its not hard to know if a change will mean the vertex buffer it belongs to need update.

I don't care at all about regions. That was relevant in software rendering. Not so much in HW.

You do decouple creation from update/reaction, but you do it for a reason. It might not even be the same person defining it.

But even if it is, I like to have my widgets initial position and layout defined in an xml. Nice and neat and does not pollute my code with layout, and I can even edit it in runtime and reload it for quick ui tweaks. (or complete ui changes as long as the same actions exists)

Since I use lambdas, there is no problem with extreme decoupling, all my callbacks are defined right then and there, without unnecessary code.

Code should be concerned with actions, and never care about exact sizes or positions.

I don't want to rewrite logic for when and how to draw my buttons for every game I do.

It makes sense for game engines where you have complex needs for culling and handling of transparency and effects.

Not that much for UIs.

To have higher class objects like views and popups make code brief and easy to read and modify the relevant parts of.

In my RMGUI, my UI is just another layer/pass in our graphics engine, I call "update" on it when it should be updated, and I call "draw" on it when it should be drawn. (so in a way IM, but on a higher level)

But I wouldn't want to call the equivalent of "draw" for each and every ui item each frame.

Not because I think it would be slow, but because I have no need to see and change that code, it can be completely generic for every UI.

Then of course, RMGUIs can be made overly complex... like most out there.

But it doesn't have to be like that, and I'm not sure IMGUIs really solve the problem, just moves the responsibilty

I don't want to discourage anyone from using an IMGUI though, I'm sure it can be perfect for a lot of projects.

Edited by Olof Hedman

##### Share on other sites

4. I don't see a reason why you couldn't load your xml file, then do IMGUI function calls based on that data.

5. Many RMGUI libs don't allow this.

6. Not sure what logic you fear of having to rewrite. You can easily have a library of precomposed functions for more complicated collections of widgets, which you can reuse in your next game.

7. You forgot that in your RMGUI you probably at some point feed the mouse events and other events into it (unless you let it take over the whole OS-event-loop). There it internally does lots of logic at that point. Thats where you could also call a function for the IMGUI to do its logic, and I don't see a problem with this, as it would be the same. Then later in your graphics engine you might do the same draw call.

Edited by wintertime

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5
• ### Forum Statistics

• Total Topics
631703
• Total Posts
3001814
×