Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using FTGL library to render text in my C++ project.

I can easily render text by using:

CFontManager::Instance().renderWrappedText(font, lineLength, position, text);

Unfortunately there is a situation in which this Button which displays text, is partly hidden because of resizing container in which it is situated. I'm able without any problem to draw Button's background to fit the container, but I've got a problem with doing the same with a text. Is it possible to somehow draw only text for given width and the rest just ignore?

This is a screen which presents my problem:

Problem with drawing only a part of text

As you can see, the Button "Click here" is being drawn properly, but I can't do the same with "Click here" text.

share|improve this question
1  
I think you'd have to figure out the width of your text string based on font size beforehand somehow, and then only print what would fit based on that. I don't know if FTGL has a way to do that or not. –  Eric B Nov 26 '12 at 12:55
    
@EricB That's what I was afraid of... I think FTGL doesn't have such possibility. But even though if I achieve this, I would be able only to cut off specific number of letters. What if I'd like to cut one letter (for example 'k' on sample screenshot I gave) in a half? Is it impossible? –  Piotr Chojnacki Nov 26 '12 at 13:03
1  
nothing's impossible, but to do that you would certainly have to use standard freetype and then manipulate the bitmaps it gives you yourself, messing with the texture coordinates and so on. So... what you're looking for CAN be done, but not quickly or easily. –  Eric B Nov 26 '12 at 13:15
    
@Mosquito: Please stop cross-posting questions. –  Nicol Bolas Nov 26 '12 at 23:09

1 Answer 1

up vote 3 down vote accepted

Perhaps you could try scissor testing the window when drawing text?

glEnable(GL_SCISSOR_TEST);
glScissor(windowX, windowY, windowSizeX, windowSizeY);
CFontManager::Instance().renderWrappedText(font, lineLength, position, text);
glDisable(GL_SCISSOR_TEST);

You can also apply this to everything within the window as a single, unified solution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.