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.

  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Eric B Nov 26 '12 at 12:55
  • \$\begingroup\$ @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? \$\endgroup\$ – Piotr Chojnacki Nov 26 '12 at 13:03
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Eric B Nov 26 '12 at 13:15
  • \$\begingroup\$ @Mosquito: Please stop cross-posting questions. \$\endgroup\$ – Nicol Bolas Nov 26 '12 at 23:09

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

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

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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