[英]Alt+Enter in Win32 apps, manage resizing and resolution
我正在努力调整项目的大小和全屏模式。 这就是我在 Pixel Shader和 GIT 上处理Mandelbrot 的内容https://github.com/ShamanLKG/Mandelbrot
按下 Alt+Enter 时应用程序崩溃,我不明白为什么。
case WM_SIZE:
{
int width = LOWORD(lParam); // Macro to get the low-order word.
int height = HIWORD(lParam); // Macro to get the high-order word.
pThis->D3D->OnResize(width, height);
pThis->D3D = std::shared_ptr<Direct3D>(new Direct3D(hWnd, width, height));
pThis->D2D = std::shared_ptr<Direct2D>(new Direct2D(hWnd, pThis->D3D));
break;
}
我在调整大小时重新创建了 Direct3d 和 Direct2 对象,以解决导航问题并调整窗口的分辨率。 但到目前为止不可能让全屏工作。 全屏工作无需重新创建 D3D 和 D2D 对象,但后来我坚持使用原始分辨率,导航无法正常工作。 我使用 MSDN 中的 OnResize() 函数( https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#handling-window-resizing )。 我尝试将 BOOL 参数传递给 InitD3D 以告诉程序交换链是否是全屏的,来自 swapchain->GetFullScreenState 但它没有帮助。
只要不改变窗口大小,导航就可以工作,那么它就不精确了。 随着屏幕比例的变化调整 yDelta 会有所帮助,但仅当窗口宽度发生变化时。 当窗口高度改变时,它又变得不稳定。 因此,作为解决方法,我重新创建了 D3D 和 D2D 对象,以从新参数开始并具有功能导航。 但结果是全屏现在崩溃了。
void Direct3D::CenterScreen(int xPos, int yPos)
{
//float ratio = startRatio / currentRatio;
int xDelta = xPos - width / 2;
int yDelta = (yPos - height / 2); //could divide by ratio to capture window width change
realStart += (float)xDelta / (float)width * 2 * mandelWidth;
imagStart += (float)yDelta / (float)height * 2 * mandelHeight;
}
有什么线索可以解决这些问题吗? 提前谢谢了。
发现错误,未释放 Direct2D 资源导致 ResizeBuffers 失败,代码为 0x887A0001。 来自https://bell0bytes.eu/fullscreen/的教程非常有帮助。
hr = swapchain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);
今天的课程,有一个强大的错误处理系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.