| 7 | #include <cstdint> |
| 8 | |
| 9 | int main() { |
| 10 | // An sf::Window for raw OpenGL rendering. |
| 11 | sf::Window app_window( sf::VideoMode( { 800, 600 } ), "SFGUI with OpenGL example", sf::Style::Titlebar | sf::Style::Close ); |
| 12 | |
| 13 | // Create an SFGUI. This is required before doing anything with SFGUI. |
| 14 | sfg::SFGUI sfgui; |
| 15 | |
| 16 | // Set the SFML Window's context back to the active one. SFGUI creates |
| 17 | // a temporary context on creation that is set active. |
| 18 | (void)app_window.setActive(); |
| 19 | |
| 20 | // Initial OpenGL setup. |
| 21 | // We have to set up our own OpenGL viewport because we are using an sf::Window. |
| 22 | glViewport( 0, 0, static_cast<int>( app_window.getSize().x ), static_cast<int>( app_window.getSize().y ) ); |
| 23 | |
| 24 | auto red_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL ); |
| 25 | auto green_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL ); |
| 26 | auto blue_scale = sfg::Scale::Create( 0.f, 1.f, .01f, sfg::Scale::Orientation::HORIZONTAL ); |
| 27 | auto angle_scale = sfg::Scale::Create( 0.f, 360.f, 1.f, sfg::Scale::Orientation::HORIZONTAL ); |
| 28 | auto auto_check = sfg::CheckButton::Create( "Auto" ); |
| 29 | |
| 30 | auto table = sfg::Table::Create(); |
| 31 | table->SetRowSpacings( 5.f ); |
| 32 | table->SetColumnSpacings( 5.f ); |
| 33 | |
| 34 | table->Attach( sfg::Label::Create( "Change the color of the rect using the scales below." ), sf::Rect<std::uint32_t>( { 0, 0 }, { 3, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 35 | table->Attach( sfg::Label::Create( "Red:" ), sf::Rect<std::uint32_t>( { 0, 1 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 36 | table->Attach( red_scale, sf::Rect<std::uint32_t>( { 1, 1 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); |
| 37 | table->Attach( sfg::Label::Create( "Green:" ), sf::Rect<std::uint32_t>( { 0, 2 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 38 | table->Attach( green_scale, sf::Rect<std::uint32_t>( { 1, 2 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); |
| 39 | table->Attach( sfg::Label::Create( "Blue:" ), sf::Rect<std::uint32_t>( { 0, 3 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 40 | table->Attach( blue_scale, sf::Rect<std::uint32_t>( { 1, 3 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); |
| 41 | table->Attach( sfg::Label::Create( "Angle:" ), sf::Rect<std::uint32_t>( { 0, 4 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 42 | table->Attach( angle_scale, sf::Rect<std::uint32_t>( { 1, 4 }, { 1, 1 } ), sfg::Table::FILL | sfg::Table::EXPAND, sfg::Table::FILL | sfg::Table::EXPAND ); |
| 43 | table->Attach( auto_check, sf::Rect<std::uint32_t>( { 2, 4 }, { 1, 1 } ), sfg::Table::FILL, sfg::Table::FILL ); |
| 44 | |
| 45 | auto window = sfg::Window::Create(); |
| 46 | window->SetTitle( "SFGUI with OpenGL" ); |
| 47 | window->Add( table ); |
| 48 | |
| 49 | sfg::Desktop desktop; |
| 50 | desktop.Add( window ); |
| 51 | |
| 52 | red_scale->SetValue( .2f ); |
| 53 | green_scale->SetValue( .5f ); |
| 54 | blue_scale->SetValue( .8f ); |
| 55 | |
| 56 | glMatrixMode( GL_PROJECTION ); |
| 57 | glLoadIdentity(); |
| 58 | |
| 59 | static const auto pi = 3.1415926535897932384626433832795f; |
| 60 | static const auto fov = 90.f; |
| 61 | static const auto near_distance = .1f; |
| 62 | static const auto far_distance = 100.f; |
| 63 | static const auto aspect = 800.f / 600.f; |
| 64 | |
| 65 | auto frustum_height = std::tan( fov / 360 * pi ) * near_distance; |
| 66 | auto frustum_width = frustum_height * aspect; |
nothing calls this directly
no test coverage detected