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

Author Topic: Destructible terrain, best way w/ SFML?  (Read 3786 times)

0 Members and 2 Guests are viewing this topic.

Haikarainen

  • Guest
Destructible terrain, best way w/ SFML?
« on: December 09, 2011, 02:32:32 am »
Think something like worms. How to do this in a fast and effiecent way is hard for me to think about, when limited to SFML (sf::Image is out of question since the slow pixelacces)

Thinking about having a sf::RenderTexture for the terrain, and then just render circles where I want to reshape the terrain(blow it up). Problem is, can you render transparent pixels to an sf::RenderTexture and have the alphachannel override (set instead of add) the old pixels? If not, I should probably have a colormask (like 255,255,0 is transparent), but then, how would you render that mask transparent?

Also a rendermask would also be awesome, so that you can render "edges" of the blown up circles, but only contain them to where it used to be terrain.

Discuss!

nitrix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Destructible terrain, best way w/ SFML?
« Reply #1 on: December 09, 2011, 03:39:57 am »
I'll suggest to look into sf::Texture::Update() from SFML2 until somebody can answer you better than I ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Destructible terrain, best way w/ SFML?
« Reply #2 on: December 09, 2011, 07:39:18 am »
Quote
Thinking about having a sf::RenderTexture for the terrain, and then just render circles where I want to reshape the terrain(blow it up). Problem is, can you render transparent pixels to an sf::RenderTexture and have the alphachannel override (set instead of add) the old pixels?

Maybe the alpha channel is overwritten when you disable alpha-blending (sf::Blend::None). I'm not sure.

Quote
I'll suggest to look into sf::Texture::Update() from SFML2

Yep, this technique is a good option too -- maintaining your own array of pixels and updating the texture when needed.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Destructible terrain, best way w/ SFML?
« Reply #3 on: December 09, 2011, 09:26:14 pm »
Quote from: "Laurent"
Maybe the alpha channel is overwritten when you disable alpha-blending (sf::Blend::None). I'm not sure.


Worth a shot!

Quote from: "Laurent"
Yep, this technique is a good option too -- maintaining your own array of pixels and updating the texture when needed.


This would be a way too slow and problematic approach, It would be so much simpler and more powerful to just draw directly to the texture.

Haikarainen

  • Guest
Destructible terrain, best way w/ SFML?
« Reply #4 on: December 17, 2011, 04:37:56 am »
Quote from: "Haikarainen"
Worth a shot!


None of the blend modes forces transparency. How slow do you think it would be to Texture::Update(Image) in realtime? with iterating pixels manually as well. The holes would range from 8x8 to 256x256~ :/


I'll go through the source and try to come up with a solution (If its successfull I might just add a Drawable::ForceTransparency(bool) or something, and post the code If you might want to implement something likewise)