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

Author Topic: How to render text to a specific rect / clipping mask in window  (Read 5233 times)

0 Members and 1 Guest are viewing this topic.

dweomer21

  • Newbie
  • *
  • Posts: 8
    • View Profile
I'm new to SFML, and am hoping that I'm just missing something obvious.
I'm trying to render text to a rect on the screen, and I want the rect to act like a clipping mask.  So, if I have a 30-line paragraph in my sf::Text object, for example, I'd like to be able to render it to the rect so that it does not overflow the bounds of the rect. I don't care if it still renders offscreen (in other words, I don't need the rect to wrap text or anything) -- I just don't want to see any of the text that would show up outside the rect.
Is this possible?  I've been fighting this for two days now, and it's GOT to be because I don't know what I'm doing!  Maybe rendering the text as a texture or sprite or something?
Thanks for any pointers.  And sorry for my ignorance :-)
--scott


fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: How to render text to a specific rect / clipping mask in window
« Reply #1 on: May 19, 2013, 09:10:44 am »
You could draw the text to a renderTexture the size of the clipping rectangle, then create a sprite from that to draw it to the screen

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

dweomer21

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: How to render text to a specific rect / clipping mask in window
« Reply #3 on: May 20, 2013, 05:22:29 am »
Thanks to both of you. 
I'm implementing a MUD-like console game, which is, unfortunately, looking more and more like it is not a good match for SGML, since it mostly deals with text.  It's kind of a hard match for any graphics lib, however.  I've been using pdcurses, but the problem there is that the event system is blocking, so I can't poll for keyboard events (not to mention that we'd like to use sprites for inventory items).
Anyway, that's just a little background on where I'm coming from. 
I've tried out Allegro, SGML, and SDL, and I like SGML the best so far... but I may have to just wait to use it for my next project, which will hopefully get into the graphics realm.

Thanks again, and keep up the excellent work!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to render text to a specific rect / clipping mask in window
« Reply #4 on: May 20, 2013, 08:59:10 am »
If you've read issue #1, you certainly noticed the simple workaround which is suggested, using sf::View.
Laurent Gomila - SFML developer

dweomer21

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: How to render text to a specific rect / clipping mask in window
« Reply #5 on: May 20, 2013, 09:18:48 pm »
Aha!  I got it to work as fallahn suggested!  I needed text scrolling as well, and I was a little discouraged by what I thought would be a huge sloppy hack, but it turned out to not be that bad.  I alter the View to scroll, and I think this makes it workable. Yay, now I can continue using SFML.

Thanks again for you time.