Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using SFML 2.1 and have an Image with some objects that I would like to number, i.e. I have a set of origin coordinates for each of them so I would place the number there.

However, I can't seem to find a good way to do this: the most relevant function seems to be Image::copy() which places a rectangle in the image. To use that, I would have to create a number map image and then do offsets for successive numbers, which seems tedious, cumbersome and unreliable, as an image with too many objects would eventually run out of numbers.

I also thought of conceivably using a RenderWindow object and printing the Image along with numbers as sf::Text objects with the right coordinates, but the API does not seem to provide a way to save the contents of the window to an image.

So the question is: is there a straightforward way to place numbers (text in general) in an Image object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
242 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your question is rather unclear, thus I guess the negative ratings.

If you want to render text, you can simply draw an sf::Text object to an sf::RenderWindow object. If you want to reuse the final result you can switch out the sf::RenderWindow with a sf::RenderTexture. If you want to manipulate single pixels, you'll have to go with an sf::Image, but keep in mind the conversion from image to texture is a slow process, so don't do it, if it isn't necessary.

See the official documentation and tutorials on how to work with SFML.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...