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. 59
      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 X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2;
bool window_active_out = true;
bool window_active_out = false;
void ImGui_setup(sf::RenderWindow &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));
SetNextWindowSize(ImVec2(size.x, size.y / 2));
Begin("Turing's Tarpit", &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
Begin("Build Status", &window_active_out);
TextColored(ImVec4(1,1,0,1), "Build Log");
BeginChild("Scrolling");
for(int n = 0; n < 50; n++) {
TextWrapped("%04d: Some Text", n);
}
EndChild();
// image placeholder
End();
}
void Window_update(sf::RenderWindow &window, sf::Sprite &player) {
void Window_update(sf::RenderWindow &window, sf::Sprite &background) {
window.clear();
window.draw(player);
SFML::Render(window);
window.draw(background);
if(window_active_out) {
fmt::println(">>>> RENDER");
SFML::Render(window);
}
window.display();
}
@ -65,7 +56,10 @@ void Handle_events(sf::RenderWindow &window) {
// is this a main event loop
while (window.pollEvent(event)) {
SFML::ProcessEvent(window, event);
if(window_active_out) {
fmt::println(">>> EVENTS");
SFML::ProcessEvent(window, event);
}
switch(event.type) {
@ -76,6 +70,9 @@ void Handle_events(sf::RenderWindow &window) {
case sf::Event::KeyPressed:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.close();
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
fmt::println(">>> SET TRUE");
window_active_out = true;
}
break;
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();
float timeStep = 1.0f / FPS;
sf::Time since = clock.getElapsedTime();
sf::Time nextTick = since - tick > sf::seconds(1) ? since : tick;
player.setPosition(winSize.x/2, 0);
player.setScale({2.0f, 2.0f});
background.setPosition(0, 0);
ImGui_update(window, deltaClock, tick);
Window_update(window, player);
if(window_active_out) {
fmt::println("<<< UPDATE");
ImGui_update(window, deltaClock, tick);
}
Window_update(window, background);
return nextTick;
}
@ -118,19 +117,21 @@ int main() {
sf::Clock clock;
sf::Time tick = clock.getElapsedTime();
sf::Texture texture;
sf::Sprite player;
sf::Sprite background;
// fake image here
if(!texture.loadFromFile("./assets/sprite.png")) {
if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) {
fmt::println("Error loading sprite!");
}
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);
// 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();

Loading…
Cancel
Save