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

Author Topic: Drawing over previous drawing  (Read 2346 times)

0 Members and 1 Guest are viewing this topic.

NON

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Drawing over previous drawing
« on: December 04, 2012, 10:44:26 pm »
Hello
In my game I have a function asking the player for number. I use it in the game's options menu among other things. It can look like this:
"PROJECTILE DELAY (ms) : 25"

And when you press return with this one selected, the player can modify this number, it should look like this:
"PROJECTILE DELAY (ms): 25_"

Where the "_" is the cursor for editing the number.

I recently switched from SDL to SFML 2.0, which I'm mostly very happy about. But I'm stuck on this function.
In SDL, the calling function first rendered its things (options menu), then called the number query function with parameters given for where to draw the number while its being typed. The query function simply drew the number over the background left from the calling function.

SFML's "philosophy" seems to be that everything should be drawn at once from a cleared screen. This gives me a problem here. The query function doesn't know anything about the background images.

One solution I see is to have the query function take a screen shot, using sf::RenderWindow::capture(). Saving that to a png file. Then load that to a texture, and render over that while the player edits the number. But it just seems... dumb somehow :P

How can I do this? What about my idea?

Can I capture the screen and use that for drawing directly, instead of having to save it to a file first?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing over previous drawing
« Reply #2 on: December 04, 2012, 11:11:31 pm »
I don't really see the problem, but it looks like you're overcomplicating things because you are used to the way how SDL works. In SFML, everything becomes easier :)

Can't you have a sf::Text of which you change the string when necessary? You don't have to handle the background specifically, just draw it before the text.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

NON

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Drawing over previous drawing
« Reply #3 on: December 04, 2012, 11:49:11 pm »
Sure, http://www.sfml-dev.org/documentation/2.0/classsf_1_1Texture.php#ad3cceef238f7d5d2108a98dd38c17fc5
Thanks!! Haven't tested it yet, but from reading, it seems to do exactly what I want  :)

By the way, could this also be a solution to the problem, when you minimize the window and open it again, it's completely black? Just check for the minimize event (I only assume there is one triggered), and when it happens, store the screen to a texture. On restore (again, I assume there is an event for it), you immediately draw from this texture and update the window.

Can't you have a sf::Text of which you change the string when necessary?
I don't use fonts, I display characters from a .png sheet. And the number querying itself is done and ready (just 40 lines of code to do exactly what I want), so I'd rather not waste time changing how I do it. Thanks for your input anyway.

NightCabbage

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: Drawing over previous drawing
« Reply #4 on: December 05, 2012, 01:10:42 am »
Yes, it sounds to me like you're not sure how to use SFML, and are expecting it to work like SDL (which does software rendering, very different to SFML's hardware rendering).

So SFML works, as you say, by first clearing the screen every frame, and then drawing everything back again :)

This is good in many ways, so don't consider it a bad thing. The rendering is so much faster than SDL that your overall frame rate will generally be much higher.

Once you have everything set up right, after you've restored a minimized window, everything will just draw again like normal. But you do not need to check for minimize event and store everything to a texture (because everything gets drawn every frame anyway).

Sprite Fonts are fine - the Text class just gives you a way of doing it without having to custom code.

 

anything