ImGui SFML |
( , .), . . : , , , . . , , .
Lua
, ImGui , .
Immediate mode GUI , retained mode GUI. ImGui . , , .
Qt, QPushButton
, - -callback, , ImGui . :
if (ImGui::Button("Some Button")) {
... // ,
}
, .
, , .
, ImGui?
,
:
, ImGui . , , .
#include "imgui.h"
#include "imgui-sfml.h"
#include Graphics/RenderWindow.hpp>
#include System/Clock.hpp>
#include Window/Event.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "");
window.setVerticalSyncEnabled(true);
ImGui::SFML::Init(window);
sf::Color bgColor;
float color[3] = { 0.f, 0.f, 0.f };
// char.
// std::string ,
char windowTitle[255] = "ImGui + SFML = <3";
window.setTitle(windowTitle);
sf::Clock deltaClock;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(event);
if (event.type == sf::Event::Closed) {
window.close();
}
}
ImGui::SFML::Update(window, deltaClock.restart());
ImGui::Begin("Sample window"); //
//
if (ImGui::ColorEdit3("Background color", color)) {
// ,
//
bgColor.r = static_cast(color[0] * 255.f);
bgColor.g = static_cast(color[1] * 255.f);
bgColor.b = static_cast(color[2] * 255.f);
}
ImGui::InputText("Window title", windowTitle, 255);
if (ImGui::Button("Update window title")) {
// ,
//
// if(ImGui::InputText(...))
window.setTitle(windowTitle);
}
ImGui::End(); // end window
window.clear(bgColor); //
ImGui::SFML::Render(target);
window.display();
}
ImGui::SFML::Shutdown();
}
- :
-. RGB, . , . .
, .
ImGui ImGui::SFML::Init
, sf::RenderWindow
. , . (. Fonts how-to imgui-sfml, ).
ImGui::SFML::Shutdown
, , ImGui.
ImGui : .
, ImGui / . ImGui::SFML::ProcessEvent
. ImGui , , . ImGui ImGui::SFML::Update
, delta time ( ), ImGui (, ). ImGui::NewFrame
, .
ImGui ImGui::SFML::Render
. / ImGui::SFML::Update
ImGui::SFML::Render
, ImGui .
, , update
ImGui::EndFrame
:
while (gameIsRunning) {
while (updateIsNeeded()) {
updateGame(dt);
ImGui::SFML::Update(window, dt);
ImGui::EndFrame();
}
renderGame();
}
(, ImGui::InputInt
ImGui::Button
). ImGui::ShowTestWindow
, ImGui, imgui_demo.cpp.
SFML , ImGui::Image
ImGui::ImageButton
sf::Sprite
sf::Texture
, DrawLine
, DrawRect
DrawRectFilled
.
: , . !
P.S. , , ImGui C++ . , ( ) ImGui: ImGui , C++03.