• SFML库的简单使用


    显示圆和矩形

    #include 
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    
    
    
        sf::CircleShape shape(10.f);
        shape.setFillColor(sf::Color::Green);
        shape.setPosition(0, 0);
        /*shape.setTexture()*/
    
        sf::RectangleShape rect(sf::Vector2f(5, 10));//设置大小
        rect.setPosition(sf::Vector2f(20, 20));//设置位置
        rect.setFillColor(sf::Color(255, 255, 255, 128));//设置颜色
        rect.setRotation(45);
        
    
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }
    
            window.clear();
            
            for (int i = 0; i < 50; i++) {
                rect.setPosition(sf::Vector2f(20 + i * 5, 20 + i * 5));//设置位置
                rect.setFillColor(sf::Color(255-i*5, 255 - i * 5, 255, 128));//设置颜色
                rect.setRotation(45 - i * 2);
                window.draw(rect);//绘制rect
            }
            window.draw(shape);
            window.display();
        }
    
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    打印实时坐标

    #include 
    #include 
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
    
        sf::Vector2i mousePosition;  // 鼠标位置
        sf::Font font;  // 字体
        //font.loadFromFile("arial.ttf"); // 替换为您自己的字体文件路径
        sf::Text text; // 显示坐标的文本框
        text.setFont(font);
        text.setCharacterSize(90);
        text.setFillColor(sf::Color::Black);
        text.setPosition(20, 20);
    
        while (window.isOpen())
        {
            sf::Event event;
    
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }
    
            mousePosition = sf::Mouse::getPosition(window);
            std::cout << "Mouse Position: (" << mousePosition.x << ", " << mousePosition.y << ")" << std::endl;
    
            text.setString("Mouse Position: (" + std::to_string(mousePosition.x) + ", " + std::to_string(mousePosition.y) + ")");
    
            window.clear(sf::Color::Yellow);
            window.draw(text);
            window.display();
        }
    
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
  • 相关阅读:
    K8S的基础知识
    电脑检测温度软件有哪些?
    Flink+Flink CDC版本升级的依赖问题总结
    [SpringBoot] 8. aop 获取 request response
    dragTabs(vue)
    android12将wifi功能和移动数据功能从一个网络按钮分开
    C语言猜数字
    毫米波V2I网络的链路层仿真研究(Matlab代码实现)
    基于 RTS 超低延时直播优化强互动场景体验
    k8s优雅停服
  • 原文地址:https://blog.csdn.net/LW_12345/article/details/132781735