SFML/imgui-sfml

Imgui not letting specific text be drawn by SFML

ojasmaheshwari opened this issue · 3 comments

#include <SFML/Graphics.hpp>
#include <imgui-SFML.h>
#include <imgui.h>

#define SCREEN_WIDTH 1000

int main(int argc, char *argv[]) {

  sf::RenderWindow window(sf::VideoMode(1000, 550), "Trajectory Simulator");

  ImGui::SFML::Init(window);

  sf::Clock deltaClock;

  sf::Font headingFont;
  headingFont.loadFromFile("assets/font/font.ttf");
  sf::Text heading("Trajectory Simulator", headingFont);
  heading.setCharacterSize(50);
  heading.setStyle(sf::Text::Regular);
  heading.setFillColor(sf::Color::Blue);
  float headingWidth = heading.getLocalBounds().width / 2;
  heading.setPosition(sf::Vector2f(SCREEN_WIDTH / 2.0 - headingWidth, 200));

  while (window.isOpen()) {
    sf::Event event;
    while (window.pollEvent(event)) {

      ImGui::SFML::ProcessEvent(window, event);

      if (event.type == sf::Event::Closed)
        window.close();
    }

    ImGui::SFML::Update(window, deltaClock.restart());
    ImGui::Begin("Testing");
    ImGui::Text("Hello world");
    ImGui::End();

    window.clear();
    window.draw(heading);
    ImGui::SFML::Render(window);
    window.display();
  }

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

Before adding ImGui, the program was working perfectly fine and heading was being displayed. However, when I run this code it does not render the heading. It does for the 1st frame but after that nothing is rendered. Not even the imgui window.

I don't know what might be causing the issue. Heading is just a simple sf::Text object.

Try making a minimal repro - try taking out unnecessary detail until you're left with "heading" rendering and Dear ImGui rendering. See if the issue is reproducible even after that.

@eliasdaler done, updated the original issue. Does not seem to work either.