Basic sfml window going for the gui redesign.
This commit is contained in:
parent
29a6a565d9
commit
015b4aac45
4 changed files with 111 additions and 1 deletions
|
@ -21,11 +21,12 @@ ftxui_component = dependency('ftxui-component')
|
||||||
catch2 = dependency('catch2-with-main')
|
catch2 = dependency('catch2-with-main')
|
||||||
sfml = dependency('sfml')
|
sfml = dependency('sfml')
|
||||||
json = dependency('nlohmann_json')
|
json = dependency('nlohmann_json')
|
||||||
|
imgui = dependency('imgui-sfml')
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
fmt, libgit2package_dep, efsw_dep,
|
fmt, libgit2package_dep, efsw_dep,
|
||||||
ftxui_screen, ftxui_dom, ftxui_component,
|
ftxui_screen, ftxui_dom, ftxui_component,
|
||||||
sfml, json
|
sfml, imgui, json
|
||||||
]
|
]
|
||||||
|
|
||||||
executable('escape_turings_tarpit',
|
executable('escape_turings_tarpit',
|
||||||
|
@ -51,6 +52,9 @@ executable('audiotest', 'audiotest.cpp',
|
||||||
executable('jsontest', 'jsontest.cpp',
|
executable('jsontest', 'jsontest.cpp',
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
|
executable('sfmltest', 'sfmltest.cpp',
|
||||||
|
dependencies: dependencies)
|
||||||
|
|
||||||
runtests = executable('runtests', [
|
runtests = executable('runtests', [
|
||||||
'game_engine.cpp',
|
'game_engine.cpp',
|
||||||
'tests/game_engine.cpp'],
|
'tests/game_engine.cpp'],
|
||||||
|
|
|
@ -16,6 +16,8 @@ meson wrap install flac
|
||||||
meson wrap install freetype2
|
meson wrap install freetype2
|
||||||
meson wrap install openal-soft
|
meson wrap install openal-soft
|
||||||
meson wrap install sfml
|
meson wrap install sfml
|
||||||
|
meson wrap install imgui
|
||||||
|
meson wrap install imgui-sfml
|
||||||
meson wrap install nlohmann_json
|
meson wrap install nlohmann_json
|
||||||
# $env:CC="clang"
|
# $env:CC="clang"
|
||||||
# $env:CXX="clang++"
|
# $env:CXX="clang++"
|
||||||
|
|
|
@ -18,6 +18,8 @@ meson wrap install ogg
|
||||||
meson wrap install flac
|
meson wrap install flac
|
||||||
meson wrap install freetype2
|
meson wrap install freetype2
|
||||||
meson wrap install openal-soft
|
meson wrap install openal-soft
|
||||||
|
meson wrap install imgui
|
||||||
meson wrap install sfml
|
meson wrap install sfml
|
||||||
|
meson wrap install imgui-sfml
|
||||||
meson wrap install nlohmann_json
|
meson wrap install nlohmann_json
|
||||||
meson setup builddir
|
meson setup builddir
|
||||||
|
|
102
sfmltest.cpp
Normal file
102
sfmltest.cpp
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui-SFML.h"
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include <math.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
|
#include <SFML/System.hpp>
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
|
constexpr int FPS=30;
|
||||||
|
constexpr int X_DIM = 1920 / 2;
|
||||||
|
constexpr int Y_DIM = 1080 / 2;
|
||||||
|
|
||||||
|
void ImGui_setup(sf::RenderWindow &window) {
|
||||||
|
bool res = ImGui::SFML::Init(window);
|
||||||
|
fmt::println("IMGUI returned {}", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) {
|
||||||
|
ImGui::SFML::Update(window, deltaClock.restart());
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window_update(sf::RenderWindow &window) {
|
||||||
|
window.clear();
|
||||||
|
ImGui::SFML::Render(window);
|
||||||
|
window.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Handle_events(sf::RenderWindow &window) {
|
||||||
|
sf::Event event;
|
||||||
|
|
||||||
|
// is this a main event loop
|
||||||
|
while (window.pollEvent(event)) {
|
||||||
|
ImGui::SFML::ProcessEvent(window, event);
|
||||||
|
|
||||||
|
switch(event.type) {
|
||||||
|
|
||||||
|
case sf::Event::Closed:
|
||||||
|
fmt::print("Exiting...\n");
|
||||||
|
window.close();
|
||||||
|
break;
|
||||||
|
case sf::Event::KeyPressed:
|
||||||
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Time Update_entities(sf::RenderWindow &window, 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;
|
||||||
|
|
||||||
|
ImGui_update(window, deltaClock, tick);
|
||||||
|
Window_update(window);
|
||||||
|
|
||||||
|
return nextTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
fmt::print("Setting up a window for you...\n");
|
||||||
|
|
||||||
|
sf::ContextSettings settings;
|
||||||
|
settings.antialiasingLevel = 8;
|
||||||
|
|
||||||
|
sf::RenderWindow window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings);
|
||||||
|
window.setPosition({.x=0,.y=0});
|
||||||
|
|
||||||
|
window.setFramerateLimit(FPS);
|
||||||
|
window.setVerticalSyncEnabled(true);
|
||||||
|
ImGui_setup(window);
|
||||||
|
|
||||||
|
sf::Clock deltaClock;
|
||||||
|
sf::Clock clock;
|
||||||
|
sf::Time tick = clock.getElapsedTime();
|
||||||
|
|
||||||
|
while (window.isOpen()) {
|
||||||
|
Handle_events(window);
|
||||||
|
// preparing for refactoring this into a class or struct for everything
|
||||||
|
tick = Update_entities(window, clock, deltaClock, tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SFML::Shutdown();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue