Bounding rectangle for a font sprite from objectspace using measurestring

Started by
1 comment, last by Monza 11 years ago

Trying to get the rendered bounding rectangle from a font sprite set to render into objectspace (not screen space) coordinates.

But the d3d9Font.measurestring(sprite ....... only gives the non objectspace rectangle even through the sprite is defined to render in objectspace.

So basically, even though the font is rendered into the 3D scene correctly at the correct depth and perspective based size (eg the same sized font may range from a few to 500 pixels of more depending on depth), I cannot get this size rectangle, because the measurestring only returns a fixed size (eg 250 x 100) regardless of rendered depth as if it was rendered directly to screen with objectspace not set (ie in transformed coordinates)

Do I need to use the defined sprite transformation matrix in another calculation or am I missing something? Is there another way to compute the final text rendered screen size?

Advertisement

Is the returned size just being used in your object space? If so, perhaps the returned size is in pixels (which is normal for sprite based text rendering) and that is the same size regardless of how far away the sprite actually is from your camera.

I'm not familiar with the interface you are using, but try to experiment with it and see if the size returned only varies according to the number of characters when it is a fixed width font (like Consolas). Then do the same test, but use a larger font size. If the size is proportional to the number of characters, and is also proportional to the font size, then I bet the returned value is in pixels...

In that case you just have to scale them according to how large you want the text to appear in your scene.

I'm sure the 'measurestring' returned rectangle is the size of the string if it was rendered to the screen without scaling or transformation. It appears to be based on the size and number of lines of the rendered font. Which would be fine if I was sending it to the screen without transformation.

But the sprite is set to 'objectspace' which transforms and renders it into the scene at a completely different size. This is the size I need (so I can calculate how to draw a bounding box around the text).

Maybe I can 'project' the font sprite bounding box coordinates into the scene to work out the size?

This topic is closed to new replies.

Advertisement