Skip to content

Imgui not letting specific text be drawn by SFML #238

Open
@ojasmaheshwari

Description

#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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions