DirectX 9, C++... Let me set the scene:

  • I have a 16:9 image.
  • I have a 16:10 screen.
  • I want the 16:9 image to be drawn so that it is vertically centred within my 16:10 screen.
  • My 16:9 image is 1920 x 1080.
  • My screen is 1920 x 1200.


float topOffset = ( 1200 - 1080 / 2 )

But what if my screen was 1400 x 900

I have to resize the image and get its new height, then do the above again:

float newHeightForScaledImage = ( 1080 * 1400 ) / 1920

Okay so now I have a topOffset for both widescreen cases. I draw all of my images and interactive objects at their ( y position + the topOffset ).

New problem is that the menu is also needed to take into consideration, so I use that systemmetricssomething call which returns 20 which I then subtract from the topOffset... Okay my drawing is vertically centred... perfect!

Question is, regardless of my entire game now being vertically centred (in the most crazy long hauled way possibly known to man), I can still draw outside of the game area into the black zone that now exists.

I know I am approaching this wrong, but I am too new to this to know any better.

How do you guys vertically centre your games if they are a different ratio to the artwork you have created for the backgrounds etc?

enter image description here


2 Answers 2


We use letterboxing. This allows us to keep a consistent ratio; you can implement it similarly here. The sample is done in XNA but the general gist is pretty much the same. I'll outline the steps here, anyway for consistency sake since this link has already gone dead once.

  1. Create your backbuffer at the display adapter’s current resolution.
  2. When drawing, first set the viewport to the full backbuffer and clear black.
  3. Compute the largest viewport of the desired aspect ratio that fits on screen and set that to the device.
  4. Clear the screen again (it will only clear the viewport area) and draw your game.

All credit to Mr. Nick Gravelyn.

  • \$\begingroup\$ Really appreciate this... This may be of help, im knackered at the moment from work, will get on this and respond asap. \$\endgroup\$
    – Jimmyt1988
    Apr 20, 2013 at 0:00
  • \$\begingroup\$ I see, I'm actually using standard CreateDevice for directX, i'm not sure if I have the width and height of the back buffer.. or a viewport \$\endgroup\$
    – Jimmyt1988
    Apr 23, 2013 at 0:11
  • \$\begingroup\$ I assume you are talking about this: msdn.microsoft.com/en-us/library/windows/desktop/… I HAVENT USED THIS YET!!! :D \$\endgroup\$
    – Jimmyt1988
    Apr 23, 2013 at 0:16
  • \$\begingroup\$ Oh so I have the viewport.. and I see that clips it well. I still have to draw within the new coordinates? does that sound right? \$\endgroup\$
    – Jimmyt1988
    Apr 23, 2013 at 0:35
  • \$\begingroup\$ @JamesT That's correct; so make sure you keep track of what your "clipped" resolution is so you can draw accordingly. \$\endgroup\$ Apr 23, 2013 at 0:36

Make your render target 19x10 and draw everything based on that. Then you can copy it to the window surface while scaling it down to fit.

  • \$\begingroup\$ hm, okay im going to take a look at my code when I get back from work. \$\endgroup\$
    – Jimmyt1988
    Apr 19, 2013 at 16:13
  • \$\begingroup\$ My render target seems to be CreateDevice average function: hr = d3dObject->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &d3dDevice ); \$\endgroup\$
    – Jimmyt1988
    Apr 23, 2013 at 0:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .