ImGui integration

hey i am from svifylabs and
I am currently working on an integration of ImGui to Urho3D.
I opened an issue for this and was told to open a thread for this too … so here i am ^^

The imgui integration as of now works for windows, have to test android and linux. (helpers always welcome)
The ImGui library is not fully wrapped in the IMUI class so you have to use the ImGui namespace for the ui elements and include “imgui/imgui.h”.
You can use the ImGui functions between the BeginFrame and EndFrame event.
ImGui uses their own font implementation so you have to load the fonts manualy and it uses an ini file for saving the position and size of the generated windows between app sessions.

There some todos i am working on but it should work for now.

For those who want to help:

  • look through the IMUI::RenderDrawLists function, you coudl find a better way to render the provided data …
  • how can i tell cmake to use ImGui not as an library but copy the source into Urho3d so we can use the provided imconfig.h for converting Uhro3d Vector2/4 to ImVec2/4 classes.
  • should i wrap all ImGui functions ? if so should i use static funtions for that ?
  • i dont think Lua or angelscript bindings are needed ? ?


I believe wrapping everything is wasted work if script bindability is not a goal. Ie. a C++ user can just as well use the library directly.

ok that is what i thought.

I think it gives me the opportunity to not care about binding imgui to Urho.

And also the ability to modify or create my own functions.
But there are two ways: modify IMUI or imgui_user.

Perhaps IMUI could be as translator for imgui in Urho (fonts, vectors, render etc.)
And can be provide an interface for modification as it makes imgui using imgui_user files.

(it’s just reflections)

I have tested the newest source code, and it works on linux just fine.

Text icons can placed as UTF-8 characters

In HelloIMUI code:
// ImGui::Text("\uF04B"); isn’t correct it is 16-bit unicode whereas ImGui takes UTF-8.
// so use in c++11 use u8"\uf016" or
ImGui::Text("\xef\x80\x96" " Line A"); // use string literal concatenation, ouputs a file icon and File as a string

I found big list of all UTF-8 characters. It help understand how it use.
utf8-chartable.de/unicode-ut … ng-literal
@ - \x40
A - \x41
B - \x42
C - \x43
D - \x44
etc.

It very useful addon.
Icons save screen space (not need draw long string) - only single symbol (can be with tooltip)
Also, not used big memory how it do full-color icons. And you can change color of icons.

Compilation on XP, OpenGL, MinGW (GCC) have small c++11 warnings:

imconfig.h

warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11

struct ImDrawVert
{
ImVec2 pos;
[b]float z = 0.0f;[/b]
ImU32 col;
ImVec2 uv;
};

HilloIMUI.cpp strings 218, 219, 220, 221.

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11

static ImVec2 point1[3] = { {0.10f,0.0f},{ 0.0f,0.0f} , {.0f,.10f} };
static ImVec2 point2[3] = { { 0.0f,0.0f },{ 0.0f,0.0f } ,{ .0f,.10f } };
static ImVec2 point3[3] = { { 0.0f,0.0f },{ 0.0f,0.0f } ,{ .0f,.0f } };
static ImVec2 point4[3] = { { 0.10f,0.0f },{ 0.0f,0.0f } ,{ .0f,.10f } };

But, It compiles and runs well.

Need easy way to set text color for Title, Button, Header. Or may be this method already exists?
Begin(“Title text”)
CollapsingHeader(“Header Text”)
Button(“Button text”, ImVec2(100.0f, 20.0f))

If i do them dark color and default text also dark colored - text will be unreadable.
The same otherwise.

I really like the curve editor it is really good for animation curves and for interpolation visualization.

What you think about integration dockable windows from ImWindow to IMUI?
ImWindow - github.com/thennequin/ImWindow

I think - it is not imgui part, but it can be IMUI window manager.
And also, it can be switchable (enable/disable) managment during compilation or runtime.

Is it C++98 backward compatable?

You have compilation problems?
I have only small c++11 warnings.

I do small hacks in RenderFrame() function in imgui for Border 3D effects.
On screenshots you can see borders-effects for Headers, Buttons, Input areas.
Dark theme

Light theme

Hi

What is the URHO equivalent example file? Is it the DEMO file in the Thirdparty folder?

Vivienne

Hi,

Do anyone know what’s up with this error?

i.imgur.com/gveww9I.png

I’m trying.

github.com/svifylabs/Urho3D/tre … ThirdParty

I am getting compile errors on those specific lines. I’m assuming the code worked on prior Urho3D versions.

Viv

Hi

This is the compile error attempting to implement IMGUI placed in AlphaEngine and tested in the beginning part of AlphaEditor. It could be applied to Urho3D fully once working if anyone wants to. I’m doing it as a LogicComponent allowing muiltiple instances of the GUI to be run possibly.

pastebin.com/sNNg9hf0

This is the base code I’m testing it on.

github.com/vivienneanthony/MyFo … evelopment

Vivienne

Error with Draw() function:

IMUI add small changes to Urho.

First step
In OGLGraphics (cpp, h) add his version of Draw() function.

Second step
And in Engine.cpp (in Engine::Initialize() function)
context_->RegisterSubsystem(new IMUI(context_));

Second step can be easy moved in you code (removed from Engine code)
Is all changes. And only new GLSL HLSL files in Data folder.


Border effect was discussed in github.com/ocornut/imgui/issues/447

[quote=“globus”]Error with Draw() function:

IMUI add small changes to Urho.

First step
In OGLGraphics (cpp, h) add his version of Draw() function.

Second step
And in Engine.cpp (in Engine::Initialize() function)
context_->RegisterSubsystem(new IMUI(context_));

Second step can be easy moved in you code (removed from Engine code)
Is all changes. And only new GLSL HLSL files in Data folder.


Border effect was discussed in github.com/ocornut/imgui/issues/447[/quote]

Hmmm. Thanks. I’m going copy the Draw functions and rename so the original code stays. I’m rebuilding now so I’ll see what happens once it finishes.

You can also compare Urho master branch and f_imgui branch to see all changes
github.com/urho3d/Urho3D/compar … bs:f_imgui
But, it big and heavy loadable Html page.

[quote=“globus”]You can also compare Urho master branch and f_imgui branch to see all changes
github.com/urho3d/Urho3D/compar … bs:f_imgui
But, it big and heavy loadable Html page.[/quote]

I wish it was that simple.

Covering the steps you mentioned.

  1. Updated the functions which still did not resolve the DrawList so I betting it’s a memory issue.

  2. Update the syntax to

    // Get the game client context
    context_->RegisterSubsystem(new ImGuiInterface(context_));
    m_pGuiInterface = context_->GetSubsystem<ImGuiInterface>();[/code]

The first  part is not needed. I think but I still added.

Bug

1. I'm think the ImGuiInterface is not created hence the failure with this part.  (Possibly *this is invalid)

[code]Program received signal SIGSEGV, Segmentation fault.
Urho3D::String::Append (this=this@entry=0x7fffffffd160, str=...) at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/Urho3D/Container/Str.cpp:310
310         return *this += str;
(gdb) bt 5
#0  Urho3D::String::Append (this=this@entry=0x7fffffffd160, str=...)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/Urho3D/Container/Str.cpp:310
#1  0x0000000000d712af in ImGuiInterface::SetSettings (this=0x24804a0, settings=...)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEngine/Interfaces/ImGui/ImGuiInterface.cpp:173
#2  0x00000000007899ab in Editor::Create (this=0x17c0e70, scene=0x23958a0, sceneUI=0x24bf170)
  1. Removing the set settings out the editor part. So I’m not sure if it’s another memory list which I don’t think DrawList is part of the Unity functions but ImGui specific.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000d45da2 in ImGui::Begin (name=name@entry=0x10ce4d6 "Hello", p_opened=p_opened@entry=0x0, size_on_first_use=..., bg_alpha=0.699999988, 
    bg_alpha@entry=-1, flags=flags@entry=0) at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEngine/ThirdParty/ImGui/imgui.cpp:3667
3667            window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
(gdb) bt 5
#0  0x0000000000d45da2 in ImGui::Begin (name=name@entry=0x10ce4d6 "Hello", p_opened=p_opened@entry=0x0, size_on_first_use=..., bg_alpha=0.699999988, 
    bg_alpha@entry=-1, flags=flags@entry=0) at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEngine/ThirdParty/ImGui/imgui.cpp:3667
#1  0x0000000000d496b5 in ImGui::Begin (name=name@entry=0x10ce4d6 "Hello", p_opened=p_opened@entry=0x0, flags=flags@entry=0)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEngine/ThirdParty/ImGui/imgui.cpp:3544
#2  0x000000000078a696 in Editor::Create (this=0x24a0bd0, scene=<optimized out>, sceneUI=<optimized out>)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEditor/Core/Editor/Editor.cpp:356
#3  0x000000000072d9b3 in MainEditorView::EditorInstance (this=0x2396a30)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEditor/GameView/MainEditorView.cpp:115
#4  0x000000000072cfa5 in MainEditorView::FinishIntroductionPartDelegate (this=0x2396a30, eventType=..., eventData=...)
    at /media/home2/vivienne/Urho3D-Hangars-MyForkEditor/Source/AlphaEditor/GameView/MainEditorView.cpp:76
(More stack frames follow...)