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

Author Topic: Backbuffer capture or multiple sprite copy to texture, CSFML 2.5.0  (Read 301 times)

0 Members and 1 Guest are viewing this topic.

CrimsonLaceStudio

  • Newbie
  • *
  • Posts: 3
  • Yuki's favorite code monkey
    • View Profile
    • FX-Unit Yuki
    • Email
So what I need to do is either capture the backbuffer to a sprite or find a way to render an entire scene's worth of sprites to another texture so I can utilize that... basically, I need to be able to capture the current frame and utilize it as a sprite. I have been pulling out my non-existant hair for 8 hours now trying to figure out a way to do this and I got nothin'. Everything I have tried either doesn't work or gives me incorrect results. For example, I've tried using sfRenderWindow_capture, which would actually make the most sense, and it returns the total window size (my window at present is 1592x896, which is what the capture grabs, but I only need the backbuffer size of 398x224), which isn't what I need... and then sfTexture_updateFromRenderWindow doesn't even work at all, despite there being a code example in the header. I can't see any functions to copy sprites from one texture to another, and the Image header is of no help either. The reason for all of this? Well, I want to capture the current frame to a sprite so I can create a transition from one scene to the next... basically, I capture the current frame and use it as a fading overlay as the next scene is displaying. I hope that all makes sense. I don't care how expensive a process it is, since it only has to be done once, even if it's just manually copying pixels (which I also don't see any way to do). The header descriptions.... aren't the best, unfortunately. I have read about RenderTexture a bit, and I figured maybe I could just do a second draw of all my sprites to that, but then how do I even utilize the RenderTexture? I see nothing outside of just sfRenderTexture_display, which doesn't look like it will work very well, since I see no options for setting its opacity. What am I missing? Am I a total dunce? I'm really stumped here, and that ain't easy. Any ideas? Thanks a billion in advance. :D
« Last Edit: October 18, 2022, 04:26:54 pm by CrimsonLaceStudio »
I code the Yuki things...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10394
    • View Profile
    • development blog
    • Email
Re: Backbuffer capture or multiple sprite copy to texture, CSFML 2.5.0
« Reply #1 on: October 18, 2022, 07:08:25 pm »
If you want to use something you rendered as a texture, then the sfRenderTexture is your solution.
You can use it like you would with a sfRenderWindow.

Call sfRenderTexture_create, then sfRenderTexture_clear and sfRenderTexture_drawSprite, and finally sfRenderTexture_display. Then you can extract the texture with sfRenderTexture_getTexture and use the returned texture with your sprite.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

CrimsonLaceStudio

  • Newbie
  • *
  • Posts: 3
  • Yuki's favorite code monkey
    • View Profile
    • FX-Unit Yuki
    • Email
Re: Backbuffer capture or multiple sprite copy to texture, CSFML 2.5.0
« Reply #2 on: October 18, 2022, 08:39:52 pm »
Ooh ok, awesome... because sfRenderTexture_getTexture returns a sfTexture pointer... that should work nicely. Thank you!

EDIT: Excellent! After a bit more hair-pulling and cursing at invisible demons, I did eventually get the desired result.

sfSprite_setTexture(transition.sprite, sfRenderTexture_getTexture(transitionrendtex), sfFalse);
That was the part I was a bit unsure of, even with your advice, but I eventually figured out just how to use the getTexture bit. Everything else seemed to be in working order... all of the sprites were being drawn to the RenderTexture just fine, as all I had to do was basically copy the original code and change the destination, then I could just draw that RenderTexture'd sprite to the main window with an alpha value at the end of the scene draw function... and I got the nice fade effect I was looking for. Dang, what a process... but it works now, and that's the important thing. I'm going to add your name to the special thanks list of our game if you'd like. 8)
« Last Edit: October 18, 2022, 11:09:33 pm by CrimsonLaceStudio »
I code the Yuki things...

 

anything