Guest User

sfml 3.0 demo text render

a guest
Aug 8th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <SFML/Window.hpp>
  2. #include <SFML/OpenGL.hpp>
  3. #include <SFML/Graphics.hpp>
  4.  
  5.  
  6.  
  7. int main(){
  8.  
  9.    sf::ContextSettings settings{
  10.       .depthBits=24,
  11.       .stencilBits=8,
  12.       .majorVersion=1,
  13.       .minorVersion=4,
  14.       .attributeFlags=sf::ContextSettings::Default,
  15.       .sRgbCapable=true,
  16.    };
  17.    sf::Context context{settings,sf::Vector2u(1,1)};
  18.  
  19.    sf::RenderWindow window(sf::VideoMode({800, 600}), "   ^^ meow", sf::Style::Default, sf::State::Windowed);
  20.    HWND hwnd = window.getNativeHandle();
  21.    ShowWindow(hwnd, SW_MAXIMIZE);
  22.    window.setVerticalSyncEnabled(true);
  23.    if (not window.setActive(true)){
  24.      // out(1,L"Не удалось активировать окно\n");
  25.    }
  26.  
  27.    bool running = true;
  28.  
  29.  
  30.  
  31.    sf::Font font;
  32.    if (!font.openFromFile("../data/Roboto-Regular.ttf"))
  33.    {
  34.       return 1;
  35.    }
  36.  
  37.    // Создание текста
  38.    sf::Text text(font,L"аАёЁяЯaAzZ", 24);
  39.    text.setFillColor(sf::Color::White);
  40.    text.setPosition(sf::Vector2f(50, 50));
  41.  
  42.  
  43.    while (running){
  44.       while (const std::optional event = window.pollEvent()){
  45.          if (event->is<sf::Event::Closed>()){
  46.             running = false;
  47.           //  out(2,L"close");
  48.          }
  49.          else if (const auto* resized = event->getIf<sf::Event::Resized>()){
  50.             glViewport(0, 0, resized->size.x, resized->size.y);
  51.           //  out(2,L"resize to %dx%d\n",resized->size.x,resized->size.y);
  52.          }
  53.       }
  54.       glClearColor(0,0.2,0.0,0);
  55.       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  56.       window.draw(text);
  57.       window.display();
  58.    }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment