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

Author Topic: Drawing just an sf::Image?  (Read 3021 times)

0 Members and 1 Guest are viewing this topic.

TheCommunistDuck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Drawing just an sf::Image?
« on: March 26, 2010, 09:51:38 pm »
Hi.

sf::Image doesn't actually derive from sf::Drawable, so how would you draw one to the screen?
I ask because my current project requires me to edit pixels in an sf::Image and then draw it to the screen. I've tried plugging it into an sf::Sprite and then GetImage(), but that returns a const sf::Image which I can't modify. Any ideas anyone, for either way?

Thanks. :D

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Drawing just an sf::Image?
« Reply #1 on: March 26, 2010, 10:01:14 pm »
What if you just have your sf::Image in your memory, modify it asyouwant, and whenever you want it to draw, just make an sf::Sprite from it, and draw that to the screen?

TheCommunistDuck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Drawing just an sf::Image?
« Reply #2 on: March 26, 2010, 10:14:43 pm »
Wouldn't that consume a lot of memory, doing it 60 times a second though?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Drawing just an sf::Image?
« Reply #3 on: March 26, 2010, 11:18:52 pm »
Quote
Wouldn't that consume a lot of memory, doing it 60 times a second though?

No ;)
But you don't have to setup a new sprite every frame, you can just create it once. You don't even need to call SetImage after modifying the image.
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Drawing just an sf::Image?
« Reply #4 on: March 26, 2010, 11:24:55 pm »
Quote from: "Laurent"

But you don't have to setup a new sprite every frame, you can just create it once. You don't even need to call SetImage after modifying the image.


Wow... There is always something to learn :D

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Drawing just an sf::Image?
« Reply #5 on: April 06, 2010, 04:52:26 am »
That is what I am currently doing. The way my rendering system was already set up before using SFML kinda required it. Same goes for drawing text. I just create a single Sprite and String2D and set it up before each draw. Very simple and low overhead. :)