SFML community forums
Help => Graphics => Topic started by: Devil0150 on July 28, 2009, 10:48:26 pm
-
This is the code that makes two rectangles. One inside the other. But I can't see the small rectangle. I tried lowering the Alpha of the big rectangle color and I saw the small rectangle, but not in white color of course. Is there anyway to choose which rectangle is drawn last or something. (I tried changing the changing places of draw statements on the code but didnt work.)
sf::Shape Rect1;
...//some code here
{
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(255, 255, 255));
Window->Draw(Rect1);
sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Window->Draw(Rect2);
}
-
The objects appear in the same order that you draw them. So you have to draw the big one first.
-
You mean like this :
sf::Shape Rect1;
//...
sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Window->Draw(Rect2);
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(255, 255, 255));
Window->Draw(Rect1);
I tried and it didnt work.
-
What does "it didn't work" means? Can you show a screenshot?
-
I dont know how to put an image here but I'll try to explain.
I have two Rectangles
Rect 1 Rect2
__________ _________________
| | | |
| | | |
| | | |
|_________| | |
| |
| |
| |
| |
|________________|
And I put Rect1 inside Rect2 but I see only Rect2. Rect1 isnt visible.
This is how it should look:
____________________
| Rect2 |
| |
| |
| _________ |
| | Rect1 | |
| | | |
| | | |
| |_________| |
| |
| |
|___________________|
And this is how it looks
____________________
| Rect2 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|___________________|
-
I dont know how to put an image here
There are plenty of websites that allow you to upload and store images, like imageshack.us.
Can you post a minimal and complete example that reproduces your problem?
-
I couldnt upload at imageshack so I did it here.
This is how it is:
[img=http://www.freeimagehosting.net/uploads/4bc1a8c0d2.jpg] (http://www.freeimagehosting.net/)
And this is how it should be:
[img=http://www.freeimagehosting.net/uploads/a38284f572.jpg] (http://www.freeimagehosting.net/)
-
Your links are broken. Anyway, I've understood your problem ;)
What about your code?
-
Here is my code. I'm trying to make a simple Paint program.
sf::RenderWindow Paint(sf::VideoMode(800, 600), "Paint");
sf::String GetString()
{
sf::Input mouseInput;
std::stringstream out;
out << "x: " << Paint.GetInput().GetMouseX() << "\ny: " << Paint.GetInput().GetMouseY();
std::string myString;
myString = out.str();
sf::Unicode::Text myText(myString);
sf::String thisString(myText, sf::Font::GetDefaultFont(), 15);
return thisString;
}
class DrawingSpace
{
public:
sf::Shape Rect1;
DrawingSpace(sf::RenderWindow* Paint)
{
// the color panel
sf::Shape Panel = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Paint->Draw(Panel);
// the white color
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(0, 0, 0));
Paint->Draw(Rect1);
// the drawing space
sf::Shape space = sf::Shape::Rectangle(100, 0, 800, 600, sf::Color(0, 0, 0));
Paint->Draw(space);
}
};
int main()
{
DrawingSpace* Space = new DrawingSpace(&Paint);
while (Paint.IsOpened())
{
sf::Event myEvent;
while (Paint.GetEvent(myEvent))
{
if (myEvent.Type == sf::Event::MouseMoved)
{
Paint.Clear();
delete Space;
Space = new DrawingSpace(&Paint);
Paint.Draw(GetString());
}
if (myEvent.Type == sf::Event::Closed)
Paint.Close();
}
Paint.Display();
}
return 0;
}
-
It works for me.
-
I fixed it accidentally while posting here. thx.