Hello everyone,

I'm working on my game project and my aim is now to produce the interface part. I've found that there is an easy way to produce some text on the screen with glutBitmapCharacter and it's working quite well except the font choice is a little bit restrictive.

So in my interface code I've planned to use additional clipping planes to make sure that the interface "widgets" aren't drawing outside of their given space. It might be a bad idea but since I didn't found a better way I'll give it a try. So my problem happens when I'm using a clipping plane with glutBitmapCharacter, I've found that the characters aren't partially clipped. They are completely drawn or if not in a clipping plane it won't be drawn.

Is it the normal behavior or is it a bug ? When drawing a shape or a line it should be drawn partially right ? This problem becomes serious when any horizontal clipping plane is on the (horizontal) text which won't be drawn. Should I make my own functions to draw characters ? Will I have the same problem as glutBitmapCharacter ?

I hope I've used the right words to describe my problem. If you need details just ask. Thank you in advance.

Recommended Answers

All 3 Replies

Here is some images to explain what is happening and what I would like to have.

example1 is when the clipping planes aren't in contact with the text, all is fine.
example2 is the result when it is in the actual state (text isn't drawn !)
example 3 is what I want.

What are the best solutions to solve this ?

I'm not sure how glutBitmapCharacter works, and these results are very weird indeed. Somehow it must treat each letter as an unclippable entity, which is weird.

I used to render text to the screen the old-school way and it works without problem. That is, create 256 display lists, each rendering a unit-size rectangle with the corresponding letter bitmap in the font-file, except for carriage return, space, tab, newline, etc. for which you do some model-view matrix operation instead (for example: for carriage-return you pop the matrix, for new-line you translate down by 1 unit, for space you move left by 1 unit, so on). Once the display lists are done, all you have to do in to render a string is apply the proper translation, rotation, projection, scaling and do "glCallLists(strlen(your_string),GL_UNSIGNED_BYTE,your_string);", et voilà! No clipping problem or whatever else. And it's pretty fast since it's a display list.

I've found an other way to display text: glutStrokeString. But it's harder and tricky to found the right height and width for any text. I have to scale and translate and it's aliasing.

So I think the next step is to make my own font system. Something similar to what you described but more flexible: like a bitmap with XML files to make irregular font possible, etc... or maybe I could use the font and generate with a specific library the bitmap/texture.
Why? 1/ glutStrokeString and glutBitmapCharacter doesn't let you know the real height of a character neither a string. 2/ The first doesn't work with clipping plane while the second is aliasing. 3/ The fonts are very limited: only 2 with glutStrokeString !

In example4 (second image) you can see my new rendering with the restriction drawn (white lines)
In example5 (first) you can see the clipping in action

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.