Unable to type text into ImGui text fields (1.12.3)

Problems building or running the engine, queries about how to use features etc.
Post Reply
LtZ
Gnoblar
Posts: 15
Joined: Thu Dec 19, 2019 9:51 am
x 11

Unable to type text into ImGui text fields (1.12.3)

Post by LtZ »

Ogre Version: 1.12.3 (compiled SDK by myself from git sources, Visual Studio 2015 Update 3)
Operating System: Windows 10
Render System: OpenGL 3+ Rendering Subsystem

Hi all

I'm rather new to Ogre3D and I want to get Dear ImGui working in my test app. So I used the Ogre's ImGuiDemo sample code as reference. Curiously, everything else seems to be working except that I can't type any characters into any of the textfield inputs.. :x ImGui appears to be receiving keypress events properly as "Keyboard, Mouse & Navigation" section in the DemoApp indicates.

Heck I can even select and clear (Backspace) already filled-in text in the DemoApp's "Focus from code" section, just not type in new characters :?: :?:

ImGui sample within SampleBrowser.exe seems to be working okay. Something must be done differently there. I have been scouring through the sources and tried everything but to no avail. Unfortunately, I can't use the SampleBrowser framework for my own app.

Has anyone managed to get ImGui working outside of the sample framework? I'd appreciate any help. Here's all the source code (Bootstrap.cpp) of my test app:

Code: Select all

#include "Ogre.h"
#include "OgreApplicationContext.h"
#include "OgreImGuiOverlay.h"
#include "OgreImGuiInputListener.h"
#include "OgreOverlaySystem.h"
#include "OgreTrays.h"
#include <iostream>

using namespace Ogre;

class MyTestApp : 
	public OgreBites::ApplicationContext, 
	public OgreBites::InputListener,
	public OgreBites::TrayListener
{
	std::unique_ptr<OgreBites::ImGuiInputListener> mImguiListener;
	OgreBites::InputListenerChain mListenerChain;

public:
    MyTestApp();
    void setup();

	bool keyPressed(const OgreBites::KeyboardEvent& evt);
	bool keyReleased(const OgreBites::KeyboardEvent& evt) { return mListenerChain.keyReleased(evt); }
	bool mouseMoved(const OgreBites::MouseMotionEvent& evt) { return mListenerChain.mouseMoved(evt); }
	bool mouseWheelRolled(const OgreBites::MouseWheelEvent& evt) { return mListenerChain.mouseWheelRolled(evt); }
	bool mousePressed(const OgreBites::MouseButtonEvent& evt) { return mListenerChain.mousePressed(evt); }
	bool mouseReleased(const OgreBites::MouseButtonEvent& evt) { return mListenerChain.mouseReleased(evt); }

	bool frameStarted(const Ogre::FrameEvent& evt);
	bool frameRenderingQueued(const Ogre::FrameEvent& evt);

private:
	LogManager *log;
	OgreBites::TrayManager *mTrayManager;
};

MyTestApp::MyTestApp() : OgreBites::ApplicationContext("MyTestApp")
{
	log = 0;
}

bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
	if (mListenerChain.keyPressed(evt))
		return true;
	//mImguiListener.get()->keyPressed(evt);
	
	if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
		getRoot()->queueEndRendering();

	return true;
}

bool MyTestApp::frameStarted(const Ogre::FrameEvent & evt)
{
	ImGuiOverlay::NewFrame(evt);
	ImGui::ShowDemoWindow();
	
	// Pass to superclass
	return OgreBites::ApplicationContext::frameStarted(evt);
}

bool MyTestApp::frameRenderingQueued(const Ogre::FrameEvent & evt)
{
	mTrayManager->frameRendered(evt);
	return OgreBites::ApplicationContext::frameRenderingQueued(evt);
}

void MyTestApp::setup(void)
{
	OgreBites::ApplicationContext::setup();
	log = LogManager::getSingletonPtr();

	// get a pointer to the already created root
	Ogre::Root* root = getRoot();
	Ogre::SceneManager* scnMgr = root->createSceneManager();

	// register our scene with the RTSS
	Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	shadergen->addSceneManager(scnMgr);


	// also need to tell where we are
	Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::Camera* cam = scnMgr->createCamera("myCam");
	cam->setNearClipDistance(2); // specific to this sample
	cam->setAutoAspectRatio(true);
	camNode->attachObject(cam);

	getRenderWindow()->addViewport(cam);

	// register our class for input events
	addInputListener(this);

	// Overlays
	mTrayManager = new OgreBites::TrayManager("InterfaceName", getRenderWindow(), this);
	scnMgr->addRenderQueueListener(getOverlaySystem()); // Enable drawing of Overlays
	mTrayManager->showFrameStats(OgreBites::TrayLocation::TL_BOTTOMLEFT);

	//
	// ImGui
	//
	ImGuiOverlay *imguiOverlay = new ImGuiOverlay();
	imguiOverlay->setZOrder(300);
	imguiOverlay->show();
	Ogre::OverlayManager::getSingleton().addOverlay(imguiOverlay); // now owned by overlaymgr

	mImguiListener.reset(new OgreBites::ImGuiInputListener());
	mListenerChain = OgreBites::InputListenerChain({ mTrayManager, mImguiListener.get() });
}


#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, LPSTR lpCmdLine, int nShowCmd)
{
    MyTestApp app;
    app.initApp();
    app.getRoot()->startRendering();
    app.closeApp(); 
    return 0;
}

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

Re: Unable to type text into ImGui text fields (1.12.3)

Post by paroj »

try registering it directly as:

Code: Select all

addInputListener(mImguiListener.get());
and drop it from mListenerChain
LtZ
Gnoblar
Posts: 15
Joined: Thu Dec 19, 2019 9:51 am
x 11

Re: Unable to type text into ImGui text fields (1.12.3)

Post by LtZ »

Tried it. Nope, doesn't work :(

Either way, Keys down, Keys pressed and Keys release events blink in ImGuiDemoWindow when I type keys, indicating it's receiving the events.

I changed the MyTestApp::keyPressed to call mImguiListener.get()->keyPressed(evt) directly so I can use Debugger to break-point on that line and to Step Into it (F11 in VisualStudio)... The character ends up all the way up to the InputQueueCharacters queue if ImGuiIO object. For example, pressing A key appends ushort value of 97 to said input queue.

Oh well, guess I'm going to have to dive deeper into the codebase and inspect the parts where characters are supposed to be extracted from said InputQueueCharacters to a TextField and where the queue gets cleared.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1993
Joined: Sun Mar 30, 2014 2:51 pm
x 1073
Contact:

Re: Unable to type text into ImGui text fields (1.12.3)

Post by paroj »

you could also try master - there have been some changes regarding text input to handle UTF-8 and locale. Maybe that fixes your issues as well.
LtZ
Gnoblar
Posts: 15
Joined: Thu Dec 19, 2019 9:51 am
x 11

Re: Unable to type text into ImGui text fields (1.12.3)

Post by LtZ »

Finally, figured out what was the problem.

I was calling ApplicationContext::frameStarted (which in turn calls SDLs pollEvents()) after ImGui NewFrame etc., so it never received the events because InputQueueCharacters gets cleared at the end of every frame. Code that works is below:

Code: Select all

bool MyTestApp::frameStarted(const Ogre::FrameEvent & evt)
{
	pollEvents(); // Must come first
	ImGuiOverlay::NewFrame(evt);
	ImGui::ShowDemoWindow();

	// Pass to superclass - WRONG!
	// return OgreBites::ApplicationContext::frameStarted(evt);
	return true;
}
pidhash
Gnoblar
Posts: 2
Joined: Sun May 23, 2021 3:14 pm

Re: Unable to type text into ImGui text fields (1.12.3)

Post by pidhash »

Is that code still working in 1.13.0 I can't get input in text edits in the imgui, I am trying the minimum imgui ogre code without sample sdk ?
pidhash
Gnoblar
Posts: 2
Joined: Sun May 23, 2021 3:14 pm

Re: Unable to type text into ImGui text fields (1.12.3)

Post by pidhash »

ImGui text input doesn't works, someone could help me to fix it ?

Code: Select all

#include <Ogre.h>
#include <OgreApplicationContext.h>
#include <Overlay/OgreImGuiOverlay.h>
#include <Bites/OgreImGuiInputListener.h>
#include <Overlay/OgreOverlaySystem.h>
#include <Bites/OgreTrays.h>
#include <iostream>

using namespace Ogre;

class MyTestApp : 
	public OgreBites::ApplicationContext, 
	public OgreBites::InputListener, public OgreBites::TrayListener
{
	std::unique_ptr<OgreBites::ImGuiInputListener> mImguiListener;
	OgreBites::InputListenerChain mListenerChain;

public:
    MyTestApp();
    void setup();

	bool keyPressed(const OgreBites::KeyboardEvent& evt); 
	bool keyReleased(const OgreBites::KeyboardEvent& evt) { return mListenerChain.keyReleased(evt); }
	bool mouseMoved(const OgreBites::MouseMotionEvent& evt) { return mListenerChain.mouseMoved(evt); }
	bool mouseWheelRolled(const OgreBites::MouseWheelEvent& evt) { return mListenerChain.mouseWheelRolled(evt); }
	bool mousePressed(const OgreBites::MouseButtonEvent& evt) { return mListenerChain.mousePressed(evt); }
	bool mouseReleased(const OgreBites::MouseButtonEvent& evt) { return mListenerChain.mouseReleased(evt); }
    bool textInput (const OgreBites::TextInputEvent& evt) { return mListenerChain.textInput (evt); }

	bool frameStarted(const Ogre::FrameEvent& evt);
	bool frameRenderingQueued(const Ogre::FrameEvent& evt);

private:
	LogManager *log;
	// OgreBites::TrayManager *mTrayManager;
};

MyTestApp::MyTestApp() : OgreBites::ApplicationContext("MyTestApp")
{
	log = 0;
}

bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
	if (mListenerChain.keyPressed(evt))
		return true;
	//mImguiListener.get()->keyPressed(evt);
	
	if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
		getRoot()->queueEndRendering();

	return OgreBites::InputListener::keyPressed(evt);
}

bool MyTestApp::frameStarted(const Ogre::FrameEvent & evt)
{
    // pollEvents();
	ImGuiOverlay::NewFrame(evt);
	ImGui::ShowDemoWindow();
	
	// Pass to superclass
	return OgreBites::ApplicationContext::frameStarted(evt);
}

bool MyTestApp::frameRenderingQueued(const Ogre::FrameEvent & evt)
{
	// mTrayManager->frameRendered(evt);
	return OgreBites::ApplicationContext::frameRenderingQueued(evt);
}

void MyTestApp::setup(void)
{
	OgreBites::ApplicationContext::setup();
	log = LogManager::getSingletonPtr();

	// get a pointer to the already created root
	auto root = getRoot();
	auto scnMgr = root->createSceneManager();

	// register our scene with the RTSS
	auto shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	shadergen->addSceneManager(scnMgr);

	// also need to tell where we are
	auto camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
	auto cam = scnMgr->createCamera("myCam");
	cam->setNearClipDistance(2); // specific to this sample
	cam->setAutoAspectRatio(true);
	camNode->attachObject(cam);

	getRenderWindow()->addViewport(cam);

	// register our class for input events
	addInputListener(this);

	// Overlays
	// mTrayManager = new OgreBites::TrayManager("InterfaceName", getRenderWindow(), this);
	scnMgr->addRenderQueueListener(getOverlaySystem()); // Enable drawing of Overlays
	// mTrayManager->showFrameStats(OgreBites::TrayLocation::TL_BOTTOMLEFT);

	//
	// ImGui
	//
	auto imguiOverlay = new ImGuiOverlay;
	imguiOverlay->setZOrder(300);
	imguiOverlay->show();
	Ogre::OverlayManager::getSingleton().addOverlay(imguiOverlay); // now owned by overlaymgr

	mImguiListener.reset(new OgreBites::ImGuiInputListener);
    // addInputListener(mImguiListener.get());
	mListenerChain = OgreBites::InputListenerChain({/*mTrayManager,*/ mImguiListener.get()});
}


int main(int argc, char *argv[])
{
    MyTestApp app;
    app.initApp();
    app.getRoot()->startRendering();
    app.closeApp(); 

    return 0;
}
pidhash
Gnoblar
Posts: 2
Joined: Sun May 23, 2021 3:14 pm

Re: Unable to type text into ImGui text fields (1.12.3)

Post by pidhash »

Ok o pollEvents(), fixed my crashes and imgui text input, it seems really important in this case.
Last edited by pidhash on Tue May 25, 2021 6:29 am, edited 1 time in total.
User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 155

Re: Unable to type text into ImGui text fields (1.12.3)

Post by sercero »

Does your code work in Ogre 1.12.12?
Post Reply