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

Author Topic: CreateMaskFromColor  (Read 3154 times)

0 Members and 1 Guest are viewing this topic.

kidchameleon

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
CreateMaskFromColor
« on: December 12, 2011, 11:53:48 pm »
Hi All,

If I'm using an image I can use the CreateMaskFromColor function to remove pixels from the image. Is there any way I can do this with a render texture?

Thanks.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
CreateMaskFromColor
« Reply #1 on: December 13, 2011, 12:19:10 am »
You could get the texture using GetTexture function and then get an Image using CopyToImage function of that texture. Finally, use CreateMaskFromColor function.

It may be a slow operation.

Cheers.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
CreateMaskFromColor
« Reply #2 on: December 13, 2011, 07:54:50 am »
Can't you draw things directly with the right alpha, instead of creating it from a color after everythings drawn?
Laurent Gomila - SFML developer

kidchameleon

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
CreateMaskFromColor
« Reply #3 on: December 13, 2011, 09:07:04 pm »
@julen,

Thanks ill give that a shot now!

@laurent

Well I'm drawing a colorful background, than another completely black background over it, finally I want the shapes of my sprites to cut into the black background, leaving a nice view of the colorful background. Its kind of hard to describe what I'm doing, its like the "Crayon Scratch Art" that you would have done in school.

kidchameleon

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
CreateMaskFromColor
« Reply #4 on: December 13, 2011, 09:49:58 pm »
Quote from: "julen26"
You could get the texture using GetTexture function and then get an Image using CopyToImage function of that texture. Finally, use CreateMaskFromColor function.

It may be a slow operation.

Cheers.


Ok so Ive done that, sucess!!!!!

Only problem is that my entire scene is fliped? Perhaps one of the methods fips an image / texture during conversion?

Anyway my game is looking great!

kidchameleon

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
CreateMaskFromColor
« Reply #5 on: December 13, 2011, 10:05:56 pm »
Quote from: "kidchameleon"
Only problem is that my entire scene is fliped? Perhaps one of the methods fips an image / texture during conversion?

Anyway my game is looking great!


Problem solved guys, it would appear that when CopyToImage() is invoked, the image is vertically flipped. The solution I found is to to flip it vertically again after the copy. Now my scene looks perfect. I'm not sure what the performance hit is with all these image / texture copy's but so far the FPS is fine.

Thanks again for your help guys.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
CreateMaskFromColor
« Reply #6 on: December 13, 2011, 10:43:29 pm »
Quote
it would appear that when CopyToImage() is invoked, the image is vertically flipped

Don't forget to call Display() on your render-texture.
Laurent Gomila - SFML developer

kidchameleon

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
CreateMaskFromColor
« Reply #7 on: December 13, 2011, 11:59:47 pm »
Quote from: "Laurent"
Quote
it would appear that when CopyToImage() is invoked, the image is vertically flipped

Don't forget to call Display() on your render-texture.


Yep, done that, that's a better way of doing it, cheers Laurent!