SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.08k stars 163 forks source link

Imgui not letting specific text be drawn by SFML #238

Open ojasmaheshwari opened 1 year ago

ojasmaheshwari commented 1 year ago
#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.

eliasdaler commented 1 year ago

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.

ojasmaheshwari commented 1 year ago

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

eliasdaler commented 7 months ago

Sorry it took me half a year to respond, but I can't repro this - I see the text So, needs more info - which OS/desktop environment, which ImGui-SFML version, which ImGui version do you use?

image