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

Author Topic: strange setcolor() behaviour [solved]  (Read 2431 times)

0 Members and 1 Guest are viewing this topic.

Boogiwoogie

  • Newbie
  • *
  • Posts: 19
    • View Profile
strange setcolor() behaviour [solved]
« on: March 17, 2009, 04:23:20 pm »
hi all!
yesterday i checked out the tutorial on displaying text and downloaded the corresponding source at the bottom of the page.
http://www.sfml-dev.org/tutorials/1.4/graphics-fonts.php

having played around a little with it, i started to add some rectangles, and didnt manage to set the color for it. once the rect is created, the setcolor() method doesnt work as it should (imho).
however, if no setcolor() is called, the rect is displayed correctly, so as a workaround one may use a set of rects, one for each color...

code snippet (its pretty much at the end of the tutorial-code)

Code: [Select]
       

        // Make the second string rotate
        Bonjour.Rotate(App.GetFrameTime() * 100.f);

        // Clear screen
        App.Clear();

        sf::Shape r = sf::Shape::Rectangle(100, 100, 200, 200, sf::Color(255, 50, 50)); // bright red
        sf::Color col(50, 255, 50); // bright green
        r.SetColor(col);
        r.SetColor(sf::Color(50, 50, 255)); //bright blue
        App.Draw(r);


        // Draw our strings
        App.Draw(Hello);
        App.Draw(Bonjour);
       


if i comment out the setcolor()-lines, i get different results, none of
them actually predictable (except if i get rid of both the lines).
if i replace the rgb values that are 50 by the value 10 (leaving all the 255 as they are ;), i dont get a rectangle at all.

boogie

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
strange setcolor() behaviour [solved]
« Reply #1 on: March 17, 2009, 04:50:16 pm »
The color you pass when creating your rectangle is assigned to every point. It has nothing to do with the global color set with SetColor. What you get is a combination (modulation) of both: the global color and the points color.
Laurent Gomila - SFML developer

Boogiwoogie

  • Newbie
  • *
  • Posts: 19
    • View Profile
strange setcolor() behaviour [solved]
« Reply #2 on: March 17, 2009, 05:12:59 pm »
Quote from: "Laurent"
The color you pass when creating your rectangle is assigned to every point. It has nothing to do with the global color set with SetColor. What you get is a combination (modulation) of both: the global color and the points color.


uhh - i see. works for me now... ;)
so actually its smart to construct it using white, then setcolor does all the magic i need.

thx for quick help!
boogie