Jump to content
  • Advertisement
Sign in to follow this  
orphankill

[SOLVED] Coordinate issues

This topic is 3784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, for a while now I've been using the D3DXFONT class to render fonts. In order to render the fonts, you need to specify a RECT structure which contains the location of the text on the screen. The problem is, when resolution changes or window resizes occur, the text is obviously not where I want it. In order to compensate, I've specifying RECT structures like this: RECT example { 12.565/ScreenWidth, 1.323/ScreenHeight..... etc } The numbers are ratios that will work with 4:3 resolutions, but I want to be able to handle all resolutions (naturally). I know there has to be a better way of doing this as everytime I want to render text I have to use a calculator to get the right ratio. How do you guys specify screen coordinates so that they always land in the same positions? I know there's a Screen to World coordinate formula, but the formula's I've found always seem to be inaccurate when switching resolutions. [Edited by - orphankill on July 11, 2008 11:26:37 PM]

Share this post


Link to post
Share on other sites
Advertisement
Just store the coordinates as values ranging from 0.0 to 1.0, where 0,0 is the top left and 1,1 is the bottom right. Then before you pass things to ID3DXFont, just multiply those values by the size of the viewport and you're done.

Share this post


Link to post
Share on other sites
Where would I find the size of my viewport?
I never actually SetViewport() at any point. Do you mean my projection matrix? In that case I declare it like this:

D3DXMatrixPerspectiveFovLH(&matProj,
D3DXToRadian(45), // the horizontal field of view
(FLOAT)m_iScreenWidth / (FLOAT)m_iScreenHeight, // aspect ratio
1.0f, // the near view-plane
1000.0f); // the far view-plane


(Also, I'm using DX9)

Share this post


Link to post
Share on other sites
If you never call SetViewport, the size of the default viewport is the size of your backbuffer. Check your PresentationParameters to see the size you're initially setting.

If you want to support dynamic resizing of your window, you'll need to keep track of size changes when the device resets (that is, when you call Device::Reset).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!