SFML community forums

Help => Graphics => Topic started by: dweomer21 on May 19, 2013, 08:48:14 am

Title: How to render text to a specific rect / clipping mask in window
Post by: dweomer21 on May 19, 2013, 08:48:14 am
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

Title: Re: How to render text to a specific rect / clipping mask in window
Post by: fallahn 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
Title: Re: How to render text to a specific rect / clipping mask in window
Post by: Laurent on May 19, 2013, 09:22:58 am
https://github.com/SFML/SFML/issues/1
Title: Re: How to render text to a specific rect / clipping mask in window
Post by: dweomer21 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!
Title: Re: How to render text to a specific rect / clipping mask in window
Post by: Laurent 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.
Title: Re: How to render text to a specific rect / clipping mask in window
Post by: dweomer21 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.