SFML community forums

Help => Graphics => Topic started by: wilbefast on September 14, 2010, 02:10:13 pm

Title: Drawable.SetColor() not working!!
Post by: wilbefast on September 14, 2010, 02:10:13 pm
Hi there,

I have great faith in SFML, but I think I may actually have found a bug  :shock:
I'm creating a black rectangle and trying to turn it white retroactively. I stubbornly remains black. SetColor() doesn't seem to be working!

Here the minimal code:

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    //Create the main Window
    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Michael Jackson!");

    //Create a black rectangle
    sf::Shape mj;
    mj = sf::Shape::Rectangle(0,0,128,128,sf::Color(0,0,0));

    //attempt to change the rectangle's colour to white
    mj.SetColor(sf::Color(255,255,255));

    //Create Event handler
    sf::Event event;

    //Start main loop
    bool running = true;
    while (running)
    {
        //Read each Event, store in 'event' and treat
        while (window.GetEvent(event))
            if(event.Type == sf::Event::Closed || event.Type == sf::Event::KeyPressed)
                    running = false;

        //Clear the Windows
        window.Clear(sf::Color(200, 0, 0));

        //Draw the rectangle
        window.Draw(mj);

        //Redraw the Window
        window.Display();
    }

    //Destroy the Window
    window.Close();

    return EXIT_SUCCESS;
}


In actual fact I'm doing stuff a lot trickier than this, but the problem is still visible in this dumbed-down version: the rectangle is created black, and refuses to change colour!

Is this is bug or is it my code? I just don't see what I could be doing wrong when there's so little of it...


William
Title: Drawable.SetColor() not working!!
Post by: Laurent on September 14, 2010, 02:26:44 pm
No, it's not a bug, just something that's not very well documented ;)
http://www.sfml-dev.org/forum/viewtopic.php?t=1387
http://www.sfml-dev.org/forum/viewtopic.php?t=1114
http://www.sfml-dev.org/forum/viewtopic.php?t=2493
http://www.sfml-dev.org/forum/viewtopic.php?t=2916
...
Title: Drawable.SetColor() not working!!
Post by: wilbefast on September 14, 2010, 02:39:02 pm
Ah  :o  so if I want to be able to modify colours on the fly, I just need to create everything white  :)

Finally a problem that isn't entirely my fault  :D