Adding some GUI to OpenGL

Started by
16 comments, last by BitMaster 8 years, 6 months ago

I love the simplicity of IMGUIs. The extensibility of the Unity editor is a testament to that.

Need a custom editor window? Just write a few lines and you are done.

I couldn't imagine however implementing a complex game UI in that fashion with artist-crafted graphics, particle effects and other stuff.

Advertisement

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.

I'll treat each paragraph as a bullet point, all are addressed:

1) Every RMGUI i've worked on (in games or otherwise) get overly complicated. It's inevitable. The most important thing in game development is iteration time, IMGUI tend to be quicker for this.

2) You can rebuild vertex buffers on invalidation sure, you should do that whether RM or IM. The topic is really about "what it takes to get my game gui done", both options have similar optimisations. I'm not sure what you mean by regions.

3) There isn't much practical need to decouple display and logic. The games ive worked on have had heavy XML driven RMGUI front ends and the artists and designers barely go near it. A well thought out IMGUI interface can produce code that is as easy to read as XML. If artists want to change the size of something they'll just look for the name and numbers wherever theyre declared.

4) Not sure about this but in my experience having callbacks registered to events etc gets very messy and it hard to track what is listening to what.

5) Surely when you call draw on your RMGUI it is fast enough that it doesn't hiccup the framerate much right? If so then just do it every frame. My IMGUI (fairly optimised) runs at around 1ms on reasonable hardware for my level editor. This is content that is much more complicated than any typical game GUI with health bars and so on. Also you don't change that code, it's completely generic for all UIs made with any given IMGUI.

6) They do move the problem to a certain degree but the fundamental benefits are that its easy to write new client UI content and you don't have application state stored in your UI widgets because they don't exist.

It's perfect for realtime applications.

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.

4. This _generally_ doesn't work because your logic is embedded. If you try too hard to declare logic in the XML you end up writing a bunch of rules that are interpretted and processed as actual logic when running your UI and so you may as well just do it in your GUI code. If your UI is command driven than you can do things like declared your menu buttons and specify a command that should be run when its clicked.

6. Yep this is basically the whole point.

wow this post is growing stronger! thanks for all the answers. smile.png
I want to add an OS based GUI.
This is a new concept for me, every application runs a native User interface, that's why i said:

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?

So, i'll go with wxwidget, which is crossplatform, but is RMGUI. I like the approach of IMGUI now

correct me if I'm wrong!

-> A win32 application used the win32 API to open a window

-> opengl by itself can't create a window

-> Only the OS can create a windows

So Can I made an entire editor with wxwidget (for example) and read inputs from sdl at the same time? Would there be a problem? (because wxwidget and SDL reads messages from the OS)

Again thanks!

Regards!

If you want OS native looked widgets and you want to be portable, you probably want QT or wxwidget.

You can mix SDL with those, thought there might be some hoops to jump through with handling events but nothing bad.

I totally understand the appeal to conform to a standard set of widgets. Now - QT is very powerful and featureful but it is an enormous thing (5 GB+ install). In my experience the problem with those big things is that it scares off lots of people in your team and you end up with 10% of the people ever looking at the project with the UI (if you have multiple projects running). It also make many things quite tedious to make IHMO. With a custom library like ImGui, many things are easier to make, and some are more tricky but you benefit from a less steep usage and learning curve, and you can create tools anytime more naturally without planning things out. wxwidget apparently is less unwieldly but I have never used it myself.

You may want to consider a few questions:

- is your app going to be short-lived or meant to be active for a very long time?

- is it small or big? simple or complex?

- will your app be used internally, for content-creators and technically minded people, or by your mother in law?

- will it have 10 users, 1000 users, one million user?

- will it have 1 developer, 10 developers, 100 developers? will they be a tight team or people coming and going?

Based on this you can better weight the trade-off of going for something more in the standard and "correct" spectrum or something more in the practical and "clunky" spectrum.

For the majority of app, having native OS widgets would ideally be better than non-native OS widgets. However you have to consider how it impact your development. Bad UI code can also become a bottleneck to your development and then you don't add feature xx or yy just become the UI is a pain to deal with. That happens everyday.

Recently I had to rewrite an old desktop-ey always-on app from a codebase that uses both Win32 and QT for standalone tools.

I bite the bullet and tried for the first time to use ImGui (which I wrote) instead of adopting QT.

The result is that I get an app that's not standard and a bit odd and has its limitation, but writing ui seems 100 times easier and everyone in the team can touch it.

Screenshot from that app: (not actually a fullscreen shot, that was a gif I made to demonstrate a feature)

1864a2c2-70df-11e5-9ce8-2acddc030f71.gif

that's a good looking gui

I will be the only user of my future tool app cool.png

I just want to add some properties panel and a menu, that's all for now, and of course a Opengl scene view (in qt this is called GL widget)

I was checking qt and something like this is what a want :
the qt creator is great , not only for qt, also as an c++ IDE, right now I'm using MSVS 2013 community , and some qt libs, for now it works pretty well, and its so easy to code, although still I don't understand what is happening in the background. With my cpp + Glew I can specify where the main loop is going to be, now in qt i don't have any idea.
In the video above use repaingGL for this (i think)
How did you make you own imgui? is there any tutorial out there? i don't what nothing complicated, only the basics
regards

My imgui was linked above https://github.com/ocornut/imgui

There's a few links on that github page in the "References" paragraph, if you have the time to read them you'll understand lots of imgui principles better.

If you want to write your own, those links will help you. For basic things such as clickable button you can make you own in a matter of minutes. For something really fancy it's like any project - it can become an infinite time sink (I spent many months on mine).

One advantage of QT is that it comes with a million non-GUI things, it's almost an engine for non-gamey thing. So if you don't have much code already done you can use that and it can be very helpful as long as you are happy with the dependency. Wouldn't hurt giving it a go and pushing QT + QT Creator and see how you feel.

In the interest of satisfying my own personal demons, the framework you are talking about is called 'Qt', not 'QT'.

This topic is closed to new replies.

Advertisement