PDA

View Full Version : How to smartly place text in window?



YYOpenGL
11-22-2009, 12:09 PM
I want to place text in window. The text shall automatically shift to another location if the given location is occupied (having other text printed already).

My steps of detecting whether an area is available for print are:
1. Convert text's obj cooridnates into window coordinates;
2. Calculate the size of the rectagnel that holds the text in window;
3. Read all pixels of the rectangle (glReadPixels);
4. Compare each pixel's color with background color;
5. If all pixels hold bg color, pint; otherwise, select another rectangle and repeat 1/2/3/4.

Yet, I can only obtain correct pixel info occasionally.

Could you corrrect the steps if necessary, or suggest a better method of smartly placing text?