zoukankan      html  css  js  c++  java
  • Directx11教程(21) 修正程序最小化异常bug

          很长时间竟然没有注意到,窗口最小化时候,程序会异常,今天调试水面程序时,随意间最小化了窗口,发现程序异常了。经过调试,原来程序最小化时候,屏幕的高度和宽度为0,此时创建深度缓冲会fail,所以在D3DClass.cpp的初始化函数中加入以下的代码,可以防止最小化时候程序异常。

    D3DClass.cpp增加代码:

    //Initialize函数包含完成D3D设置的所有代码。
    bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen,
        float screenDepth, float screenNear)

    {

    //如果屏幕高度或者宽度为0,则会创建深度缓冲失败,
    //当窗口最小化时候,会出现窗口为0的情况

    if(screenWidth < 1)
        screenWidth = 1;
    if(screenHeight <1)
        screenHeight = 1;

    // 初始化交换链描述
    ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

    // 用1个后缓冲
    swapChainDesc.BufferCount = 1;

    //帧缓冲的大小和应用程序窗口大小相等.
    swapChainDesc.BufferDesc.Width = screenWidth;
    swapChainDesc.BufferDesc.Height = screenHeight;

    // 后缓冲的surface的格式为DXGI_FORMAT_R8G8B8A8_UNORM.
    // surface的每个像素用4个无符号的8bit[映射到0-1]来表示。NORM表示归一化

    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

    // 如果使用垂直同步,设置后缓冲的刷新率。.
    //刷新率就是一秒钟把后缓冲内容在屏幕上画出的次数。
    //如果开启垂直同步,则锁定刷新率,则fps是固定的

    if(m_vsync_enabled)
        {
        swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
        swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
        }
    else
        {
        swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
        swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
        }

    }

  • 相关阅读:
    hdu 3018
    poj 1833 排列
    poj 1256 Anagram
    CF 548B Mike and Fun
    CF 548A
    【冰茶几专题】F
    【冰茶几专题】C
    535 C.Tavas and karafs
    [WA]cf 534 D. Handshakes
    cf 534C. Polycarpus' Dice
  • 原文地址:https://www.cnblogs.com/mikewolf2002/p/2418551.html
Copyright © 2011-2022 走看看