View Full Version : Position text with glrasterpos

04-07-2010, 12:43 PM

I am currently using bitmap fonts in my Windows Form application and the Tao Framework with wglUseFontBitmapsA but I am having trouble positioning the text properly. I am able to get the text to display on the control and position the text using glrasterpos3f(). I am trying to draw a polar graph in my window and would like to label the angles around the axis. I am able to calculate the positions without any problem for the angles on the right side of the graph but for the angles on the left half of the graph, the text is overlapping onto the graph. I know that this is because the text renders left to right and the raster position is the lower left corner of the first letter. Therefore, I need to compensate for this by subtracting the width of the string from my raster position's X coordinate. Is there a way to calculate the width of a bitmap string? I know I can accomplish this by getting the difference of the GL_CURRENT_RASTER_POSITION before and after the glCallLists command but by then my text is already rendered. Is there a better method?


04-08-2010, 12:58 PM
This seems entirely related to the library you use to rasterize the font to the bitmap and not really an OpenGL issue. OpenGL really knows nothing about the width of the contents of an image you have generated. If I understand your question correctly.

04-08-2010, 01:37 PM
Something around GetGlyphOutline metrics sould get you the data you need :

05-04-2010, 01:43 PM
Dorbie, I believe you are correct since it doesn't really relate to OpenGL but it's just that I'm trying to do it in OpenGL. The way I got around it was to render a character and use glrasterpos before and after the rendering to calculate the width of a single character. So now I have the width of a character and can multiply it by the string length.

Zbuffer, your solution is probably what I need to do but I have not been able to experiment with this nor do I know how to begin using it in VB.NET. I am currently not modifying the display font but would like to really soon. Ideally, I want to be able to use a smaller font in a smaller opengl window.