Page 1 of 3

Ogre ImGui binding

Posted: Tue Sep 06, 2016 1:00 pm
by Crashy
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);
}

Re: Ogre ImGui binding

Posted: Tue Sep 06, 2016 3:53 pm
by insider
Excellent :D

Re: Ogre ImGui binding

Posted: Wed Sep 07, 2016 2:35 am
by hydexon
OH DEAR GOD, Thanks you so much!

Re: Ogre ImGui binding

Posted: Wed Sep 07, 2016 2:50 am
by xrgo
Fantastic!! thanks for sharing =D!

Re: Ogre ImGui binding

Posted: Wed Sep 07, 2016 8:43 am
by Crashy
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.

Re: Ogre ImGui binding

Posted: Fri Sep 09, 2016 10:11 am
by Crashy
Aaaand now I've fixed build issues with Ogre 1.x and added D3D9 shaders.

Re: Ogre ImGui binding

Posted: Sun Sep 18, 2016 8:50 pm
by chaos creator
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

Re: Ogre ImGui binding

Posted: Thu Sep 29, 2016 12:02 am
by only_a_ptr
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.

Re: Ogre ImGui binding

Posted: Sun Oct 16, 2016 2:31 am
by hydexon
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.

Re: Ogre ImGui binding

Posted: Sun Oct 23, 2016 1:33 pm
by einherjer
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)?

Re: Ogre ImGui binding

Posted: Fri Oct 28, 2016 12:09 pm
by chaos creator
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 :)

Re: Ogre ImGui binding

Posted: Fri Oct 28, 2016 10:55 pm
by hydexon
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.

Re: Ogre ImGui binding

Posted: Wed Nov 02, 2016 3:29 pm
by john21wall
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.

Re: Ogre ImGui binding

Posted: Fri May 19, 2017 1:25 pm
by only_a_ptr
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 71 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).

Re: Ogre ImGui binding

Posted: Wed May 24, 2017 8:48 pm
by only_a_ptr
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?

Re: Ogre ImGui binding

Posted: Wed May 24, 2017 11:48 pm
by dark_sylinc
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

Re: Ogre ImGui binding

Posted: Thu May 25, 2017 12:11 am
by Crashy
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.

Re: Ogre ImGui binding

Posted: Fri May 26, 2017 11:53 am
by devxkh
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

Re: Ogre ImGui binding

Posted: Mon May 29, 2017 1:37 pm
by only_a_ptr
@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! :)

Re: Ogre ImGui binding

Posted: Fri Jun 02, 2017 4:34 pm
by only_a_ptr
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.

Re: Ogre ImGui binding

Posted: Sat Jun 03, 2017 12:42 pm
by Crashy
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.

Re: Ogre ImGui binding

Posted: Sat Jun 03, 2017 7:29 pm
by Crashy
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");

Re: Ogre ImGui binding

Posted: Mon Jun 05, 2017 9:09 am
by only_a_ptr
@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

Re: Ogre ImGui binding

Posted: Mon Jun 05, 2017 9:13 pm
by Crashy
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.

Re: Ogre ImGui binding

Posted: Fri Jun 16, 2017 6:59 am
by Crashy
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.