Displaying some text with a box around it


I can print some text and i know how to do a box but i have acoupld of qustions. I would like to create a box around the text, how can i do that please? I basically need to know how to calculate the width of the text, if i am using bitmap fonts.

And how can i get a transparent box, trying to give it a cool effect, i though that glCOlor4f(0,0,0,0.5); would give a transluecent box buit that dint work.

Any help would be appreciated.

Hi !

You need to enable blending to get transparancy working, have a peek at any OpenGL tutorial on blending.


You can parse the string character by character, calling glutBitmapWidth each time. Sum the results to get the total width of the string in pixels. If you’re using a fixed-width font, then you only need to do this for one character and then multiply by the length of the string. You might also have to account for the width taken up by the space between characters.