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

Author Topic: Constructing a texture or image from what is drawn on the screen?  (Read 2519 times)

0 Members and 1 Guest are viewing this topic.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
I forget how to do this.  I know there is a way to build a texture or image from things drawn on the screen but forget how to do it.  Say a black square acts as what will be transparent and there are many green triangles draw connected together with either Shape or Vertex.  I'm working on a unit builder/editor with this and I'm going to save the created image in a database or in memory for use later in a game I'm working on.  The database would only care about the points needed to remake the image later so the only real issue is the creation of the image itself.

The idea is a player uses the editor to make some unit or structure with some shapes that gets saved as a new image for use by that unit or structure later.  In game it would be a single texture or image but in the editor it is the many smaller textures or images used to make it.

Any ideas?
I have many ideas but need the help of others to find way to make use of them.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Constructing a texture or image from what is drawn on the screen?
« Reply #1 on: February 22, 2015, 11:41:11 pm »
(I kinda listed them in the order of their speed, but 1. is useless on its' own if you want a subrect, since there is no SFML pure way to get a subrect of Texture into new one, I don't know if there is a GL way to do that even, but there might be. If you do it only on 'unit save' then speed shouldn't matter anyway so I'd say go for 3.)
1. Texture has update method that you can use to download entire window into it (but you probably want a subrect...).
2. You can use RenderTexture for the image editing space itself and copy its' internal texture when you are done and then throw away the RenderTexture itself.
3. RenderWindow has capture method which will get the window's content as an Image and then you can load (a part of) that to Texture using loadFromImage with custom subrect.

1. is pure GPU (but useless if you want a subrect), 2. and 3. take a trip through CPU.
« Last Edit: February 22, 2015, 11:47:40 pm by FRex »
Back to C++ gamedev with SFML in May 2023

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Constructing a texture or image from what is drawn on the screen?
« Reply #2 on: February 23, 2015, 12:02:11 am »
I don't know if there is a GL way to do that even, but there might be.
glCopyImageSubData ;D

But... like FRex said, the best way to do it using only SFML is to draw to a RenderTexture and draw that RenderTexture to the screen. This way you have access to its framebuffer ("screen") contents through the SFML-only API via getTexture() which you can either process on the GPU or copy to the CPU as an Image.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Constructing a texture or image from what is drawn on the screen?
« Reply #3 on: February 23, 2015, 01:17:25 am »
hmm sounds like it might be fun to get working.
I have many ideas but need the help of others to find way to make use of them.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Constructing a texture or image from what is drawn on the screen?
« Reply #4 on: February 23, 2015, 02:11:27 pm »
« Last Edit: February 23, 2015, 02:13:00 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG