# [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.

## 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 on other sites
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 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 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 on other sites
Thank you, solved my problem.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633408
• Total Posts
3011701
• ### Who's Online (See full list)

There are no registered users currently online

×