{"id":52,"date":"2014-11-29T16:13:10","date_gmt":"2014-11-29T14:13:10","guid":{"rendered":"http:\/\/heikkili.kapsi.fi\/blog\/?p=52"},"modified":"2024-09-15T14:15:06","modified_gmt":"2024-09-15T12:15:06","slug":"cg-study-1","status":"publish","type":"post","link":"http:\/\/heikkili.kapsi.fi\/blog\/?p=52","title":{"rendered":"CG study #1"},"content":{"rendered":"<p>Basic Idea of these posts is to keep track of my study of Directx 11 from a book 3D Game Programming with DirectX 11 by Frank Luna that I finished reading a while ago. l have also started to build a simple 3d game demo to learn more about game and graphics programming.<\/p>\n<p>Every chapter of the book have exercises at the end of each chapter. I decided to try to finish as much of them as I can same time building my demo project. First I made a plan to finish exercises from 3 or 4 chapters a week but after finishing first 4 I realized its too much if I also want to actually have time to make a game demo. I decided to finish at least one chapter a week and add something to demo every week. Most of the exercises also ask to implement different effects that I can use in my demo.<\/p>\n<p>First three chapters discussed with vectors, matrices, and transformations etc.I used pen and pare to solve the exercises of those chapters.<\/p>\n<p>Chapter 4 was about basic initialization of directx. Exercises asked things like enumerate display adapters and disable alt+enter to switch to full screen, modify the view port etc.<\/p>\n<p>I do not know yet if I should post code solutions for the exercises or only screenshots but here is both for the chapter 4.<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\t\/\/ ch.4 ex. 1 disable fullscreen\n\tHR(dxgiFactory-&amp;amp;gt;MakeWindowAssociation(mhMainWnd, DXGI_MWA_NO_ALT_ENTER));\n\n\t\/\/ ch.4 ex. 2 number of adapters\n\tUINT numAdapters = 0;\n\twhile (dxgiFactory-&amp;amp;gt;EnumAdapters(numAdapters, &amp;amp;amp;dxgiAdapter) != DXGI_ERROR_NOT_FOUND)\n\t{\n\t\tnumAdapters++;\n\t}\n\n\twchar_t msgbuf&#x5B;256];\n\tswprintf(msgbuf, 256, L&amp;amp;quot;***NUM ADAPTERS %d\\n&amp;amp;quot;, numAdapters);\n\tOutputDebugString(msgbuf);\n\n\t\/\/ ch.4 ex. 3 check directx support, note this can not be used for dx11.\n\tfor (UINT i = 0; i &amp;amp;lt; numAdapters; i++)\n\t{\n\t\t\/\/ Note  You can use CheckInterfaceSupport only to check whether a Direct3D 10.x interface is supported,\n\t\t\/\/ and only on Windows Vista SP1 and later versions of the operating system.\n\t\t\/\/ http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb174524%28v=vs.85%29.aspx\n\t\tHR(dxgiFactory-&amp;amp;gt;EnumAdapters(i, &amp;amp;amp;dxgiAdapter));\n\t\tif (dxgiAdapter-&amp;amp;gt;CheckInterfaceSupport(__uuidof(ID3D10Device), NULL) != DXGI_ERROR_UNSUPPORTED)\n\t\t{\n\t\t\tswprintf(msgbuf, 256, L&amp;amp;quot;***D3D11 SUPPORTED FOR ADAPTER %d\\n&amp;amp;quot;, i);\n\t\t\tOutputDebugString(msgbuf);\n\t\t}\n\n\t}\n\n\t\/\/ ch.4 ex. 4 check numper of outputs for default adapter.\n\tUINT numOutputs = 0;\n\tHR(dxgiFactory-&amp;amp;gt;EnumAdapters(0, &amp;amp;amp;dxgiAdapter));\n\tIDXGIOutput* dxgiOutput = 0;\n\twhile (dxgiAdapter-&amp;amp;gt;EnumOutputs(numOutputs, &amp;amp;amp;dxgiOutput) != DXGI_ERROR_NOT_FOUND)\n\t{\n\t\tnumOutputs++;\n\t}\n\n\tswprintf(msgbuf, 256, L&amp;amp;quot;***NUM OUTPUTS FOR DEFAULT ADAPTER = %d\\n&amp;amp;quot;, numOutputs);\n\tOutputDebugString(msgbuf);\n\n\t\/\/ ch.4 ex. 5 list of display modes for outputs\n\tfor (int i = 0; i &amp;amp;lt; numOutputs; i++)\n\t{\n                swprintf(msgbuf, 256, L&amp;amp;quot;***DISPLAY MODES FOR OUTPUT = %d\\n&amp;amp;quot;, i);\n\t\tOutputDebugString(msgbuf);\n\t\tHR(dxgiAdapter-&amp;amp;gt;EnumOutputs(i, &amp;amp;amp;dxgiOutput));\n\n\t\t\/\/ get numModes\n\t\tUINT numModes = 0;\n\t\tdxgiOutput-&amp;amp;gt;GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &amp;amp;amp;numModes, NULL);\n\n\t\tDXGI_MODE_DESC* pDesc = 0;\n\t\tpDesc = new DXGI_MODE_DESC&#x5B;numModes];\n\t\tHR(dxgiOutput-&amp;amp;gt;GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &amp;amp;amp;numModes, pDesc));\n\n\t\tfor (int j = 0; j &amp;amp;lt; numModes; j++)\n\t\t{\n\n\t\t\tUINT w = pDesc-&amp;amp;gt;Width;\n\t\t\tUINT h = pDesc-&amp;amp;gt;Height;\n\t\t\tDXGI_RATIONAL rr = pDesc-&amp;amp;gt;RefreshRate;\n\n\t\t\tpDesc++;\n\n\t\t\tswprintf(msgbuf, 256, L&amp;amp;quot;***WIDTH = %d HEIGHT = %d REFRESH = %d\\\\%d\\n&amp;amp;quot;, w, h, rr.Numerator, rr.Denominator );\n\t\t\tOutputDebugString(msgbuf);\n\n\t\t}\n\t}\n<\/pre>\n<p>Modifying the viewport<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/\/ ch.4 ex. 6\nZeroMemory(&amp;amp;amp;amp;mScreenViewport, sizeof(D3D11_VIEWPORT));\nmScreenViewport.TopLeftX = 100.0f;\nmScreenViewport.TopLeftY = 100.0f;\nmScreenViewport.Width = static_cast&amp;amp;lt;float&amp;amp;gt;(mClientWidth) - 200.0f;\nmScreenViewport.Height = static_cast&amp;amp;lt;float&amp;amp;gt;(mClientHeight)- 200.0f;\nmScreenViewport.MinDepth = 0.0f;\nmScreenViewport.MaxDepth = 1.0f;\n\nmd3dImmediateContext-&amp;amp;gt;RSSetViewports(1, &amp;amp;amp;amp;mScreenViewport);\n<\/pre>\n<p>Here is a image for modified view port \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"67\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=67\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?fit=816%2C639\" data-orig-size=\"816,639\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ch4ex6\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?fit=300%2C234\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignnone size-medium wp-image-67\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?resize=300%2C234\" alt=\"ch4ex6\" width=\"300\" height=\"234\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?resize=300%2C234 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?resize=383%2C300 383w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/11\/ch4ex6.png?w=816 816w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I will post more of my game demo I started to build after I get something on screen and some basic architecture ready.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic Idea of these posts is to keep track of my study of Directx 11 from a book 3D Game Programming with DirectX 11 by Frank Luna that I finished reading a while ago. l have also started to build a simple 3d game demo to learn more about game and graphics programming. Every chapter&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[4,2],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-computer-graphics","tag-c","tag-directx11"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7k3DT-Q","_links":{"self":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/52"}],"collection":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":22,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":635,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions\/635"}],"wp:attachment":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}