SFML community forums

Help => Graphics => Topic started by: troopson on June 14, 2011, 07:32:27 pm

Title: Paint
Post by: troopson on June 14, 2011, 07:32:27 pm
I'm trying to make a Paint application.
How do i draw shapes/lines to a buffer like Image ? I can't paint everything directly to the window because when i resize/move etc the window it all dissapears. I wanted to do something like draw everything to an image and in main loop draw the image. How do i do that in sfml?
Title: Paint
Post by: Laurent on June 14, 2011, 08:02:40 pm
You can't draw to an image with SFML 1.6.

Quote
I can't paint everything directly to the window because when i resize/move etc the window it all dissapears.

???
Maybe we should try to solve this problem instead ;)
It looks like you're only painting things once, whereas they should be painted in an infinite loop that clears/draws/displays.
Title: Paint
Post by: troopson on June 14, 2011, 10:44:03 pm
"It looks like you're only painting things once, whereas they should be painted in an infinite loop that clears/draws/displays."

well... u want me to draw 923592592 lines and remember it all ?Any other ideas?:P
Title: Paint
Post by: Laurent on June 14, 2011, 10:57:39 pm
Quote
well... u want me to draw 923592592 lines and remember it all ?Any other ideas?

How do you implement undo/redo ? ;)

Anyway, you should switch to SFML 2. Drawing to an image is the only other solution, and it is not available in SFML 1.
Title: Paint
Post by: David on June 15, 2011, 03:54:07 am
Quote from: "Laurent"
Quote
well... u want me to draw 923592592 lines and remember it all ?Any other ideas?

How do you implement undo/redo ? ;)

Anyway, you should switch to SFML 2. Drawing to an image is the only other solution, and it is not available in SFML 1.


What do you mean by drawing to an image?

You can make a pixel-sized image and create a dynamic array so you'll be able to undo/redo and save. If the pixels aren't limited to the FPS (maybe you can make it a triple digit number, I haven't tested this out), it should work out. You can also create a funky algorithm that creates a line made up of more pixels if there happens to be a gap between them
Title: Paint
Post by: Laurent on June 15, 2011, 06:59:11 am
Quote
What do you mean by drawing to an image?

I mean this
Code: [Select]
sf::Image image;
sf::Sprite sprite;
image.Draw(sprite);

(it's not like this in SFML 2 but it's more obvious this way)
Title: Paint
Post by: AlexRAwesome on June 15, 2011, 12:48:37 pm
Quote from: "Laurent"
Quote
What do you mean by drawing to an image?

I mean this
Code: [Select]
sf::Image image;
sf::Sprite sprite;
image.Draw(sprite);

(it's not like this in SFML 2 but it's more obvious this way)


It kinda looks like you're drawing nothing because "sprite" does not have an image set
Title: Paint
Post by: Laurent on June 15, 2011, 12:57:01 pm
Quote
It kinda looks like you're drawing nothing because "sprite" does not have an image set

Did you actually read the previous messages before answering? :lol:

This piece of code was just an example to show what rendering to an image means. It's not supposed to do anything useful...
Title: Paint
Post by: troopson on June 15, 2011, 04:16:42 pm
i dont want to write code which draws a line/circle/stuff (know its not so hard);p
Title: Paint
Post by: Nexus on June 15, 2011, 04:23:45 pm
Quote from: "troopson"
i dont want to write code which draws a line/circle/stuff
But you want to write Paint?

What's wrong with the solutions given in this thread?