Skip to content
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

Can't get ImGui to draw OVER my OpenGL stuff #70

Closed
oxysoft opened this issue Dec 10, 2018 · 2 comments
Closed

Can't get ImGui to draw OVER my OpenGL stuff #70

oxysoft opened this issue Dec 10, 2018 · 2 comments
Labels

Comments

@oxysoft
Copy link

oxysoft commented Dec 10, 2018

Here is a relevant excerpt from my code

bool OpenglContext::Start(const std::string& title, int width, int height, bool isFullscreen)
{
	m_windowTitle = title;
	m_isFullscreen = isFullscreen;
	InitWindow(width, height);
	ImGui::SFML::Init(m_window);

	Init();
	LoadResource();
	ShowCursor();

	sf::Clock clock;
	while (m_window.isOpen())
	{
		m_window.setActive();
		sf::Event event;
		while (m_window.pollEvent(event))
		{
			ImGui::SFML::ProcessEvent(event);

			switch (event.type)
			{
				case sf::Event::Closed:
					m_window.close();
					break;

				case sf::Event::Resized:
					OnWindowResized(event.size.width, event.size.height);
					break;

				case sf::Event::KeyPressed:
					OnKeyPress(event.key.code);
					break;

				case sf::Event::KeyReleased:
					OnKeyRelease(event.key.code);
					break;

				case sf::Event::MouseMoved:
					OnMouseMove(event.mouseMove.x, event.mouseMove.y);
					break;

				case sf::Event::MouseButtonPressed:
					OnMousePress(ConvertMouseButton(event.mouseButton.button), event.mouseButton.x,
					             event.mouseButton.y);
					break;

				case sf::Event::MouseButtonReleased:
					OnMouseReleased(ConvertMouseButton(event.mouseButton.button), event.mouseButton.x,
					                event.mouseButton.y);
					break;

				case sf::Event::MouseWheelMoved:
					if (event.mouseWheel.delta > 0)
						OnMousePress(MOUSE_BUTTON_WHEEL_UP, event.mouseButton.x, event.mouseButton.y);
					else
						OnMousePress(MOUSE_BUTTON_WHEEL_DOWN, event.mouseButton.x, event.mouseButton.y);
					break;

			}
		}

		ImGui::SFML::Update(m_window, clock.restart());
		ImGui::Begin("MyWindow"); // begin window
		ImGui::Button("wow!");
		ImGui::End(); // end window

		m_window.clear(sf::Color(30, 30, 30));
		m_window.resetGLStates();
		// Uncommenting the two lines below replaces everything with my game.
//		Init();
//		Render(m_lastFrameTime);

		ImGui::SFML::Render(m_window);
		m_window.display();
		m_lastFrameTime = clock.getElapsedTime().asSeconds();

		// Handle ourself frame rate limit, sf::Window::setFramerateLimit doesn't seems to work
		float waitTime = (1.f / m_maxFps) - m_lastFrameTime;
		if (waitTime > 0)
		{
			sf::sleep(sf::seconds(waitTime));

			m_lastFrameTime = clock.getElapsedTime().asSeconds();
		}
	}

	UnloadResource();
	DeInit();

	ImGui::SFML::Shutdown();
	return true;
}

The two commented lines prepare the GL context (enable depth test, etc.) and then draws the entirety of my game. If I keep these lines commented, I can see my ImGui window with a button in it. If I comment out these lines, ImGui is nowhere to be seen.

What gives?

  1. I update ImGui and send some stuff to it.
  2. Render my game.
  3. Render ImGui with ImGui::SFML::Render
  4. Send to the screen with RenderWindow::Display

What am I missing?

@eliasdaler
Copy link
Contributor

Hello
It'll help me a lot if you'll find a very simple compilable example. Even if it's pretty big, but is one file that I can compile - it'll help a lot. I'm not doing 3D graphics, so I'm not sure what can cause the problem, unfortunately.

Also take a look at "RenderDrawLists" in imgui-SFML.cpp - I think there might be some glEnable/glDisable calls which I've missed and which screw up the OpenGL state.

@eliasdaler
Copy link
Contributor

Might be related to #159, might be fixed in one of the latest versions... Feel free to reopen if needed.

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

No branches or pull requests

2 participants