Skip to content

Embedding Imgui into personal project causes text on windows to render as white blocks #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dissolete opened this issue Aug 24, 2016 · 11 comments

Comments

@dissolete
Copy link

dissolete commented Aug 24, 2016

Hello!

This might not be something that you, Elias, can find a solution for, considering that my project is rather large, but this is worth a shot in case a solution IS found and others have the same problem as me. :)

Following the tutorial you provided on your blog as an introduction to Imgui, I was able to create the sample window with no problem -- the text was rendering properly. However, upon using the same code in my own project, the text only renders as white blocks.

capture5

Clearly, this is an issue with either my code, or my makefile (but everything seems to be linking correctly). The functions in which the Imgui code is embedded are called in the correct order in which the Imgui window should be constructed.

Below is how I am using Imgui. Granted, this is only one file of many in my project (these functions are being called by a separate class). Is there something that I'm failing the understand about how the Imgui window gets constructed?

TestState::TestState(std::string stateID, CRE::App& theApp):
    CRE::State(stateID, theApp),
    deltaClock()
{
}

TestState::~TestState()
{}

void TestState::init()
{
    CRE::State::init();
    ImGui::SFML::Init(_theApp._window);
}

void TestState::reinit()
{

}


void TestState::pause()
{
    CRE::State::pause();
}

void TestState::resume()
{
    CRE::State::resume();
}

void TestState::handle_events(sf::Event theEvent)
{
    ImGui::SFML::ProcessEvent(theEvent);
}

void TestState::update()
{
}

void TestState::update_variable(float elapsedTime)
{
    update_imgui();
}

void TestState::update_imgui()
{
    ImGui::SFML::Update(deltaClock.restart());
    ImGui::Begin("Test Window");
    ImGui::Button("THis is a button");
    ImGui::End();
}

void TestState::draw()
{
    _theApp._window.clear();
    ImGui::Render();
}

void TestState::handle_cleanup()
{
    ImGui::SFML::Shutdown();
}

Note that TestState::update_imgui() is only being called once every frame, and "window.display()" is called outside of this file.

I will continue to dabble until I find a solution to my problem. I'm sure I'm doing something really dumb.

@eliasdaler
Copy link
Contributor

eliasdaler commented Aug 24, 2016

It's hard for me to tell what causes the problem, but maybe it's because of drawing other stuff.
Can you try putting ImGui::Render() just before doing window.display()? (so that nothing is rendered after ImGui).
Or try disabling all rendering except for ImGui and then add different things one after another and see what works and what makes ImGui not render properly?

It's possible that it's bug in the binding but so far I haven't encountered it so if you will find what causes it, the problem will likely to be fixed later. :)

P.S. What version of SFML are you using? What's your OS and compiler? There was previously similar problem (#8) but the main cause of the problem wasn't found.

@dissolete
Copy link
Author

dissolete commented Aug 25, 2016

Thanks for the reply! I understand that it's difficult to diagnose the issue when I've only provided a tiny snippet of the code.

I actually found out that this is causing the issue:

capture6

The Imgui code is in the TestState. For whatever reason, adding in more game states prevents the Imgui window from rendering properly. By removing my SpashState, the Imgui renders properly. At this point, it's obvious that my code is breaking it somehow and doesn't seem to be an issue with the library so you may wish to close the issue. I still don't know why the Imgui window is not rendering properly (hopefully I find out soon!), as add_active_state doesn't do anything to directly affect the data contained in the states, and nothing else is being rendered in this project other than the Imgui window (the splash screen gets destroyed and stops rendering before Imgui even gets initialized). I tried placing the Imgui code into a different container class just to see if the states were somehow affecting it and I got the same effect (with garbled text) only when I added new game states. And now I'm just talking about code you can't see so I'm going to stop there. You can leave this open if you would like me to report if I've found a solution or not, but that"s up to you since this is now a personal problem.

My OS is Ubuntu v. 14.04.
My compiler is g++ v. 4.8.4
SFML version 2.1

@dissolete
Copy link
Author

Oh, you might be on to something. I tested activating the TestState before the SplashState -- no problem. Then when switching to the SplashState and then back to the TestState in the same program run, the text became garbled. Perhaps this is a similar issue to #8 since the SplashState renders a sprite to the window. I'll see if rendering a sprite in the TestState without the SplashState breaks the Imgui window.

@dissolete
Copy link
Author

dissolete commented Aug 25, 2016

Yes. This seems to be the same issue as #8. I don't know if this is good or bad news. Haha!

capture7

I forgot to mention that my Ubuntu is running through a VM! Perhaps this is part of the issue?

I'm just happy that there is at least a hackish solution with the window.pushGLStates() and window.popGLStates() so I can at least move forward with my SFML-Imgui developments!

@eliasdaler
Copy link
Contributor

Can you find a minimal complete example that reproduces the problem so I can test it?

VM shouldn't be a problem, it works for me with Ubuntu and VM.
What SFML version are you using? It may be SFML bug, there were lots of them fixed in latest versions.

And where do you put push/popGLStates?

@dissolete
Copy link
Author

dissolete commented Aug 25, 2016

Do you want a similar architecture to my project, or just something that produces the problem?

I placed the push/popGlStates as such:

void TestState::draw()
{
    theApp.window.clear();
    theApp.window.pushGLStates();
    theApp.window.draw(testSprite);
    theApp.window.popGLStates();
    ImGui::Render();
}

I'm using SFML 2.1

@dissolete
Copy link
Author

dissolete commented Aug 25, 2016

Here is the minimum code that resembles my project architecture.

If you need even less code, the example that issue #8 rose also affects me. Rendering sprites without push/popGLStates prevents the Imgui from rendering correctly.

sampleimguibug.tar.gz

As it stands, on my end, the Imgui window does not get rendered correctly.

@dissolete
Copy link
Author

In the morning (I reside in the USA), I will try updating SFML and see if the issue gets resolved.

@eliasdaler
Copy link
Contributor

eliasdaler commented Aug 25, 2016

Hmm, that's pretty strange... looks like SFML somehow changes OpenGL in a weird state. :S
I'll wait until you update to latest SFML version before making any assumptions, there's a possibility that the problem is related to one of the bugs in SFML.

@dissolete
Copy link
Author

I've updated to SFML 2.4.0.

No more problems!

It seems that the bugs you mentioned must have been messing with the ImGui window. Perhaps this is a solution for #8 as well.

Thanks for taking the time to work through this with me! I really appreciate it. :) I'm going to close the issue.

@eliasdaler
Copy link
Contributor

Nice! You're welcome.
And now I'll have to find out minimal version of SFML with which ImGui-SFML works properly and add that in README :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants