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

Author Topic: Drawable.SetColor() not working!!  (Read 2604 times)

0 Members and 1 Guest are viewing this topic.

wilbefast

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • http://wilbefast.com
Drawable.SetColor() not working!!
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

wilbefast

  • Newbie
  • *
  • Posts: 31
    • View Profile
    • http://wilbefast.com
Drawable.SetColor() not working!!
« Reply #2 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

 

anything