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

Author Topic: Drawing questions.  (Read 3316 times)

0 Members and 1 Guest are viewing this topic.

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing questions.
« on: July 21, 2010, 12:33:29 pm »
Hello.
Is there a way to draw a sprite/image onto another sprite/image? I want to do some pre-draw manipulations like blends with alpha brushes I made and I can't figure out how. I find this drawing system to be kind of weird.
Maybe I'm just used to Allegro's method, which by the way, is great.

Anyway. Thanks in advance.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing questions.
« Reply #1 on: July 21, 2010, 01:50:57 pm »
It depends what you want to do. You have Image::Copy to copy an image to another (possibly with alpha enabled), or you can do things manually if you know how you want to blend pixels.

In SFML 2 you can use the RenderImage class to draw directly to an image rather than to a window.
Laurent Gomila - SFML developer

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing questions.
« Reply #2 on: July 21, 2010, 02:18:55 pm »
Well basically I want to make an heightmap on an image using an alpha brush and painting (blotting would be a better word) on random spots on the image. Then I would read each pixel in the image/sprite and convert it to a height array. Then boom, I got a heightmap.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing questions.
« Reply #3 on: July 21, 2010, 02:47:41 pm »
If you only have alpha to apply (no transformation), then Image::Copy will do the job.
Laurent Gomila - SFML developer

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing questions.
« Reply #4 on: July 21, 2010, 02:54:40 pm »
Quote from: "Laurent"
If you only have alpha to apply (no transformation), then Image::Copy will do the job.

Very awesome. I'm reading up on the function and will test it soon.

[EDIT]
Do you use it like this?:
largerDestinationImage.copy(alphaBrushImage, randomX, randomY, IntRect(0, 0, 32, 32), true);
This copies a 32 by 32 pixel square from alphaBrushImage onto largerDestinationImage at (randomX,randomY), with alpha...I assume?

[EDIT EDIT]
"This function does a slow pixel copy and should only be used at initialization time".
Is this something to be put off by? I'm going to perform this action atleast 30 times on one destinationImage.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing questions.
« Reply #5 on: July 21, 2010, 03:19:25 pm »
Quote
Do you use it like this?:
largerDestinationImage.copy(alphaBrushImage, randomX, randomY, IntRect(0, 0, 32, 32), true);
This copies a 32 by 32 pixel square from alphaBrushImage onto largerDestinationImage at (randomX,randomY), with alpha...I assume?

Correct.

Quote
"This function does a slow pixel copy and should only be used at initialization time".
Is this something to be put off by? I'm going to perform this action atleast 30 times on one destinationImage.

"slow" means "don't use it 30 times per second". If you call it 30 times during initialization, it's ok.
Laurent Gomila - SFML developer

hagel

  • Newbie
  • *
  • Posts: 23
    • View Profile
Drawing questions.
« Reply #6 on: July 21, 2010, 03:22:51 pm »
Quote from: "Laurent"
Quote
...

Correct.

Quote
...

"slow" means "don't use it 30 times per second". If you call it 30 times during initialization, it's ok.

Much appreciated.