Super jank clock in ImGUI to learn the SFML time keeping functions.
This commit is contained in:
parent
e7efc197a1
commit
d2dfb72775
1 changed files with 38 additions and 19 deletions
|
@ -7,26 +7,50 @@
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
|
void ImGui_setup(sf::RenderWindow &window) {
|
||||||
|
int res = ImGui::SFML::Init(window);
|
||||||
|
if(res == 1) {
|
||||||
|
fmt::print("ImGui returned result {}\n", res);
|
||||||
|
} else {
|
||||||
|
fmt::print("ImGui returned an error code={}\n", res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) {
|
||||||
|
ImGui::SFML::Update(window, deltaClock.restart());
|
||||||
|
ImGui::ShowDemoWindow();
|
||||||
|
ImGui::Begin("Hello, world!");
|
||||||
|
|
||||||
|
std::string msg = fmt::format("Time: {}\n", tick.asSeconds());
|
||||||
|
ImGui::Button(msg.c_str());
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window_update(sf::RenderWindow &window, sf::Shape &shape) {
|
||||||
|
window.clear();
|
||||||
|
window.draw(shape);
|
||||||
|
ImGui::SFML::Render(window);
|
||||||
|
window.display();
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
fmt::print("Setting up a window for you...\n");
|
fmt::print("Setting up a window for you...\n");
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(1920, 1080), "ImGui + SFML = <3");
|
sf::RenderWindow window(sf::VideoMode(1920, 1080), "ImGui + SFML = <3");
|
||||||
// window.setFramerateLimit(60);
|
// window.setFramerateLimit(60);
|
||||||
window.setVerticalSyncEnabled(true);
|
window.setVerticalSyncEnabled(true);
|
||||||
int res = ImGui::SFML::Init(window);
|
|
||||||
if(res == 1) {
|
ImGui_setup(window);
|
||||||
fmt::print("ImGui returned result {}\n", res);
|
|
||||||
} else {
|
|
||||||
fmt::print("ImGui returned an error code={}\n", res);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::CircleShape shape(100.f);
|
sf::CircleShape shape(100.f);
|
||||||
shape.setFillColor(sf::Color::Green);
|
shape.setFillColor(sf::Color::Green);
|
||||||
|
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
|
sf::Clock clock;
|
||||||
|
sf::Time tick = clock.getElapsedTime();
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
|
||||||
while (window.pollEvent(event)) {
|
while (window.pollEvent(event)) {
|
||||||
ImGui::SFML::ProcessEvent(window, event);
|
ImGui::SFML::ProcessEvent(window, event);
|
||||||
|
|
||||||
|
@ -36,18 +60,13 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SFML::Update(window, deltaClock.restart());
|
sf::Time since = clock.getElapsedTime();
|
||||||
|
if(since - tick > sf::seconds(1)) {
|
||||||
|
tick = since;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
ImGui_update(window, deltaClock, tick);
|
||||||
|
Window_update(window, shape);
|
||||||
ImGui::Begin("Hello, world!");
|
|
||||||
ImGui::Button("Look at this pretty button");
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
window.clear();
|
|
||||||
window.draw(shape);
|
|
||||||
ImGui::SFML::Render(window);
|
|
||||||
window.display();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SFML::Shutdown();
|
ImGui::SFML::Shutdown();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue