Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I'm having problems with drawing  (Read 1231 times)

0 Members and 1 Guest are viewing this topic.

xRiccardoC++

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
I'm having problems with drawing
« on: September 24, 2018, 02:51:01 pm »
I'm trying to use a sf::CircleShape as a brush because i want to make a paint remake or something like that. Because of that i don't clear the window every frame and this causes a really weird thing to happen.

#include <SFML/Graphics.hpp>

int main()
{
    using namespace sf;
    RenderWindow window(VideoMode(800, 600), "Title_String");
    window.setFramerateLimit(60);

    CircleShape brush(16.0f);
    brush.setFillColor(Color::Red);

    window.clear(Color::Black);

    while (window.isOpen())
    {
        Event e;
        while (window.pollEvent(e))
        {
            if (e.type == Event::Closed)
            {
                window.close();
            }
        }

        if (Mouse::isButtonPressed(Mouse::Button::Left))
        {
            int mx = Mouse::getPosition(window).x;
            int my = Mouse::getPosition(window).y;
            brush.setPosition(mx - 8, my - 8);
            window.draw(brush);
        }

        window.display();
    }


    return 0;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: I'm having problems with drawing
« Reply #1 on: September 24, 2018, 03:01:53 pm »
So what's the issue?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I'm having problems with drawing
« Reply #2 on: September 24, 2018, 03:18:13 pm »
You must always clear the window every frame. If you want a persistent pixel buffer, then use a sf::RenderTexture.
Laurent Gomila - SFML developer

 

anything