{"id":4264,"date":"2015-11-30T17:23:50","date_gmt":"2015-11-30T17:23:50","guid":{"rendered":"http:\/\/anthroponaute.fr\/blog-informatique\/?p=4264"},"modified":"2015-12-16T08:53:37","modified_gmt":"2015-12-16T08:53:37","slug":"introduction-a-directx-10-redimensionner-la-fenetre-de-rendu-partie-6","status":"publish","type":"post","link":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/?p=4264","title":{"rendered":"Introduction \u00e0 DirectX 10 \u2013 Redimensionner la fen\u00eatre de rendu \u2013 partie 6"},"content":{"rendered":"<p><a href=\"https:\/\/anthropoya.cluster014.ovh.net\/blog-informatique\/wp-content\/uploads\/2015\/03\/directx9c.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1053\" src=\"https:\/\/anthropoya.cluster014.ovh.net\/blog-informatique\/wp-content\/uploads\/2015\/03\/directx9c.png\" alt=\"directx9c\" width=\"346\" height=\"360\" srcset=\"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/wp-content\/uploads\/2015\/03\/directx9c.png 346w, https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/wp-content\/uploads\/2015\/03\/directx9c-288x300.png 288w\" sizes=\"(max-width: 346px) 100vw, 346px\" \/><\/a><\/p>\n<p><strong>Intro :<\/strong><\/p>\n<p>Dans une application DirectX, l&rsquo;utilisateur peut vouloir redimensionner la fen\u00eatre \u00e0 sa guise ou passer le jeu en mettre en mode plein \u00e9cran.<\/p>\n<p>Il faut impl\u00e9menter et coder cette fonctionnalit\u00e9.<\/p>\n<p><strong>Pr\u00e9requis :<\/strong><\/p>\n<p>&#8211; Avoir suivi la cinqui\u00e8me partie de ce tutoriel.<\/p>\n<h2><strong>Sixi\u00e8me partie :<\/strong><\/h2>\n<p>Redimensionnement et plein \u00e9cran de la fen\u00eatre de rendu.<\/p>\n<p><strong>Explications :<\/strong><\/p>\n<p>Avant tout, juste pour \u00e9noncer un petit point\u00a0 mis \u00e0 part :<\/p>\n<p>L&rsquo;appel \u00e0<em> D3D11DeviceContext::ClearState<\/em> r\u00e9initialise par d\u00e9faut toutes les configurations du contexte d&rsquo;affichage (remet \u00e0 z\u00e9ro les shaders, les inputs layout, les viewports, etc..)<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p>Avec les interfaces <strong>DXGI*<\/strong> on peut obtenir les informations sur la carte graphique :<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\nbool D3D10Renderer::GetGPUInfo()\r\n{\r\n\u00a0\u00a0 \u00a0HRESULT hr = S_OK;\r\n\r\n\u00a0\u00a0 \u00a0uint32 iNumModes;\r\n\r\n\u00a0\u00a0 \u00a0IDXGIFactory* pDXGIFactory = nullptr;\r\n\u00a0\u00a0 \u00a0IDXGIAdapter* pDXGIAdapter = nullptr;\r\n\u00a0\u00a0 \u00a0IDXGIOutput* pDXGIAdapterOutput = nullptr;\r\n\r\n\u00a0\u00a0 \u00a0DXGI_MODE_DESC* pDisplayModeList = nullptr;\r\n\r\n\u00a0\u00a0 \u00a0DXGI_ADAPTER_DESC adapterDesc;\r\n\r\n\u00a0\u00a0 \u00a0\/\/ Cr\u00e9\u00e9e une interface m\u00e9tier &quot;factory&quot; DirectX\r\n\u00a0\u00a0 \u00a0hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&amp;pDXGIFactory);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/\/ Utilise la &quot;factory&quot;\r\n\u00a0\u00a0 \u00a0hr = pDXGIFactory-&gt;EnumAdapters(0, &amp;pDXGIAdapter);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/\/ Enum\u00e8re l'adpatateur principal de l'\u00e9cran\r\n\u00a0\u00a0 \u00a0hr = pDXGIAdapter-&gt;EnumOutputs(0, &amp;pDXGIAdapterOutput);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/\/ Obtient le nombre de modes d'affichage qui corresppond \u00e0 DXGI_FORMAT_R8G8B8A8_UNORM \u00a0\r\n\u00a0\u00a0 \u00a0hr = pDXGIAdapterOutput-&gt;GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &amp;iNumModes, nullptr);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/* Cr\u00e9\u00e9 une liste qui d\u00e9tient tous les modes d'affichage possibles pour cette carte graphique et\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 le format d'affichage *\/\r\n\u00a0\u00a0 \u00a0pDisplayModeList = new DXGI_MODE_DESC[iNumModes];\r\n\r\n\u00a0\u00a0 \u00a0if (!pDisplayModeList)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return false;\r\n\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0\/\/ Remplie la pr\u00e9c\u00e9dente structure\r\n\u00a0\u00a0 \u00a0hr = pDXGIAdapterOutput-&gt;GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &amp;iNumModes, pDisplayModeList);\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/* On parcourt tous les modes d'affichages possibles\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 et on trouve celui qui correspond \u00e0 la taille sp\u00e9cifi\u00e9e\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 en param\u00e8tre ; puis on enregistre le num\u00e9rateur et le d\u00e9nominateur\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 du taux de rafraichissement de l'\u00e9cran\r\n\u00a0\u00a0 \u00a0*\/\r\n\u00a0\u00a0 \u00a0for (uint32 i = 0; i &lt; iNumModes; i++)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (pDisplayModeList[i].Width == (uint32)m_iWidth)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (pDisplayModeList[i].Height == (uint32)m_iHeight)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_iNumerator = pDisplayModeList[i].RefreshRate.Numerator;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_iDenominator = pDisplayModeList[i].RefreshRate.Denominator;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0DXGI_MODE_DESC desc = pDisplayModeList[i];\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ On v\u00e9rifie que ce mode n'a pas d\u00e9j\u00e0 \u00e9t\u00e9 ajout\u00e9\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0bool bAlreadyExist = false;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (uint32 i = 0; i &lt; m_modes.size(); i++)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (m_modes[i].Width == desc.Width &amp;&amp;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_modes[i].Height == desc.Height)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0bAlreadyExist = true;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0break;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (!bAlreadyExist)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_modes.push_back(desc);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0hr = pDXGIAdapter-&gt;GetDesc(&amp;adapterDesc);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0\/\/ On enregistre la taille de la m\u00e9moire vid\u00e9o en m\u00e9gabytes\r\n\u00a0\u00a0 \u00a0m_iVideoCardMemory = (adapterDesc.DedicatedVideoMemory \/ 1024 \/ 1024);\r\n\r\n\u00a0\u00a0 \u00a0size_t iStringLength = 0;\r\n\u00a0\u00a0 \u00a0\/\/ Convertie le nom la carte vid\u00e9o dans une cha\u00eene de caract\u00e8res\r\n\u00a0\u00a0 \u00a0int iError = wcstombs_s(&amp;iStringLength, m_sVideoCardDescription, 128, adapterDesc.Description, 128);\r\n\r\n\u00a0\u00a0 \u00a0if (iError != 0)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0return false;\r\n\u00a0\u00a0 \u00a0}\r\n\r\n    \/\/ On supprime les objets dont a plus besoin !\r\n\u00a0\u00a0 \u00a0SAFE_DELETE_ARRAY(pDisplayModeList);\r\n\r\n\u00a0\u00a0 \u00a0SAFE_RELEASE(pDXGIAdapterOutput);\r\n\u00a0\u00a0 \u00a0SAFE_RELEASE(pDXGIAdapter);\r\n\u00a0\u00a0 \u00a0SAFE_RELEASE(pDXGIFactory);\r\n\r\n\u00a0\u00a0 \u00a0return true;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Voici le programme de cet article une fois compil\u00e9 et lanc\u00e9 :<\/p>\n<p><strong><a href=\"https:\/\/anthropoya.cluster014.ovh.net\/blog-informatique\/wp-content\/uploads\/2015\/11\/fullscreen1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4464\" src=\"https:\/\/anthropoya.cluster014.ovh.net\/blog-informatique\/wp-content\/uploads\/2015\/11\/fullscreen1.png\" alt=\"fullscreen\" width=\"805\" height=\"759\" srcset=\"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/wp-content\/uploads\/2015\/11\/fullscreen1.png 805w, https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/wp-content\/uploads\/2015\/11\/fullscreen1-300x283.png 300w, https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/wp-content\/uploads\/2015\/11\/fullscreen1-624x588.png 624w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/a><br \/>\n<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>La fonction qui redimensionne les buffers :<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\nbool D3D10Renderer::ResizeSwapChain(const size_t iWidth, const size_t iHeight)\r\n{\r\n\u00a0\u00a0 \u00a0\/* On d\u00e9charge les pr\u00e9c\u00e9dents objets de rendu *\/\r\n\u00a0\u00a0 \u00a0SAFE_RELEASE(m_pRenderTargetView);\r\n\u00a0\u00a0 \u00a0SAFE_RELEASE(m_pDepthStencilView);\r\n\r\n\u00a0\u00a0 \u00a0HRESULT hr = S_OK;\r\n\u00a0\u00a0 \u00a0hr = m_pSwapChain-&gt;ResizeBuffers(2, iWidth, iHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0);\r\n\r\n\u00a0\u00a0 \u00a0HR_FAILED_RETURN_FALSE(hr);\r\n\r\n\u00a0\u00a0 \u00a0m_iWidth = iWidth;\r\n\u00a0\u00a0 \u00a0m_iHeight = iHeight;\r\n\r\n\u00a0\u00a0 \u00a0\/* Puis on les recr\u00e9er *\/\r\n\u00a0\u00a0 \u00a0CreateRenderTarget();\r\n\u00a0\u00a0 \u00a0CreateDepthStencilView();\r\n\r\n\u00a0\u00a0 \u00a0\/\/m_pCube-&gt;SetLens()\r\n\u00a0\u00a0 \u00a0SetViewport();\r\n\r\n\u00a0\u00a0 \u00a0return true;\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>La fonction qui g\u00e8re les entr\u00e9es clavier :<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid D3D10Renderer::OnKeyPressed(const KeyEvent&amp; arg)\r\n{\r\n\u00a0\u00a0 \u00a0if (arg.keyCode == VK_ESCAPE)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0SYSTEM-&gt;Quit();\r\n\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0else if (arg.keyCode == VK_F1)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_bFullscreen = !m_bFullscreen;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (m_bFullscreen)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0ResizeSwapChain(m_iWidth, m_iHeight);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0m_pSwapChain-&gt;SetFullscreenState(m_bFullscreen, nullptr);\r\n\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0else if (arg.keyCode == VK_F2)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0static uint32 iMode = 0;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ Largeur de la fen\u00eatre\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0uint32 iWidth = m_modes[iMode].Width;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ Hauteur de la fen\u00eatre\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0uint32 iHeight = m_modes[iMode].Height;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0ResizeSwapChain(iWidth, iHeight);\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0RECT rc;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0GetWindowRect(m_hWnd, &amp;rc);\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0SetWindowPos(m_hWnd, 0, rc.left, rc.top, iWidth, iHeight, SWP_SHOWWINDOW);\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0iMode++;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (iMode &gt;= m_modes.size())\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0iMode = 0;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0}\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>R\u00e9sum\u00e9 :<\/strong><\/p>\n<p>Depuis DirectX 10 il est plus facile et ais\u00e9 de changer de r\u00e9solution et de passer en mode plein \u00e9cran.<\/p>\n<p>Voici les fichiers source &#8211; <a href=\"https:\/\/anthropoya.cluster014.ovh.net\/blog-informatique\/data\/DirectX%2010%20Tutoriel%20-%20Partie%206.zip\">Partie 6 <\/a><\/p>\n<p><strong>R\u00e9f\u00e9rences :<\/strong><\/p>\n<p>&#8211; https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ff476389%28v=vs.85%29.aspx<\/p>\n<p>&#8211; https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb174577%28v=vs.85%29.aspx<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Intro : Dans une application DirectX, l&rsquo;utilisateur peut vouloir redimensionner la fen\u00eatre \u00e0 sa guise ou passer le jeu en mettre en mode plein \u00e9cran. Il faut impl\u00e9menter et coder cette fonctionnalit\u00e9. Pr\u00e9requis : &#8211; Avoir suivi la cinqui\u00e8me partie de ce tutoriel. Sixi\u00e8me partie : Redimensionnement et plein \u00e9cran de la fen\u00eatre de rendu. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/posts\/4264"}],"collection":[{"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4264"}],"version-history":[{"count":37,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/posts\/4264\/revisions"}],"predecessor-version":[{"id":4531,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=\/wp\/v2\/posts\/4264\/revisions\/4531"}],"wp:attachment":[{"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.la-porte-des-nebuleuses.net\/blog-informatique\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}