Direct3D Window-> Bounds.Width / Height与真实分辨率不同

时间:2016-01-28 19:18:15

标签: visual-c++ directx-11

我注意到在执行this tutorial时Direct3D出现了一种奇怪的行为。

我从Window对象获得的尺寸与配置的窗口分辨率不同。在那里我设置了1920 * 1080,Winows对象的宽度和高度是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

我正在使用Alienware 14开发,也许这会导致这个问题,但我找不到任何答案。

1 个答案:

答案 0 :(得分:0)

CoreWindow大小,指针位置等以像素表示。它们以设备无关像素(DIPS)表示。要转换为/从像素转换,您需要使用每英寸点数(DPI)值。

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来自DisplayInformation::GetForCurrentView()->LogicalDpi,当您发生更改时,您会收到DpiChanged事件。

有关详细信息,请参阅DPI and Device-Independent Pixels

您应该查看GitHub上的Direct3D UWP游戏模板,并查看Main.cpp中如何处理这些模板。