Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

Easy:

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

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Really appreciate this... This may be of help, im knackered at the moment from work, will get on this and respond asap. –  Jimmyt1988 Apr 20 '13 at 0:00
    
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 –  Jimmyt1988 Apr 23 '13 at 0:11
    
I assume you are talking about this: msdn.microsoft.com/en-us/library/windows/desktop/… I HAVENT USED THIS YET!!! :D –  Jimmyt1988 Apr 23 '13 at 0:16
    
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? –  Jimmyt1988 Apr 23 '13 at 0:35
    
@JamesT That's correct; so make sure you keep track of what your "clipped" resolution is so you can draw accordingly. –  Vaughan Hilts Apr 23 '13 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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.