• Advertisement
Sign in to follow this  

OpenGL Adding some GUI to OpenGL

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

If you intended to correct an error in the post then please contact us.

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:

 

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
Advertisement

 

OMG is that simple:

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

then i can start drawing GUI things biggrin.png

 

 

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

 

Thanks!

Share this post


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


Link to post
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")

 

 

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

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

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

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

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

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

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

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

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

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

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

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
In the interest of satisfying my own personal demons, the framework you are talking about is called 'Qt', not 'QT'.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By khawk
      We've just released all of the source code for the NeHe OpenGL lessons on our Github page at https://github.com/gamedev-net/nehe-opengl. code - 43 total platforms, configurations, and languages are included.
      Now operated by GameDev.net, NeHe is located at http://nehe.gamedev.net where it has been a valuable resource for developers wanting to learn OpenGL and graphics programming.

      View full story
    • By TheChubu
      The Khronos™ Group, an open consortium of leading hardware and software companies, announces from the SIGGRAPH 2017 Conference the immediate public availability of the OpenGL® 4.6 specification. OpenGL 4.6 integrates the functionality of numerous ARB and EXT extensions created by Khronos members AMD, Intel, and NVIDIA into core, including the capability to ingest SPIR-V™ shaders.
      SPIR-V is a Khronos-defined standard intermediate language for parallel compute and graphics, which enables content creators to simplify their shader authoring and management pipelines while providing significant source shading language flexibility. OpenGL 4.6 adds support for ingesting SPIR-V shaders to the core specification, guaranteeing that SPIR-V shaders will be widely supported by OpenGL implementations.
      OpenGL 4.6 adds the functionality of these ARB extensions to OpenGL’s core specification:
      GL_ARB_gl_spirv and GL_ARB_spirv_extensions to standardize SPIR-V support for OpenGL GL_ARB_indirect_parameters and GL_ARB_shader_draw_parameters for reducing the CPU overhead associated with rendering batches of geometry GL_ARB_pipeline_statistics_query and GL_ARB_transform_feedback_overflow_querystandardize OpenGL support for features available in Direct3D GL_ARB_texture_filter_anisotropic (based on GL_EXT_texture_filter_anisotropic) brings previously IP encumbered functionality into OpenGL to improve the visual quality of textured scenes GL_ARB_polygon_offset_clamp (based on GL_EXT_polygon_offset_clamp) suppresses a common visual artifact known as a “light leak” associated with rendering shadows GL_ARB_shader_atomic_counter_ops and GL_ARB_shader_group_vote add shader intrinsics supported by all desktop vendors to improve functionality and performance GL_KHR_no_error reduces driver overhead by allowing the application to indicate that it expects error-free operation so errors need not be generated In addition to the above features being added to OpenGL 4.6, the following are being released as extensions:
      GL_KHR_parallel_shader_compile allows applications to launch multiple shader compile threads to improve shader compile throughput WGL_ARB_create_context_no_error and GXL_ARB_create_context_no_error allow no error contexts to be created with WGL or GLX that support the GL_KHR_no_error extension “I’m proud to announce OpenGL 4.6 as the most feature-rich version of OpenGL yet. We've brought together the most popular, widely-supported extensions into a new core specification to give OpenGL developers and end users an improved baseline feature set. This includes resolving previous intellectual property roadblocks to bringing anisotropic texture filtering and polygon offset clamping into the core specification to enable widespread implementation and usage,” said Piers Daniell, chair of the OpenGL Working Group at Khronos. “The OpenGL working group will continue to respond to market needs and work with GPU vendors to ensure OpenGL remains a viable and evolving graphics API for all its customers and users across many vital industries.“
      The OpenGL 4.6 specification can be found at https://khronos.org/registry/OpenGL/index_gl.php. The GLSL to SPIR-V compiler glslang has been updated with GLSL 4.60 support, and can be found at https://github.com/KhronosGroup/glslang.
      Sophisticated graphics applications will also benefit from a set of newly released extensions for both OpenGL and OpenGL ES to enable interoperability with Vulkan and Direct3D. These extensions are named:
      GL_EXT_memory_object GL_EXT_memory_object_fd GL_EXT_memory_object_win32 GL_EXT_semaphore GL_EXT_semaphore_fd GL_EXT_semaphore_win32 GL_EXT_win32_keyed_mutex They can be found at: https://khronos.org/registry/OpenGL/index_gl.php
      Industry Support for OpenGL 4.6
      “With OpenGL 4.6 our customers have an improved set of core features available on our full range of OpenGL 4.x capable GPUs. These features provide improved rendering quality, performance and functionality. As the graphics industry’s most popular API, we fully support OpenGL and will continue to work closely with the Khronos Group on the development of new OpenGL specifications and extensions for our customers. NVIDIA has released beta OpenGL 4.6 drivers today at https://developer.nvidia.com/opengl-driver so developers can use these new features right away,” said Bob Pette, vice president, Professional Graphics at NVIDIA.
      "OpenGL 4.6 will be the first OpenGL release where conformant open source implementations based on the Mesa project will be deliverable in a reasonable timeframe after release. The open sourcing of the OpenGL conformance test suite and ongoing work between Khronos and X.org will also allow for non-vendor led open source implementations to achieve conformance in the near future," said David Airlie, senior principal engineer at Red Hat, and developer on Mesa/X.org projects.

      View full story
    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
  • Advertisement