Allegro.cc - Online Community

Allegro.cc Forums » Allegro.cc Comments » Suggesting to add imgui to GUI libraries

This thread is locked; no one can reply to it. rss feed Print
Suggesting to add imgui to GUI libraries
Alianix
Member #10,518
December 2008
avatar

Wouldn't it be good to add imgui:

https://github.com/ocornut/imgui

to

allegro.cc/resource/Libraries/GUI

?

I tried it and it works well with Allegro.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Alianix
Member #10,518
December 2008
avatar

I haven't been on the forum for a few years, well I thought it's worth a note...

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

everything on allegro.cc is out of date, the binaries, the docs, the depot submissions, everything

While I don't feel a need to knock imgui, I always had low fps, and high cpu when I tried their demo programs.

and, there are a lot of other guis floating out there too, mine included

Alianix
Member #10,518
December 2008
avatar

I see very low CPU with their demos, so I'm curious how you got high? I only tried under Linux though. I don't know of any other immediate mode GUI library that works with opengl/allegro and C/C++ that is as good as ImGUI. But yes there are a lot of outdated unmaintained GUIs out there for sure...

I checked out your GUI demo4 and 5 under Windows and it worked OK.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Given it was an older laptop, that could have been the problem. But I was getting literally 5 fps and max cpu.

In my opinion the whole idea of an immediate mode gui is ridiculous. You spend every frame over and over recreating the same data structure, needlessly wasting cpu.

A better measure of a GUI is how customizable it is, whether you can skin it, whether you can configure it easily, etc...

Because under the hood, they're all the same basic widgets, just written with a different style in mind.

Alianix
Member #10,518
December 2008
avatar

If the GUI state becomes complex it's not so easy and efficient to use dirty rectangles or sprites and the game or other logic+rendering also requires drawing layers etc...I don't see how you can get away with not drawing everything anyway these days unless your app is a very simple game with a few layers. By the time you track state and patch your layers it's not much better or perhaps worse I think not to mention the extra coding...I actually was not positive about the re-drawing myself but it works really well and the app is at ~7% CPU with the demo maxed out which has complex set of widgets @60FPS, you can try it for yourself it's interesting.

Chris Katko
Member #1,881
January 2002
avatar

Also, imgui is C++. Allegro could have a plugin/addon but you could not integrate it into Allegro directly which is C only.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Alianix
Member #10,518
December 2008
avatar

Right, the creators of imgui have implemented their GUI on top of Allegro. So getting started with it and Allegro is really simple if you already have Allegro.

jmasterx
Member #11,410
October 2009

mmmmm GUI Thread! :)

Alianix
Member #10,518
December 2008
avatar

Thanks for the heads up, I checked out the demo and Agui looks like a really nice looking functioning library, great work. However I noticed then when running idle with a single calculator it consumes what seems to be an excessive amount of CPU. On my windows 8 (64) box it's ~3.5% per core times the number of calculators. Relative to imgui this seems to be a quite a bit, I'm getting only about 2% in imgui full demo mode and there's a lot of widgets and changes going on (all the examples running). There is probably a good explanation for this.

Chris Katko
Member #1,881
January 2002
avatar

For one, make sure you're actually measuring something you care about.

Benchmarks don't automatically mean anything. This is not a personal opinion.

Do you care about idle %, or do you care about performance when you're actually drawing something?

Measure a real case that is similar to what you'd use in a real product, with identical environments (no extra apps running).

2% and 3% on modern computers is within the margin of error with literally anything. It could be CPU scheduling. It could be another program messing with the cache. It could be differently coded example programs.

The book (of many editions printed) "Computer Organization and Architecture" by the famous William Stallings, goes directly in the first chapters "What is a benchmark?" and opened my mind on it. I've seen other competition experts on blogs/articles that have said the phrase, "Good benchmarks are hard to write." You may be able to find Stallings book for free in PDF form online. I've purchased multiple older editions to compare them for $3 or so each.

So while it's entirely possible one is "faster" than the other. You have to first qualify, what does "faster" mean? CPU usage? Draw rate? Number of simultaneous objects?

Even the tools you use to measure can be faulty! A program could "spike" usage faster than a tool reports and it only reports the smaller average. And much worse!

And further, you also have to ask whether performance (of 10/20/30%) even matters. At the end of the day, can you easily reason about and debug a program written with your chosen API? If one is 30% faster, but looks ugly-as-hell and is prone to breaking on many users machines, is it better? Maybe.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Alianix
Member #10,518
December 2008
avatar

Of course I agree with all that, and obviously my benchmark if it can be even called that is nothing rigorous, just the results left me perplexed as it seems to me there are a lot more going on in the imgui demo, I haven't looked at your library implementation just assumed that you probably also draw everything each frame. I will have to look into it myself to get clear answers I guess...And yes idle cycles are very important for me as well as rendering cost and in general for my projects so re-drawing everything is a chunk to swallow with imgui or anything else. I don't really care how something is implemented as long as it's efficient and straight forward enough to use. In the case of GUIs I think it's obvious that handling individual widgets is a good measuring stick: the more individual widgets the more work/cycles. If one draws 10 widgets while the other handles 100 at the same CPU cost that's a perplexing situation, even if one is using shading or not, that is done in the GPU, also size of widgets shouldn't matter for the same reason...

By the time I finished writing all this I built Agui under Linux from git with a few CMakeLists hacks and then the example for allegro5, here is the issue just so you know apart from having to add allegro5 includes and libraries:

[ 90%] Building CXX object CMakeFiles/agui_allegro5.dir/src/Agui/Backends/Allegro5/Allegro5Font.cpp.o
/usr/bin/c++ -DALLEGRO_STATICLINK -O2 -DNDEBUG -o CMakeFiles/agui_allegro5.dir/src/Agui/Backends/Allegro5/Allegro5Font.cpp.o -c /home/alian/local/Agui/src/Agui/Backends/Allegro5/Allegro5Font.cpp
/home/alian/local/Agui/src/Agui/Backends/Allegro5/Allegro5Font.cpp:41:10: fatal error: Agui/Backends/Allegro5/Allegro5Font.hpp: No such file or directory
#include "Agui/Backends/Allegro5/Allegro5Font.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

So after that I ran the agui_example_a5 and saw double the CPU vs imgui, looking at the source code (few widgets rendered) I'm again perplexed but still looking, any ideas or should I disect this further?

jmasterx
Member #11,410
October 2009

First of all, Agui's calculators demo uses 9 patch images and fairly big, suboptimal textures. It's a demo. But the api is designed so you can override the paint() calls and do it however you want.

I would not be concerned with 2 vs 3% cpu usage. These libraries are made to be incorporated in games running 60 fps. It's not made to render on changes.

But since Agui is event based you could technically only redraw the screen when any event occurs.

I believe use the tool that will let you be most productive. On a modern cpu, immediate vs stateful gui is negligible.

Cache misses cost wayyyyyyyy more.

If you need something to really only redraw when needed check out libraries like QT which are designed to work with a message pump.

Never choose a library based on the fact that one unoptimized demo performs marginally better than another.

Here is one of my most popular SO questions: https://stackoverflow.com/questions/2217524/how-are-3d-games-so-efficient

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Chris Katko
Member #1,881
January 2002
avatar

Oh hey, one more think I remembered but forgot to add to my post!

When you're benchmarking lower/idle CPU/GPU state watch your clockrates!!!!!!! This is an absolute requirement.

Any time you run something that yields back to the time scheduler instead of running wide-open as fast as it can, may not do enough actual work to make the CPU engage higher clock rates. You may be using as little CPU as a "background service" from the perspective of a particular CPU core, and it'll just stay in low (or lower) power mode. Under-rating voltage and/or frequency.

You absolutely MUST disable all power scaling features of your CPU if you're going to measure idle / low CPU usage with any accuracy.

And even if you're doing wide-open, you may engage "turbo mode" which shuts off cores and overclocks the remaining cores. The problem there is, you may think you're running as-fast-as-possible but then you add some more threads to use more CPU cores and all the cores suddenly get slower because they can't use turbo mode anymore! :o

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: