user2790762
user2790762

Reputation:

Direct3D Window->Bounds.Width/Height differs from real resolution

I noticed a strange behaviour with Direct3D while doing this tutorial.

The dimensions I am getting from the Window Object differ from the configured resolution of windows. There I set 1920*1080, the width and height from the Winows Object is 1371*771.

CoreWindow^ Window = CoreWindow::GetForCurrentThread();
// set the viewport
D3D11_VIEWPORT viewport = { 0 };

viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = Window->Bounds.Width; //should be 1920, actually is 1371
viewport.Height = Window->Bounds.Height;  //should be 1080, actually is 771

I am developing on an Alienware 14, maybe this causes this problem, but I could not find any answers, yet.

Upvotes: 1

Views: 201

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41057

CoreWindow sizes, pointer locations, etc. are not expressed in pixels. They are expressed in Device Independent Pixels (DIPS). To convert to/from pixels you need to use the Dots Per Inch (DPI) value.

inline int ConvertDipsToPixels(float dips) const
{
    return int(dips * m_DPI / 96.f + 0.5f);
}

inline float ConvertPixelsToDips(int pixels) const
{
    return (float(pixels) * 96.f / m_DPI);
}

m_DPI comes from DisplayInformation::GetForCurrentView()->LogicalDpi and you get the DpiChanged event when and if it changes.

See DPI and Device-Independent Pixels for more details.

You should take a look at the Direct3D UWP Game templates on GitHub, and check out how this is handled in Main.cpp.

Upvotes: 1

Related Questions