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

Author Topic: How to build an image in memory?  (Read 1369 times)

0 Members and 1 Guest are viewing this topic.

ichineko

  • Newbie
  • *
  • Posts: 44
    • View Profile
How to build an image in memory?
« on: November 17, 2012, 11:05:45 pm »
I'm slapping together a quick tetris clone to familiarize myself with SFML.

I have an image of a single block for a tetrimino, and what I would like to do is 'build' the entire tetrimino image, and just keep that for rotations, and so on.

I'm not sure how to go about doing this with SFML.  Could someone link me to the documentation I should be reading and/or describe roughly how you would go about doing it?

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: How to build an image in memory?
« Reply #1 on: November 17, 2012, 11:25:37 pm »
http://www.sfml-dev.org/documentation/2.0/annotated.php

A couple of ways I can think of..
1. manually copy and transform the image data into an Image.

sf::Image img;
img.setPixels(.....);
sf::Texture tex;
tex.loadFromImage(img);
sf::Sprite spr(tex);

2. Load the image into a sf::Sprite, then create a RenderTexture to store all the new sprites. Draw the main sprite into the rendertex using sprite.draw(...), rotate, etc ... tracking the bounds of the sprites (essentially building a sprite map in memory). Then use the texture from the rendertexture and the frames of the sprites to create all the sf::Sprites;

ichineko

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: How to build an image in memory?
« Reply #2 on: November 18, 2012, 10:18:43 pm »
Thanks eigenbom, I was able to get what I needed from that.  I decided to go a different approach, but not before seeing how a technique like that would work.