Sign in to follow this  
MasterSlowPoke

Best way to render text in front of a grid mesh

Recommended Posts

For a game I'm making, I have a 6x5 cell triangular grid mesh centered at the origin, and a camera pointing at it. I'd like to render some text over each of the cells, but I can't think of the best way to approach it. My first idea was to render directly to screen coordinates, as my camera is static. However, if the game window is resized I'll need new coordinates, and I can't think of a good way to calculate them. I could just prevent window resizes, but I'd rather not as that seems like a poor solution. My next idea would be to have 30 quads sitting in front of the grid mesh, and render the text to a texture, but I have no idea how to generate the coordinates for this, either. I suspect it would involve the projection matrix, though. I'm using DirectX, but I think this is a problem of theory rather than API.

Share this post


Link to post
Share on other sites
Using screen coordinates sounds like a good idea. To get the coordinates base on world coordinates, you'll need to project the world coordinates into screen coordinates. This way, you can bind your text to a specific on the grid but have them drawn in screenland.

-jouley

Share this post


Link to post
Share on other sites
Wow, thanks a lot! I don't use Managed DirectX (yet), so I was going to build my own version of that function. At the last second I decided to recheck the MSDN and found the C++ version of the function (D3DXVec3Project). With some fiddling, I got it to snap to the grid perfectly! Well, almost perfectly. It's occasionally +/- 1 pixel off in the y direction, depending on the viewport size. It's not a huge issue, and will likely never be seen as the edges will be transparent anyhow, but do you have any idea why?

Share this post


Link to post
Share on other sites
Quote:
Original post by MasterSlowPoke
Wow, thanks a lot! I don't use Managed DirectX (yet), so I was going to build my own version of that function. At the last second I decided to recheck the MSDN and found the C++ version of the function (D3DXVec3Project). With some fiddling, I got it to snap to the grid perfectly! Well, almost perfectly. It's occasionally +/- 1 pixel off in the y direction, depending on the viewport size. It's not a huge issue, and will likely never be seen as the edges will be transparent anyhow, but do you have any idea why?

Whoops! I haven't done much with DirectX, so I didn't even think to check the area of MSDN I was linking to. I'll keep that in mind for the future... Glad you found what you needed, though. [smile]

As far as the jitter goes, I'd assume it has to do with mapping the floating point values of the world to the discrete integers of the screen; some mapping ranges (viewport sizes) produce more accurate results (not being +/- a pixel off). As you say, it's probably not a big deal.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this