Have a basic template for the gui up, but obviously not using it right. The ImGui does pop up when I hit space, but fails a second time claiming I need to run render again. Needs more research.

master
Zed A. Shaw 3 months ago
parent df6944b0fb
commit 8707982907
  1. BIN
      assets/turing_tarpit_main_screen.png
  2. 53
      sfmltest.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

@ -15,7 +15,7 @@ using namespace ImGui;
constexpr int FPS=30; constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2; constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2; constexpr int Y_DIM = 1080 / 2;
bool window_active_out = true; bool window_active_out = false;
void ImGui_setup(sf::RenderWindow &window) { void ImGui_setup(sf::RenderWindow &window) {
bool res = SFML::Init(window); bool res = SFML::Init(window);
@ -30,33 +30,24 @@ void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tic
SetNextWindowPos(ImVec2(0, size.y / 2)); SetNextWindowPos(ImVec2(0, size.y / 2));
SetNextWindowSize(ImVec2(size.x, size.y / 2)); SetNextWindowSize(ImVec2(size.x, size.y / 2));
Begin("Turing's Tarpit", &window_active_out); Begin("Build Status", &window_active_out);
// HP | Hits Taken | Round | Streak
Text("HP X"); SameLine();
Text("Hits Taken X"); SameLine();
Text("Round X"); SameLine();
Text("Streak X");
// HP BAR
float hp = 50.0f;
SliderFloat("HP", &hp, 0.0f, 100.0f);
// Build Log
TextColored(ImVec4(1,1,0,1), "Build Log"); TextColored(ImVec4(1,1,0,1), "Build Log");
BeginChild("Scrolling"); BeginChild("Scrolling");
for(int n = 0; n < 50; n++) { for(int n = 0; n < 50; n++) {
TextWrapped("%04d: Some Text", n); TextWrapped("%04d: Some Text", n);
} }
EndChild(); EndChild();
// image placeholder
End(); End();
} }
void Window_update(sf::RenderWindow &window, sf::Sprite &player) { void Window_update(sf::RenderWindow &window, sf::Sprite &background) {
window.clear(); window.clear();
window.draw(player); window.draw(background);
if(window_active_out) {
fmt::println(">>>> RENDER");
SFML::Render(window); SFML::Render(window);
}
window.display(); window.display();
} }
@ -65,7 +56,10 @@ void Handle_events(sf::RenderWindow &window) {
// is this a main event loop // is this a main event loop
while (window.pollEvent(event)) { while (window.pollEvent(event)) {
if(window_active_out) {
fmt::println(">>> EVENTS");
SFML::ProcessEvent(window, event); SFML::ProcessEvent(window, event);
}
switch(event.type) { switch(event.type) {
@ -76,6 +70,9 @@ void Handle_events(sf::RenderWindow &window) {
case sf::Event::KeyPressed: case sf::Event::KeyPressed:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close(); window.close();
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
fmt::println(">>> SET TRUE");
window_active_out = true;
} }
break; break;
default: default:
@ -85,17 +82,19 @@ void Handle_events(sf::RenderWindow &window) {
} }
} }
sf::Time Update_entities(sf::RenderWindow &window, sf::Sprite &player, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick) { sf::Time Update_entities(sf::RenderWindow &window, sf::Sprite &background, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick) {
sf::Vector2u winSize = window.getSize(); sf::Vector2u winSize = window.getSize();
float timeStep = 1.0f / FPS; float timeStep = 1.0f / FPS;
sf::Time since = clock.getElapsedTime(); sf::Time since = clock.getElapsedTime();
sf::Time nextTick = since - tick > sf::seconds(1) ? since : tick; sf::Time nextTick = since - tick > sf::seconds(1) ? since : tick;
player.setPosition(winSize.x/2, 0); background.setPosition(0, 0);
player.setScale({2.0f, 2.0f});
if(window_active_out) {
fmt::println("<<< UPDATE");
ImGui_update(window, deltaClock, tick); ImGui_update(window, deltaClock, tick);
Window_update(window, player); }
Window_update(window, background);
return nextTick; return nextTick;
} }
@ -118,19 +117,21 @@ int main() {
sf::Clock clock; sf::Clock clock;
sf::Time tick = clock.getElapsedTime(); sf::Time tick = clock.getElapsedTime();
sf::Texture texture; sf::Texture texture;
sf::Sprite player; sf::Sprite background;
// fake image here // fake image here
if(!texture.loadFromFile("./assets/sprite.png")) { if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) {
fmt::println("Error loading sprite!"); fmt::println("Error loading sprite!");
} }
texture.setSmooth(true); texture.setSmooth(true);
player.setTexture(texture); background.setTexture(texture);
while (window.isOpen() && window_active_out) { while (window.isOpen()) {
fmt::println(">>>>>>>>>>>>>>>>>> WINDOW LOOP");
Handle_events(window); Handle_events(window);
// preparing for refactoring this into a class or struct for everything // preparing for refactoring this into a class or struct for everything
tick = Update_entities(window, player, clock, deltaClock, tick); tick = Update_entities(window, background, clock, deltaClock, tick);
fmt::println("<<<<<<<<<<<<<<<< EXIT WINDOW LOOP");
} }
SFML::Shutdown(); SFML::Shutdown();

Loading…
Cancel
Save