-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


ImGui SFML

, 13 2017 . 09:52 +

, !
. ImGui SFML. .




( , .), . . : , , , . . , , .


ImGui :





Lua




, ImGui , .


ImGui immediate GUI


Immediate mode GUI , retained mode GUI. ImGui . , , .


Qt, QPushButton, - -callback, , ImGui . :


if (ImGui::Button("Some Button")) {
    ... // ,    
}

, .


, , .


ImGui, .


, ImGui?


  • MIT-
  • / ( , ImGui )
  • :
  • , .


,


  1. SFML, . , .
  2. ImGui.
  3. ImGui SFML , ImGui.
    : imconfig-SFML.h imconfig.h
  4. ImGui include
  5. :


    • imgui.cpp
    • imgui_draw.cpp
    • imgui-SFML.cpp
    • imgui_demo.cpp

  6. , OpenGL .

, 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


SFML , ImGui::Image ImGui::ImageButton sf::Sprite sf::Texture, DrawLine, DrawRect DrawRectFilled.



: , . !


P.S. , , ImGui C++ . , ( ) ImGui: ImGui , C++03.

Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/335512/

:  

: [1] []
 

:
: 

: ( )

:

  URL