| 7 | #include <SFML/Graphics.hpp> |
| 8 | |
| 9 | int main() { |
| 10 | // Create the main SFML window |
| 11 | sf::RenderWindow app_window( sf::VideoMode( { 800, 600 } ), "SFGUI Image Example", sf::Style::Titlebar | sf::Style::Close ); |
| 12 | |
| 13 | // We have to do this because we don't use SFML to draw. |
| 14 | app_window.resetGLStates(); |
| 15 | |
| 16 | // Create an SFGUI. This is required before doing anything with SFGUI. |
| 17 | sfg::SFGUI sfgui; |
| 18 | |
| 19 | // Create our main SFGUI window |
| 20 | auto window = sfg::Window::Create(); |
| 21 | window->SetTitle( "Title" ); |
| 22 | |
| 23 | // Our sf::Image source |
| 24 | sf::Image sfgui_logo; |
| 25 | |
| 26 | // Our sfg::Image |
| 27 | auto image = sfg::Image::Create(); |
| 28 | |
| 29 | // Try to load the image |
| 30 | if( sfgui_logo.loadFromFile( "data/sfgui.png" ) ) { |
| 31 | image->SetImage( sfgui_logo ); |
| 32 | } |
| 33 | |
| 34 | // Add the image to the window. |
| 35 | window->Add( image ); |
| 36 | |
| 37 | // Start the game loop |
| 38 | while ( app_window.isOpen() ) { |
| 39 | // Process events |
| 40 | while ( const std::optional event = app_window.pollEvent() ) { |
| 41 | // Handle events |
| 42 | window->HandleEvent( *event ); |
| 43 | |
| 44 | // Close window : exit |
| 45 | if ( event->is<sf::Event::Closed>() ) { |
| 46 | return EXIT_SUCCESS; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Update the GUI, note that you shouldn't normally |
| 51 | // pass 0 seconds to the update method. |
| 52 | window->Update( 0.f ); |
| 53 | |
| 54 | // Clear screen |
| 55 | app_window.clear(); |
| 56 | |
| 57 | // Draw the GUI |
| 58 | sfgui.Display( app_window ); |
| 59 | |
| 60 | // Update the window |
| 61 | app_window.display(); |
| 62 | } |
| 63 | |
| 64 | return EXIT_SUCCESS; |
| 65 | } |