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

Author Topic: Pass a vertex array to an sf::Image  (Read 1741 times)

0 Members and 1 Guest are viewing this topic.

bendy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Pass a vertex array to an sf::Image
« on: December 23, 2014, 06:17:05 pm »
I'm fairly new at this. I can draw user defined vertex arrays to the screen/window, and also define/export an image pixel by pixel. Is there a way to combine the two? I mean to create a vertex array and then export it as an image as a .png etc..
Thanks a bunch.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Pass a vertex array to an sf::Image
« Reply #1 on: December 23, 2014, 06:21:29 pm »
The short answer is no you can't do this, because vertex arrays are meant to be input to your GPU that tells it what texture coordinates to map to what screen coordinates.  As far as I know, GPUs cannot output directly to ordinary RAM (which is where sf::Images are).

But you can do something very similar by rendering to an sf::RenderTexture (with the usual clear/draw/display) because that puts the GPU's "output" somewhere that you're allowed to access and do further work on.  So after the display() call, simply use getTexture() to get an sf::Texture of what it drew, convert that to an sf::Image, then use sf::Image::saveToFile().  Obviously, don't do this every frame, but for something like exporting image files this is the way to go.
« Last Edit: December 23, 2014, 06:24:38 pm by Ixrec »

bendy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Pass a vertex array to an sf::Image
« Reply #2 on: December 23, 2014, 07:03:17 pm »
Thanks, worked perfectly. :)

 

anything