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

Loading…
Cancel
Save