Now I have a spinning square in the center and a clock. Kind of a weird spin but it work. We got motion.

master
Zed A. Shaw 7 months ago
parent 29a9949498
commit c3d16f7930
  1. 25
      sfmldemo/main.cpp

@ -18,9 +18,11 @@ void ImGui_setup(sf::RenderWindow &window) {
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) {
ImGui::SFML::Update(window, deltaClock.restart());
ImGui::ShowDemoWindow();
ImGui::Begin("Hello, world!");
// ImGui::ShowDemoWindow();
ImGui::Begin("Clock");
sf::Vector2u size = window.getSize();
ImGui::SetWindowPos(ImVec2(size.x - 150, 0));
ImGui::SetWindowSize(ImVec2(150, 50));
std::string msg = fmt::format("Time: {}\n", tick.asSeconds());
ImGui::Button(msg.c_str());
ImGui::End();
@ -28,6 +30,8 @@ void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tic
void Window_update(sf::RenderWindow &window, sf::Shape &shape) {
window.clear();
sf::Vector2u size = window.getSize();
shape.setPosition(size.x / 2, size.y / 2);
window.draw(shape);
ImGui::SFML::Render(window);
window.display();
@ -35,15 +39,21 @@ void Window_update(sf::RenderWindow &window, sf::Shape &shape) {
int main() {
fmt::print("Setting up a window for you...\n");
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(1920, 1080), "Simple Game Demo", sf::Style::Default, settings);
sf::RenderWindow window(sf::VideoMode(1920, 1080), "ImGui + SFML = <3");
// window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
ImGui_setup(window);
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
sf::CircleShape shape(100.f, 4);
shape.setFillColor(sf::Color(150, 50, 250));
shape.setOutlineThickness(10.f);
shape.setOutlineColor(sf::Color(250, 150, 100));
sf::Clock deltaClock;
sf::Clock clock;
sf::Time tick = clock.getElapsedTime();
@ -67,6 +77,7 @@ int main() {
if (event.type == sf::Event::Closed) {
fmt::print("Exiting...\n");
window.close();
thread.terminate();
}
}
@ -75,6 +86,8 @@ int main() {
tick = since;
}
shape.rotate(1);
ImGui_update(window, deltaClock, tick);
Window_update(window, shape);
}

Loading…
Cancel
Save