Advertisement Jump to content


This topic is now archived and is closed to further replies.


window scaling hassle

This topic is 6181 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

i have this annoying problem i need help with. if i make a window for direct x that is num x num in dimensions (width and height are the same) i can draw a 1.0f x 1.0f square and it will actually look like a square. if the window dimensions are different (if i initiate them differently or resize a 600x600 window), the polygon looks like a rectangle because it got streched in only one dimension. maybe i''m not using the aspect ratio corretly... but how do i make it so that when i resize a window, the contents inside are scaled properly in all 3 dimensions? this is my matrix code... the program window size is 640 x 480 D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); i believe the 3rd parameter is the aspect ratio correct? i tried changing it to (float)640/480 and (float)480/640 and any other weird numbers but nothing on the window changes.

Share this post

Link to post
Share on other sites
The aspect ratio is the ratio between the width and height of the display. A 1:1 (the 1.0) means that the width and height are identical. If you are using a 640x480 resolution, then use a ratio of 1.333333 (which is 640/480). I use the following settings that always work for me:

D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.333333f, 1.0f, 10000.0f);

Jim Adams

Share this post

Link to post
Share on other sites
For any window use this code:

RECT rc;
GetClientRect(hwndRender, &rc);
D3DXMatrixPerspectiveFovLH(..., float(rc.right)/rc.bottom, ...);

Note that you need float cast so that you don''t do integer division.

You might want to put this code also in your WM_SIZE handler. Since there is no way to change back-buffer size on the fly, when your window is resized you need to destroy d3d device and recreate it.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!