Ogre ImGui binding

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Ogre ImGui binding

Post by Crashy » Tue Sep 06, 2016 1:00 pm

Hi everybody,

I've just released my quick and (not so) dirty integration of imgui in ogre. I'm using it with Ogre 2.0 and GL3+/D3D11 render systems, but it may work with other ogre versions and/or D3d9 with minor modifications.
Now it works with Ogre 1.x too, and in D3D9, D3D11 & Gl 3+

Disclaimer: this is my very first release of open source code, so feel free to comment about improvements/fixes :)

http://bitbucket.org/LMCrashy/ogreimgui/overview

screenshot:
imguiogre.jpg
From the readme:

Integration

Create and init the ImguiManager after your Ogre init:

Code: Select all

ImguiManager::createSingleton();
ImguiManager::getSingleton().init(mSceneMgr,mOISKeyboardInput,mOISMouseInput);
Then in your render loop:

Code: Select all

ImguiManager::getSingleton().newFrame(getDeltaTime(), Ogre::Rect(0,0,_getRenderWindow()->getWidth(),_getRenderWindow()->getHeight()));
And voilà !

You can then use imgui just like you want.

Note

You'll also need to transfer input events from your OIS Input listener to the Imgui manager.
For example:

Code: Select all

bool MyInputManager::mouseMoved( const OIS::MouseEvent &arg )
{
    Ogre::ImguiManager::getSingleton().mouseMoved(arg);
}
Last edited by Crashy on Fri Sep 09, 2016 10:05 am, edited 2 times in total.
1 x
Follow la Moustache on Twitter or on Facebook
Image

User avatar
insider
Orc
Posts: 462
Joined: Thu Sep 15, 2011 12:50 pm
x 2

Re: Ogre ImGui binding

Post by insider » Tue Sep 06, 2016 3:53 pm

Excellent :D
0 x

hydexon
Gremlin
Posts: 164
Joined: Sun Apr 14, 2013 8:51 pm
x 1

Re: Ogre ImGui binding

Post by hydexon » Wed Sep 07, 2016 2:35 am

OH DEAR GOD, Thanks you so much!
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1064
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 83

Re: Ogre ImGui binding

Post by xrgo » Wed Sep 07, 2016 2:50 am

Fantastic!! thanks for sharing =D!
0 x

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Wed Sep 07, 2016 8:43 am

Thanks for your positive feedback.

I've just made some changes to use unified gpu programs, and I can also confirm it works with the D3D11 Render System.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Fri Sep 09, 2016 10:11 am

Aaaand now I've fixed build issues with Ogre 1.x and added D3D9 shaders.
0 x
Follow la Moustache on Twitter or on Facebook
Image

chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm

Re: Ogre ImGui binding

Post by chaos creator » Sun Sep 18, 2016 8:50 pm

A few days ago I saw your post, searched for ImGUI and was surprised that I haven't seen it earlier.
So I immediately started trying to port it to Ogre 2.1 since that's what I'm currently porting.

First of all, your code was very legible and easy to understand, without it I don't even know if I would have even tried writing my own binding ;)

But unfortunately some things didn't work under Ogre 2.1
So first I tried doing everything the correct "v2 way" - which was way too complicated.
Using vao's and creating a movable object and renderables didn't work out for me (at least in the short amout of time I spent on it)
(BTW, there is a bug in your GLSL shader where you output "ocol" in the vertexshader but try to input "col" in the fragmentshader)

One of the issues render queue listeners: only renderQueueStarted is called (for the Ogre overlays to work),
so the listeners are basically useless :(

Then I had to modify the setting of the used Pass to use a hlms macro- and blendblock.
Also the correct blend mode was ignored by the render system, so I had to set it manually.


I'm not exactly sure how much I changed in the end, but I suspect your version and my 2.1 port differ to much to bundle it into one repro (also I changed some things to my own coding style :D)


Sooo.... I'll just show my own version ;)

Image

https://bitbucket.org/ChaosCreator/imgu ... inding/src


Usage

Just init ImguiManager once after you init Ogre:

Code: Select all

ImguiManager::getSingleton().init(mSceneManager);
... and that's about it.
No need to include anything else (besides the 4 source files)

Don't call Imgui::newFrame() or Imgui::render() or something similar, the ImguiManager does it for you.
Also be aware that it just renders the GUI in the middle of frameRenderingQueued.

Besides that: you can now call all your Imgui functions and the results are immediately shown.


Input

Nearly forgot to say...
You have to do that part yourself (at least for now)
I removed the OIS part as I'm using SDL. SDL has no listeners, so I see no point of handling input in the ImguiManager itself.
Basically you need to update the Imgui key- and mousestate within your own code, but that is completely unrelated to ogre.

And after all, the gui should also be seperated from the input system of your choise ;)



@Crashy
I also use the Imgui clipping data to set the scissoring tests accordingly ;)
You might look into that, but it means splitting the Renderables much more finely since clipping is performed on every Gui element
0 x

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Thu Sep 29, 2016 12:02 am

Yay! I was almost determined to begin researching and integrating DearImgui and OGRE myself, but now I can just remain lazy.

Many thanks for both the 2.0 and 2.1 variant.
0 x
Rigs of Rods is alive and kicking!

hydexon
Gremlin
Posts: 164
Joined: Sun Apr 14, 2013 8:51 pm
x 1

Re: Ogre ImGui binding

Post by hydexon » Sun Oct 16, 2016 2:31 am

I have a little issue to trying it on Windows 10, OGRE 2.1/D3D11, OGRE throws an exception, about an sampler0 is not found when you set the named constant in ImGuiManager::createMaterial(), line 441.

The relevant log about the exception was:

Code: Select all

Invalid target for D3D11 shader 'imgui/VP/D3D9' - 'vs_2_0'
Invalid target for D3D11 shader 'imgui/FP/D3D9' - 'ps_2_0'
Exception thrown at 0x00007FFFFDCB7788 in DragoraCarbon.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x000000DED57CD510.
Unhandled exception at 0x00007FFFFDCB7788 in DragoraCarbon.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x000000DED57CD510.
i'm using the "chaos creator" version, i wonder why is using D3D9 as their default version when i'm using D3D11 version.
0 x

einherjer
Gnoblar
Posts: 11
Joined: Wed Sep 09, 2009 10:47 am

Re: Ogre ImGui binding

Post by einherjer » Sun Oct 23, 2016 1:33 pm

Same problem for me with the OGRE 2.1 version:
14:31:07: OGRE EXCEPTION(2:InvalidParametersException): Parameter called sampler0 does not exist. Known names are: in GpuProgramParameters::_findNamedConstantDefinition at C:\OgreSDK\OgreMain\src\OgreGpuProgramParams.cpp (line 2214)
If I am commeting out the following line

Code: Select all

mPass->getFragmentProgramParameters()->setNamedConstant("sampler0", 0);
I am getting the following error when trying to render the GUI:
14:40:49: OGRE EXCEPTION(3:RenderingAPIException): D3D11 device cannot draw indexed
Error Description:ID3D11DeviceContext::DrawIndexed: A Vertex Shader is always required when drawing, but none is currently bound.
Active OGRE vertex shader name: imgui/VP/D3D11
Active OGRE fragment shader name: imgui/FP/D3D11 in D3D11RenderSystem::_render at C:\OgreSDK\RenderSystems\Direct3D11\src\OgreD3D11RenderSystem.cpp (line 3330)
What are we doing wrong (OGRE 2.1, D3D11, 64 bit, statically linked)?
0 x

chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm

Re: Ogre ImGui binding

Post by chaos creator » Fri Oct 28, 2016 12:09 pm

Does it work under OpenGL?
I never used D3D11 because Ogre crashed even when I only included the Plugin.
Probably I should look into it, but because OpenGl is crossplattform I saw no problem in switching to it.

So unfortunatly right now I can't even search for the reason for the crash - but at least it was never guaranteed to work ;D

If you can try openGl I would be happy to hear if it worked :)
0 x

hydexon
Gremlin
Posts: 164
Joined: Sun Apr 14, 2013 8:51 pm
x 1

Re: Ogre ImGui binding

Post by hydexon » Fri Oct 28, 2016 10:55 pm

chaos creator wrote:Does it work under OpenGL?
I never used D3D11 because Ogre crashed even when I only included the Plugin.
Probably I should look into it, but because OpenGl is crossplattform I saw no problem in switching to it.

So unfortunatly right now I can't even search for the reason for the crash - but at least it was never guaranteed to work ;D

If you can try openGl I would be happy to hear if it worked :)
Doesn't work in OpenGL (in Windows), but unlike DX11, they don't crash but don't display anythying from ImGui ( called ImGui::ShowTestWindow() just after setting up ImGui ), the Log output throws OpenGL Error such GL_BIND something is invalid.
0 x

john21wall
Gnoblar
Posts: 1
Joined: Wed Nov 02, 2016 12:40 pm

Re: Ogre ImGui binding

Post by john21wall » Wed Nov 02, 2016 3:29 pm

Hi guys, I am currently working with a program which implements terrain the same way it is implemented in the third basic tutorial. I have to add some effects which are easy done using material passes (fog_override so I have only fog where the terrain is and not above, caustics as animated texture), so I would love to use an .material file for this terrain. Is this somehow possible? Like if I would create an object using the entity-strategy described in basic tutorial 1.
0 x

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Fri May 19, 2017 1:25 pm

Hello.

I created a demo application to test the binding: https://github.com/only-a-ptr/ogre-imgui-test. It's basically trimmed OgreWiki-TutFramework with ImGUI + the binding included.

With DirectX9, I get a blurry text and slightly misaligned elements - apparently the entire sizing is off, although settings are default.
imgui-directx.png
DirectX9
Ogre.log
DirectX9
(15.06 KiB) Downloaded 74 times
With OpenGL, UPDATE: I fixed the GLSL shader bug discovered by user <chaos creator> above. The rendering is now crisp :D - but that only makes me more baffled by the DirectX issue.

I'm using Windows 7 x64, Visual Studio 2015 pro, OGRE 1.9 - rest is visible from the logs. I'm quite baffled by the scaling issue of DirectX - can anyone enlighten me please? Note that so far I've only worked with LMCrashy's repository version of the binding, I haven't inspected the other modification (and mentioned bugs).
0 x
Rigs of Rods is alive and kicking!

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Wed May 24, 2017 8:48 pm

Sorry for bumping, but attachment limit...

I tested again on a different machine (geForce videocard). Same issue. I'm attaching Ogre.log to show my full specs, and also a comparsion image of DirectX9 / OpenGL rendering result.
mygui-blurry-detailed-comparsion-ogreforum.png
closeup render output.
Anyone has an idea what's the problem?
Attachments
Ogre.log
DirectX on geForce660 machine.
(14.17 KiB) Downloaded 68 times
0 x
Rigs of Rods is alive and kicking!

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4138
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 268
Contact:

Re: Ogre ImGui binding

Post by dark_sylinc » Wed May 24, 2017 11:48 pm

Looks like the D3D9 version isn't using the half-texel offset correction (whereas OGL & D3D11 don't need it)

Ogre 1.x provides how much offset to apply via RenderSystem::getHorizontalTexelOffset & RenderSystem::getVerticalTexelOffset and also via texel_offsets auto binding for shaders.

I don't know anything about this ImGui port so I cannot help further. AFAIK ImGui already has a D3D9 backend, so it's very likely they already some facility to perform the texel offset, if so, it would be just a matter of telling ImGui to use it when D3D9 RenderSystem is active.

Cheers
0 x

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Thu May 25, 2017 12:11 am

I'm gonna take a look as soon as I have some time left. I haven't tested the dx9 version that much.
ImGUi doesn't use any texture to render, so at least it's not a filtering issue, Dark Sylink is surely right about the texel offset.

I'm also going to fix that glsl little bug, it works fine on my nVidia card but I know in/out variable naming is important on some hardware.
0 x
Follow la Moustache on Twitter or on Facebook
Image

User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 3

Re: Ogre ImGui binding

Post by devxkh » Fri May 26, 2017 11:53 am

I've tried to implement imgui with a movable object without luck. Seems to be a projectionmatrix problem, that i don't understand. :)
Maybe someone else is interrested and is able to solve this.
http://www.ogre3d.org/forums/viewtopic. ... 05#p536905
0 x
My little OGRE engine -> FrankE WIP

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Mon May 29, 2017 1:37 pm

@dark_sylinc: Thanks for the pointer - problem solved, code published in my test repo

Once I learned what to look for, it wasn't hard to find it in ImGui's DirectX9 sample: header comment and the projection matrix

@Crashy: Feel free to grab anything from my test repo! :)
0 x
Rigs of Rods is alive and kicking!

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Fri Jun 02, 2017 4:34 pm

BUMP!

Another issue: Font rendering. Only the built-in bitmap font "ProggyClean" works OK, any TTF font will come out distorted.
DirectX9 looks worst. OpenGL is better, but also broken.
Attachments
IMgui-OGRE-RobotoFontProblems.png
Code used to insert the font is equivalent: size=25, all defaults
0 x
Rigs of Rods is alive and kicking!

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Sat Jun 03, 2017 12:42 pm

Hi,
thanks, i've merged your changes into my repo, and also fixed the glsl shader.
I'll try to use another font and tell you my results.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Sat Jun 03, 2017 7:29 pm

BTW, how are you adding the extra-fonts ?
Could you please also output & post it the generated atlas ?

Just add this at the end of ImguiManager::createFontTexture

Code: Select all

Ogre::Image dst;
    mFontTex->convertToImage(dst,false);
    dst.save("f:/font.tga");
0 x
Follow la Moustache on Twitter or on Facebook
Image

User avatar
only_a_ptr
Halfling
Posts: 62
Joined: Sun Apr 26, 2009 8:43 pm
x 1

Re: Ogre ImGui binding

Post by only_a_ptr » Mon Jun 05, 2017 9:09 am

@crashy
- For the DirectX9 sample, I uncommented this line (plus the `GetIO()` one) and changed font filename.
- For my testbed, I added the same line at the top of `createFontTexture()` function.

I have image-dump code in there already, but I don't think the image atlas is the problem. Here's a side-by-side comparsion screenshot with ImGui's Dx9 demo - the textures look perfectly equivalent:
imgui-OGRE-fontTexture-comparsion.png
Here's the dumped texture anyway (white font on transparent BG, so it's OK to appear blank :D ):
FontTexture_Direct3D9 Rendering Subsystem.png
dumped image atlas texture
0 x
Rigs of Rods is alive and kicking!

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Mon Jun 05, 2017 9:13 pm

Okay. At least my atlas is the same as yours.
But I don't have any glyph visible here using GL3+ RS. I'm looking for a fix.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 20
Contact:

Re: Ogre ImGui binding

Post by Crashy » Fri Jun 16, 2017 6:59 am

Ok, I think I've found the issue, at least on GL*
It was just a filtering issue, just as I expected, see this changeset: https://bitbucket.org/LMCrashy/ogreimgu ... fd8f0ce036

Please tell me if that fixed your bug.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Post Reply