Ogre ImGui binding

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
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 » Sun Jun 18, 2017 11:48 pm

[SOLVED] - It's working perfectly under both OpenGL and DirectX9 for me.

Texture filtering... why didn't I think of that? :D Thanks!
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 » Mon Jul 10, 2017 10:21 am

BUMP!

@Crashy Any reason why you set required GLSL version to "150"? This appears to be causing issues for users with OGRE 1.9 and linux: https://github.com/RigsOfRods/rigs-of-r ... -310236651

I'm under impression a much lower version requirement would do: https://github.com/RigsOfRods/rigs-of-r ... -310245578 I'm going to research further, but I'd still like to ask.
0 x
Rigs of Rods is alive and kicking!

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

Re: Ogre ImGui binding

Post by Crashy » Mon Jul 10, 2017 10:29 am

No, if it's working on lower version, you can change it. The shader is really simple, it shouldn't be a problem.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Garibalde
Halfling
Posts: 69
Joined: Thu Apr 16, 2009 2:38 am
Location: Montreal, Quebec
x 1
Contact:

Re: Ogre ImGui binding

Post by Garibalde » Mon Aug 21, 2017 3:27 pm

Hi

I am trying to integrate imgui into my basic Ogre application. I don't have OIS as I am using SDL.
I tried ChaosCreate 2.1 ogre integration however this version Ogre 1.10.8 doe snot seem to have
OgreFastArray.h so I cant compile (I guess its a 2.1 upgrade).

If there a way to integrate it into Ogre 1.10.8. Seem some have it working in 1.9 is that with OIS? or SDL?

Thanks
0 x
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com

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

Re: Ogre ImGui binding

Post by Crashy » Mon Aug 21, 2017 3:40 pm

Hi, you'll need to use my version when using Ogre 1.x, however, some changes are required to use SDL instead of OIS. It should be easy though.
Input related functions are

Code: Select all

 virtual bool mouseMoved( const OIS::MouseEvent &arg );
		virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
		virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
        //Inherhited from OIS::KeyListener
		virtual bool keyPressed( const OIS::KeyEvent &arg );
		virtual bool keyReleased( const OIS::KeyEvent &arg );
Just change them to take SDL input events instead of OIS.
0 x
Follow la Moustache on Twitter or on Facebook
Image

Garibalde
Halfling
Posts: 69
Joined: Thu Apr 16, 2009 2:38 am
Location: Montreal, Quebec
x 1
Contact:

Re: Ogre ImGui binding

Post by Garibalde » Tue Aug 22, 2017 2:58 am

Ok I have tried to make the change from OIS to SDL as i am using Ogre 1.10.8

However i have some strange issues. I am implementing the default GUIs in the Demo in the Ogre application.
I see the menus but interaction with it is messed up. I cant pickup the windows and move them and i can click
on any of the buttons. I was able to do this in the demo application in IMGUI.
Ogrewindow.png
I have made changes to the virtual functions to pass in SDL events.

Code: Select all

		
                //Inherhited from OIS::MouseListener
		virtual bool mouseMoved(const OgreBites::MouseMotionEvent &arg);
		virtual bool mouseWheelRolled(const OgreBites::MouseWheelEvent& arg);
		virtual bool mousePressed(const OgreBites::MouseButtonEvent &arg);
		virtual bool mouseReleased(const OgreBites::MouseButtonEvent &arg);
		//Inherhited from OIS::KeyListener
		virtual bool keyPressed(const OgreBites::KeyboardEvent& evt);
		virtual bool keyReleased(const OgreBites::KeyboardEvent& evt);
I have changes the code the in the function to reflect this in ImguiManager.cpp:

Code: Select all

 //Inherhited from OIS::MouseListener
bool ImguiManager::mouseMoved(const OgreBites::MouseMotionEvent &arg)
{

    ImGuiIO& io = ImGui::GetIO();

    io.MousePos.x = arg.x;
    io.MousePos.y = arg.y;

    //io.MouseWheel = Ogre::Math::Sign(arg.state.Z.rel);

    return true;
}

bool ImguiManager::mouseWheelRolled(const OgreBites::MouseWheelEvent& arg)
{
	ImGuiIO& io = ImGui::GetIO();

	io.MouseWheel = Ogre::Math::Sign(arg.y);

	return true;
}

bool ImguiManager::mousePressed(const OgreBites::MouseButtonEvent &arg)
{
    ImGuiIO& io = ImGui::GetIO();
    if(arg.button<5)
    {
        io.MouseDown[arg.button] = true;
    }
    return true;
}
bool ImguiManager::mouseReleased(const OgreBites::MouseButtonEvent &arg)
{
    ImGuiIO& io = ImGui::GetIO();
    if(arg.button<5)
    {
        io.MouseDown[arg.button] = false;
    }
    return true;
}
//Inherhited from OIS::KeyListener
bool ImguiManager::keyPressed(const OgreBites::KeyboardEvent& evt)
{
    ImGuiIO& io = ImGui::GetIO();
    io.KeysDown[evt.keysym.sym] = true;
    
    //VM++ if(evt.text>0)
    //VM++ {
    //VM++     io.AddInputCharacter((unsigned short)arg.text);
    //VM++ }

    return true;
}
bool ImguiManager::keyReleased(const OgreBites::KeyboardEvent& evt)
{
    ImGuiIO& io = ImGui::GetIO();
    io.KeysDown[evt.keysym.sym] = false;
    return true;
}
I then called these functions from my OGRE class which handles inputs

Code: Select all

bool SurSimMain::mouseMoved(const OgreBites::MouseMotionEvent &arg)
{
	//! Update SDL with the mouse moved
	Ogre::ImguiManager::getSingleton().mouseMoved(arg);
}

bool SurSimMain::mouseWheelRolled(const OgreBites::MouseWheelEvent& evt)
{
	//! Update SDL with the mouse Wheel rolled.
	Ogre::ImguiManager::getSingleton().mouseWheelRolled(evt);
}

bool SurSimMain::mousePressed(const OgreBites::MouseButtonEvent &arg)
{
	//! Update SDL with the mouse pressed.
	Ogre::ImguiManager::getSingleton().mousePressed(arg);
}

etc...
In the OGRE Setup() I create an instance and initialised it.

Code: Select all

	//! Initialize IMGui
	Ogre::ImguiManager::createSingleton();
	Ogre::ImguiManager::getSingleton().init(mSceneMgr);
Finally in the frameRenderingQueued() I create newframe() on each pass.
and call my GUI code (Copy of the example code).

Code: Select all


void SurSimMain::LoadGUIInterfaces()
{
	{
		static float f = 0.0f;
		ImGui::Text("Hello, world!");
		ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
		ImGui::ColorEdit3("clear color", (float*)&clear_color);
		if (ImGui::Button("Test Window")) show_test_window ^= 1;
		if (ImGui::Button("Another Window")) show_another_window ^= 1;
		ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
	}

	// 2. Show another simple window, this time using an explicit Begin/End pair
	if (show_another_window)
	{
		ImGui::SetNextWindowSize(ImVec2(200, 100), ImGuiCond_FirstUseEver);
		ImGui::Begin("Another Window", &show_another_window);
		ImGui::Text("Hello");
		ImGui::End();
	}

	// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
	if (show_test_window)
	{
		ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
		ImGui::ShowTestWindow(&show_test_window);
	}
}

bool SurSimMain::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
	Ogre::ImguiManager::getSingleton().newFrame(evt.timeSinceLastFrame, Ogre::Rect(0,0, getRenderWindow()->getWidth(), getRenderWindow()->getHeight()));

	LoadGUIInterfaces();

	for (std::set<InputListener*>::iterator it = mInputListeners.begin();
		it != mInputListeners.end(); ++it) {
		(*it)->frameRendered(evt);
	}

	return true;
}
My interaction with the gui pages are nothing like that of the demo. It seems my inputs are not registering or are random.
I am unable to move the windows around or click on any of the menu buttons. A few highlight as i pass over them.

What am i missing?

Thanks
0 x
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com

Garibalde
Halfling
Posts: 69
Joined: Thu Apr 16, 2009 2:38 am
Location: Montreal, Quebec
x 1
Contact:

Re: Ogre ImGui binding

Post by Garibalde » Tue Aug 22, 2017 8:57 pm

I resolved the issue:

Seems SDL mouse buttons start from 1-5 and in Imgui assumes 0-4

So I changed the following in ImguiManager.cpp

Code: Select all

bool ImguiManager::mousePressed(const OgreBites::MouseButtonEvent &arg)
{
    ImGuiIO& io = ImGui::GetIO();
    if(arg.button<=5)
    {
        io.MouseDown[arg.button-1] = true;
    }
    return true;
}

bool ImguiManager::mouseReleased(const OgreBites::MouseButtonEvent &arg)
{
    ImGuiIO& io = ImGui::GetIO();
    if(arg.button<=5)
    {
        io.MouseDown[arg.button-1] = false;
    }
    return true;
}
0 x
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com

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 » Tue Sep 19, 2017 10:42 am

There's one last nuissance about this GUI integration: it doesn't do window content clipping (or 'scissoring', I'm not sure of the proper term). All elements which don't completely fit into a scrollable region "pop out", as seen on the following screenshots:
imgui-OGRE-clipping-issues.png
User 'ChaosCreator' mentioned that before: http://www.ogre3d.org/forums/viewtopic. ... 59#p531059 - it's on the bottom of his post. I looked into his code shortly - seems easy enough to get right: https://bitbucket.org/ChaosCreator/imgu ... er.cpp-175

[UPDATE]: Done. Code available in my testbed repo: https://github.com/only-a-ptr/ogre-imgu ... /ror-style
1 x
Rigs of Rods is alive and kicking!

Garibalde
Halfling
Posts: 69
Joined: Thu Apr 16, 2009 2:38 am
Location: Montreal, Quebec
x 1
Contact:

Re: Ogre ImGui binding

Post by Garibalde » Tue Oct 31, 2017 6:47 pm

I posted this in a different thread. But I think this maybe better for ImGUi issues.

i am using ImGui with Ogre 1.10.8

I have split my viewport into quads (4 viewport in a single screen) so I can render different camera views in each quad.
However my ImGui windows are all locked to the first viewport and shrunk (Scaled). Mouse control is still full window (Position).

I would like the gui to overlay over all the viewports (Complete window). How can i do this with ImGUI?

In CEUGUI I think we created a "Sheet" and assigned the root rendernode and attached CEGUI dui elements to this "Sheet"
I am guessing I need to render a overlay over the viewports. How do i achieve this?
0 x
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com

paroj
OGRE Team Member
OGRE Team Member
Posts: 545
Joined: Sun Mar 30, 2014 2:51 pm
x 76
Contact:

Re: Ogre ImGui binding

Post by paroj » Thu Feb 22, 2018 7:17 pm

ported to Ogre 1.10/ SDL2 style input and added build and example:
https://github.com/OGRECave/ogre-imgui
1 x

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

Re: Ogre ImGui binding

Post by Crashy » Thu Feb 22, 2018 8:04 pm

Hi,
Nice, I think I'll put the current code in a branch named 1.9x/OIS and merge your pull request in the default afterwards.

On my side I added a quick way to use textures, using the Ogre::Texture handle as ImGui texture Id. It could be more optimal, but at least, it works.

Usage:
1-be sure your texture is loaded (as it may not be used by anything else than your Imgui widget)

Code: Select all

 Ogre::TextureManager::getSingleton().load("MyTex.png","MyResourceGroup");
2-Retrieve the handle and use it as a ImTextureID

Code: Select all

Ogre::ResourceHandle texHandle = Ogre::TextureManager::getSingleton().getByName("MyTex.png")->getHandle();
ImGui::Image((ImTextureID)texHandle , ImVec2(32, 32));
0 x
Follow la Moustache on Twitter or on Facebook
Image

z80
Gnoblar
Posts: 5
Joined: Sun Aug 05, 2018 7:56 am
x 2

Re: Ogre ImGui binding

Post by z80 » Sun Aug 05, 2018 8:41 am

Hello,

I'm trying using images with your IMGUI binding. I use the latest (commit sha256: e953853814fb83754b50eed8ee2dedc3e5d83f30) of https://github.com/OGRECave/ogre-imgui binding. My Ogre3d version is 1.11 build on Ubuntu linux machine (if it matters).
In order to see an image I try doing similar thing to the example above.

Code: Select all

        Ogre::TextureManager::getSingleton().load("MyGrass.jpg","My");
        TexturePtr t = TextureManager::getSingleton().getByName( "MyGrass.jpg", "My" );
        ResourceHandle hdl = t->getHandle();
        int w = t->getWidth();
        int h = t->getHeight();
        ImGui::Image( (ImTextureID)hdl, ImVec2( w, h ) );
        ImGui::ImageButton( (ImTextureID)hdl, ImVec2( w, h ) );
Image size does correspond to the right one. However, the image itself is always the "default" font image (with letters and numbers, see the image attached to this post).
On the other hand, if I change lines of code in ImguiManager.cpp responsible for texture from

Code: Select all

            if(drawCmd->TextureId != 0 )
            {
                Ogre::ResourceHandle handle = (Ogre::ResourceHandle)drawCmd->TextureId;
to

Code: Select all

            if(true )
            {
                Ogre::ResourceHandle handle = 185;
I do see the result. Of course, in this case all textures are replaced with the one I hard-code with handle 185. But so far this is the only way to see anything other that the font texture due to some reason.

Would one, please, help me out with this issue I met? I'd appreciate any help! Thank you!
Image
0 x

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

Re: Ogre ImGui binding

Post by Crashy » Mon Aug 06, 2018 6:03 am

MMhhh, I don't see why this is not working.

What happens if you only call Ogre::TextureManager::getSingleton().load("MyGrass.jpg","My"); once at the beginning of your program, and not every frame ?
0 x
Follow la Moustache on Twitter or on Facebook
Image

z80
Gnoblar
Posts: 5
Joined: Sun Aug 05, 2018 7:56 am
x 2

Re: Ogre ImGui binding

Post by z80 » Tue Aug 07, 2018 6:16 am

Hello,

It seems it doesn't matter. I moved texture loading and getting it's handle to setup() method. But I still see the same font texture only in all places (see details below).
Can it be Ogre3d version related thing? May I know what version you used in the example you've provided three messages above?

Thank you!


In setup():

Code: Select all

        TexturePtr t2 = TextureManager::getSingleton().getByName( "MyGrass.jpg", "My" );
        ResourceHandle hdl = t2->getHandle();
        textureHandle = hdl;
In window drawing routine:

Code: Select all

        ImGui::Begin( "Texture view" ); // begin window
        ImGui::TextWrapped( "Here I expect to see my texture, but got these :) However, texture size is orrect. But the content is always the default \'font\' one." );
        int w = 128;
        int h = 128;
        ImGui::Image( (ImTextureID)textureHandle, ImVec2( w, h ) );
        ImGui::ImageButton( (ImTextureID)textureHandle, ImVec2( w, h ) );

        ImGui::End(); // end window

As I see this code in ImguiManager.cpp seems to have no effect regardless of texture handle. If handle is valid, "mTexUnit->setTexture(tex);" is called. And if I place some random number instead of a valid handle "mTexUnit->setTexture(tex);" is not called. But result is always the same font texture even in the case of intentionally placed invalid texture handle.

Code: Select all

            if(drawCmd->TextureId != 0 )
            {
                Ogre::ResourceHandle handle = (Ogre::ResourceHandle)drawCmd->TextureId;
                Ogre::TexturePtr tex = Ogre::static_pointer_cast<Ogre::Texture>(
                    Ogre::TextureManager::getSingleton().getByHandle(handle));
                if (tex)
                {
                    mTexUnit->setTexture(tex);
                    mTexUnit->setTextureFiltering(Ogre::TFO_TRILINEAR);
                }
            }
0 x

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

Re: Ogre ImGui binding

Post by Crashy » Tue Aug 07, 2018 6:48 am

I'm using Ogre 2.0.
So the setTexture is called but it doesn't change anything ?
Which RenderSystem are you using ?
You might need to check two thing
-Is the changed texture unit the one used in mPass (it should)
-When RenderSystem::_setTextureUnitSettings is called (in SceneManager::_setPass, called by _injectRenderWithPass), is it the right texture ?
0 x
Follow la Moustache on Twitter or on Facebook
Image

z80
Gnoblar
Posts: 5
Joined: Sun Aug 05, 2018 7:56 am
x 2

Re: Ogre ImGui binding

Post by z80 » Wed Aug 08, 2018 2:46 am

Hello,

Thank you so much for your support! Your two hints guided me to the following.

Due to some reason Pass is not the same as the one used to retrieve TextureUnitState in createMaterial() method. Due to that changes don't take effect. The following two lines before choosing a texture in ImguiManager.cpp solve the problem:

Code: Select all

            Pass * mPass = mRenderable.mMaterial->getBestTechnique()->getPass(0);
            TextureUnitState * st = mPass->getTextureUnitState( 0 );
            if(drawCmd->TextureId != 0 )
            {
                Ogre::ResourceHandle handle = (Ogre::ResourceHandle)drawCmd->TextureId;
                Ogre::TexturePtr tex = Ogre::static_pointer_cast<Ogre::Texture>(
                    Ogre::TextureManager::getSingleton().getByHandle(handle));
                if (tex)
                {
                    st->setTexture(tex);
                    st->setTextureFiltering(Ogre::TFO_TRILINEAR);
                }
            }
            else
            {
                st->setTexture(mFontTex);
                st->setTextureFiltering(Ogre::TFO_NONE);
            }
Thank you again!
1 x

z80
Gnoblar
Posts: 5
Joined: Sun Aug 05, 2018 7:56 am
x 2

Re: Ogre ImGui binding

Post by z80 » Wed Aug 08, 2018 2:51 am

See the screenshot attached.
Image
1 x

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

Re: Ogre ImGui binding

Post by Crashy » Wed Aug 08, 2018 6:41 am

Thanks, I think I understand: you're using RTSS, aren't you ?
Anyway, here is the patch commit.

(didn't compiled nor tested it as I'm using another branch, I know it's really bad, but it should be ok)
0 x
Follow la Moustache on Twitter or on Facebook
Image

z80
Gnoblar
Posts: 5
Joined: Sun Aug 05, 2018 7:56 am
x 2

Re: Ogre ImGui binding

Post by z80 » Thu Aug 09, 2018 4:55 am

Hello,
Yes, I did attach RTSS to scene manager. I didn't know that I shouldn't. It must be I'm missing something.
Thank you so much! So far it looks like it works as expected.
0 x

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

Re: Ogre ImGui binding

Post by Crashy » Thu Aug 09, 2018 6:01 am

Oh no you can use it, it's jut that I never tested this feature with RTSS enabled ;)
0 x
Follow la Moustache on Twitter or on Facebook
Image

Post Reply