Sign in to follow this  
lightbug

OpenGL Adding some GUI to OpenGL

Recommended Posts

lightbug    123

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:

 

1 - Should I download a free gui library (c++) or made one with SDL?

 

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? 

 

In any case, I would appreciate a good book about this specific topic

 

 

Thanks and sorry for the english happy.png

Edited by lightbug

Share this post


Link to post
Share on other sites
Glass_Knife    8636


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 this post


Link to post
Share on other sites
lightbug    123

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")

 

 

See this link : http://gamedev.stackexchange.com/questions/24103/immediate-gui-yae-or-nay

 

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

Share this post


Link to post
Share on other sites
alh420    5995

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 this post


Link to post
Share on other sites
wintertime    4108

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 this post


Link to post
Share on other sites
dave    2187

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 this post


Link to post
Share on other sites
alh420    5995

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 this post


Link to post
Share on other sites
wintertime    4108

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

Share this post


Link to post
Share on other sites
Madhed    4095

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.

Share this post


Link to post
Share on other sites
dave    2187

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.

Share this post


Link to post
Share on other sites
dave    2187

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.

Share this post


Link to post
Share on other sites
lightbug    123
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!

Edited by lightbug

Share this post


Link to post
Share on other sites
ocornut    383

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

Edited by ocornut

Share this post


Link to post
Share on other sites
lightbug    123

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 :
 
 https://www.youtube.com/watch?v=1nzHSkY4K18
 
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
Edited by lightbug

Share this post


Link to post
Share on other sites
ocornut    383

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
    • By Picpenguin
      Hi
      I'm new to learning OpenGL and still learning C. I'm using SDL2, glew, OpenGL 3.3, linmath and stb_image.
      I started following through learnopengl.com and got through it until I had to load models. The problem is, it uses Assimp for loading models. Assimp is C++ and uses things I don't want in my program (boost for example) and C support doesn't seem that good.
      Things like glVertexAttribPointer and shaders are still confusing to me, but I have to start somewhere right?
      I can't seem to find any good loading/rendering tutorials or source code that is simple to use and easy to understand.
      I have tried this for over a week by myself, searching for solutions but so far no luck. With tinyobjloader-c and project that uses it, FantasyGolfSimulator, I was able to actually load the model with plain color (always the same color no matter what I do) on screen and move it around, but cannot figure out how to use textures or use its multiple textures with it.
      I don't ask much: I just want to load models with textures in them, maybe have lights affect them (directional spotlight etc). Also, some models have multiple parts and multiple textures in them, how can I handle those?
      Are there solutions anywhere?
      Thank you for your time. Sorry if this is a bit confusing, English isn't my native language
  • Popular Now