{"id":1593,"date":"2013-04-11T16:30:00","date_gmt":"2013-04-11T16:30:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2013\/04\/11\/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3\/"},"modified":"2021-09-29T15:24:43","modified_gmt":"2021-09-29T15:24:43","slug":"developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3\/","title":{"rendered":"Developing an app with the Visual Studio 3D Starter Kit, part 3 of 3"},"content":{"rendered":"<p>Welcome back to our third and final post on using the <a href=\"https:\/\/aka.ms\/vs3dkit\">Visual Studio 3D Starter Kit<\/a>! If you read our previous posts in this series (<a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/03\/26\/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3.aspx\">here<\/a> and <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/04\/02\/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3.aspx\">here<\/a>), you&rsquo;ve got an app that has an animated die, and you&rsquo;re ready to make the last few changes to get this app to run on Windows RT devices&nbsp;and Windows Phone 8.&nbsp;<\/p>\n<p>If you haven&rsquo;t read the previous posts, you may want to go through these posts and create an app &ndash; we&rsquo;ll be here once you&rsquo;re ready.<\/p>\n<p>If you&#8217;re more of a visual learner, you might prefer following Part 1 and 2 in our new <a href=\"https:\/\/channel9.msdn.com\/posts\/VS-3D-Starter-Kit-Dice-Roller\">Channel 9 video<\/a>! In less than 30 minutes you&#8217;ll go from&nbsp;zero to jumping dice!<\/p>\n<p><a href=\"https:\/\/channel9.msdn.com\/posts\/VS-3D-Starter-Kit-Dice-Roller\"><img decoding=\"async\" style=\"max-width: 512px\" src=\"http:\/\/media.ch9.ms\/ch9\/b3eb\/05e328a7-8b3d-4e91-9085-e1241e46b3eb\/DiceRollerrs_512.jpg\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<h2>Final steps for Windows RT<\/h2>\n<p>Since current Windows RT devices have a graphics card with <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ff476876.aspx\">D3D_FEATURE_LEVEL_9_1<\/a> and the Visual Studio Graphics tools generate shaders for graphics cards with D3D_FEATURE_LEVEL_10_0 and above, there&rsquo;s one small extra step that has to be done for this app to run on Windows RT: we need to generate a version of the shaders to be compiled for the correct feature level.<\/p>\n<p>To do that, open your mesh (Die.fbx) and click the cube. On the Properties tool window look for a property called Effect. Click the &ldquo;+&rdquo; button to the left of that property and select the (Advanced) value. Finally, click the &ldquo;&hellip;&rdquo; button to open the shader source for the Phong effect.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/6758.Part3_Fig1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/6758.Part3_Fig1.png\" alt=\"Image 6758 Part3 Fig1\" width=\"391\" height=\"366\" class=\"aligncenter size-full wp-image-28898\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/6758.Part3_Fig1.png 391w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/6758.Part3_Fig1-300x281.png 300w\" sizes=\"(max-width: 391px) 100vw, 391px\" \/><\/a><\/p>\n<p>What you see now is the default&nbsp;shader that Visual Studio applied to this mesh, displayed in the Visual Studio Shader Designer. The Shader Designer allows you to build complex visual effects without the need to learn a new programming language. To learn more about the Shader Designer, check the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/hh315733(v=VS.110).aspx\">documentation<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/jj161095.aspx\">walkthrough<\/a> on MSDN.<\/p>\n<p>What we want to do with this shader is export it to HLSL in order to be able to re-compile it for Direct3D Feature Level 9 graphics cards. The Starter Kit will automatically look for a fallback shader with the same name as the original in case the device does not support D3D Feature Level 10 or higher.<\/p>\n<p>To export this shader, go to the last icon in the toolbar (Advanced) -&gt; Export -&gt; Export as&hellip; (see figure below) and save it as &ldquo;<strong>Phong.hlsl<\/strong>&rdquo; in your Assets folder. Then, add the file to the project by right-clicking the Assets folder on Solution Explorer -&gt; Add -&gt; Existing item&hellip; and selecting the file we just exported.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0842.Part3_Fig2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0842.Part3_Fig2.png\" alt=\"Image 0842 Part3 Fig2\" width=\"968\" height=\"682\" class=\"aligncenter size-full wp-image-28897\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0842.Part3_Fig2.png 968w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0842.Part3_Fig2-300x211.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0842.Part3_Fig2-768x541.png 768w\" sizes=\"(max-width: 968px) 100vw, 968px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Finally, we need to tell the HLSL compiler that this file is a Pixel Shader. To do that, right-click &ldquo;Phong.hlsl&rdquo; on your Solution Explorer and choose Properties. On the Properties page, make sure the &ldquo;Configuration&rdquo; drop down is set to &ldquo;All Configurations&rdquo; and the &ldquo;Platform&rdquo; drop down is set to &ldquo;All Platforms&rdquo;, so that the changes we make are applied to all versions of our app.<\/p>\n<p>Then, on the &ldquo;HLSL Compiler&rdquo; page, change the Shader Type property to &ldquo;Pixel Shader (\/ps)&rdquo; and make sure to enable optimizations (set the Disable optimizations property to &#8220;No&#8221;), like the figure below:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/7181.Part3_Fig3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/7181.Part3_Fig3.png\" alt=\"Image 7181 Part3 Fig3\" width=\"852\" height=\"605\" class=\"aligncenter size-full wp-image-28899\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/7181.Part3_Fig3.png 852w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/7181.Part3_Fig3-300x213.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/7181.Part3_Fig3-768x545.png 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/a><\/p>\n<p>With this step, everything is ready for Windows RT. This app can now be deployed to your favorite device using the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/hh441469(v=vs.110).aspx\">Visual Studio Remote Debugging Tools<\/a>.<\/p>\n<p>Another change you should make before releasing the app for Windows RT is to make sure snap view and portrait mode work as expected. In this case, all we did was to make sure the camera stayed on the same orientation when we change the view, by deleting the following line on the CreateWindowSizeDependentResource()&nbsp;method on&nbsp;Game.cpp:<\/p>\n<pre style=\"background: white;color: black;font-family: Consolas\"><span style=\"color: blue\">void<\/span>&nbsp;<span style=\"color: #2b91af\">Game<\/span>::CreateWindowSizeDependentResources()\r\n{\r\n&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #2b91af\">GameBase<\/span>::CreateWindowSizeDependentResources();\r\n&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: green\">\/\/&nbsp;(snip) Initialize camera...<\/span>\r\n<\/pre>\n<pre style=\"background: white;color: black;font-family: Consolas\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: blue\">if<\/span>&nbsp;(aspectRatio&nbsp;&lt;&nbsp;1.0f)\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: green\">\/\/\/<\/span>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: green\">\/\/\/&nbsp;portrait&nbsp;or&nbsp;snap&nbsp;view<\/span>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: green\">\/\/\/<\/span>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"text-decoration: line-through;background-color: #ffc5e2\">m_graphics.GetCamera().SetUpVector(<span style=\"color: #2b91af;text-decoration: line-through\">XMFLOAT3<\/span>(1.0f,&nbsp;0.0f,&nbsp;0.0f)); <\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/pre>\n<pre style=\"background: white;color: black;font-family: Consolas\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fovAngleY&nbsp;=&nbsp;120.0f&nbsp;*&nbsp;XM_PI&nbsp;\/&nbsp;180.0f;\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n<\/pre>\n<pre style=\"background: white;color: black;font-family: Consolas\"><span style=\"color: green\"> \/\/&nbsp;(snip) Lights...<\/span><br \/>}\r\n<\/pre>\n<p>You can download the project at this state on <a href=\"http:\/\/diceroller3d.codeplex.com\/SourceControl\/changeset\/5ebb20f0b93447d14d615508b3d8df7f57d683d7\">CodePlex<\/a>&nbsp;(direct download link below).<\/p>\n<p><a href=\"http:\/\/download-codeplex.sec.s-msft.com\/Download\/SourceControlFileDownload.ashx?ProjectName=diceroller3d&amp;changeSetId=5ebb20f0b934\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1541.SupportForRT.png\" alt=\"Image 1541 SupportForRT\" width=\"150\" height=\"150\" class=\"size-full wp-image-28901\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1541.SupportForRT.png 150w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1541.SupportForRT-24x24.png 24w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1541.SupportForRT-48x48.png 48w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1541.SupportForRT-96x96.png 96w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<h2>Porting it to the Windows Phone<\/h2>\n<p>Using the <a href=\"https:\/\/aka.ms\/vs3dkit\">Starter Kit with support for Windows Phone<\/a>, porting this app to Windows Phone 8 is a breeze. All you have to do is get the Starter Kit, replace the Game.cpp and Game.h classes by the ones you created for this app, add all your assets (in this case, Die.fbx, DieTexture.png and Phong.hlsl), and change the XAML codebehind to call RollDie() when the screen is tapped. Let&rsquo;s go over this in a short step by step:<\/p>\n<ol>\n<li>Make sure you have the <a href=\"http:\/\/dev.windowsphone.com\/en-us\/downloadsdk\">Windows Phone 8 SDK<\/a> installed on your PC.<\/li>\n<li>Get the <a href=\"https:\/\/aka.ms\/vs3dkit\">Visual Studio 3D Starter Kit with support for Windows Phone<\/a> and open it in Visual Studio.<\/li>\n<li>In the StarterKitPhoneComponent project, delete the Shared\/Animation folder and delete all the assets from the Shared\/Assets folder.<\/li>\n<li>Replace the Game.cpp and Game.h files by the ones you created in this tutorial.<\/li>\n<li>Add all the assets used in your game to the Shared\/Assets folder in the StarterKitPhoneComponent project: Die.fbx, DieTexture.png and Phong.hlsl.<\/li>\n<li>For Phong.hlsl, on the Properties page, make sure the &ldquo;Configuration&rdquo; drop down is set to &ldquo;All configurations&rdquo; and the &ldquo;Platform&rdquo; drop down is set to &ldquo;All Platforms&rdquo;. Then, on the &ldquo;HLSL Compiler&rdquo; page, change the Shader Type property to &ldquo;Pixel Shader (\/ps)&rdquo; and set the Disable optimizations property to &rdquo;No&rdquo;.<\/li>\n<li>In Direct3DBackground.cpp\/.h, remove the unused methods: ToggleHitEffect() and ChangeMaterialColor()<\/li>\n<li>In Direct3DBackground.cpp, add the following to the OnPointerReleased() method:\n<pre style=\"background: white;color: black;font-family: Consolas\"><span style=\"color: blue\">void<\/span>&nbsp;Direct3DBackground::OnPointerReleased(DrawingSurfaceManipulationHost^&nbsp;sender,&nbsp;PointerEventArgs^&nbsp;args)\r\n{\r\n\t<span style=\"background-color: #00ffff\">m_renderer-&gt;RollDie();<\/span>\r\n}<\/pre>\n<\/li>\n<li>On MainPage.xaml, remove all XAML related to the counters and app bar.<\/li>\n<li>On MainPage.xaml.cs, remove all unused fields and methods.<\/li>\n<\/ol>\n<p>Done! You can now run this app on the Windows Phone emulator or on your Windows Phone 8 device. You may want to tweak the camera position and field of view to get a bigger die on your phone screen.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0361.DiceRollerPhone.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0361.DiceRollerPhone.png\" alt=\"Image 0361 DiceRollerPhone\" width=\"365\" height=\"659\" class=\"aligncenter size-full wp-image-28896\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0361.DiceRollerPhone.png 365w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/0361.DiceRollerPhone-166x300.png 166w\" sizes=\"(max-width: 365px) 100vw, 365px\" \/><\/a><\/p>\n<p>You can download the final project on <a href=\"http:\/\/diceroller3d.codeplex.com\/SourceControl\/changeset\/78429aedf85e34b4e3a9b41c47ce219ceed9da91\">CodePlex<\/a> (direct download link below).<\/p>\n<p><a href=\"http:\/\/download-codeplex.sec.s-msft.com\/Download\/SourceControlFileDownload.ashx?ProjectName=diceroller3d&amp;changeSetId=78429aedf85e\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/04\/1854.FinalProject.png\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<h2>For the future<\/h2>\n<p>This app is now complete, but there&rsquo;s still a lot that can be done to make it shine on the Windows Store. Here are some initial ideas:<\/p>\n<ul>\n<li>Change the logo, tile icons and splash screen to match the app theme<\/li>\n<li>Create a cool background, and possibly a &ldquo;table&rdquo; where the die is resting<\/li>\n<li>Add shadows, reflections and other realistic visual effects<\/li>\n<li>Make the die customizable, translucent, or add rounded edges<\/li>\n<li>Make the app work with more than one die, or with dice with a different number of sides<\/li>\n<li>Add realistic physics elements, such as bouncing, force-based spinning, and collision detection<\/li>\n<li>Save the dice state when the app is suspended and restore afterwards<\/li>\n<li>Save the history of previous dice rolls<\/li>\n<li>Add sensor support to allow the dice to be rolled by shaking the device<\/li>\n<li>Add sound when the dice are rolled<\/li>\n<li>Use the dice roller to implement a board game or a casino simulator&hellip;<\/li>\n<\/ul>\n<h2>Wrapping up<\/h2>\n<p>In this blog series you saw how to create a 3D app for Windows 8, Windows RT and Windows Phone with the Visual Studio 3D Starter Kit, sharing all the app logic and assets between all platforms. You also learned a little bit about the Visual Studio Graphics tools, and discovered that creating a 3D app is not a mysterious task &ndash; you can start without a deep knowledge of 3D modeling, complex math and HLSL, and learn new concepts at your own pace.<\/p>\n<p>We&rsquo;d love to hear feedback about this walkthrough, the Visual Studio 3D Starter Kit, or what you&rsquo;d like to see in the future from Visual Studio for graphics development.&nbsp; Leave us a note in the comments!<\/p>\n<p><em>Very special thanks to Jennifer Leaf for co-authoring the articles and beta-testing the code. Special thanks to Golnaz Alibeigi for all the help with the video, and Bruno Sonnino and Eric Battalio for reviewing the blog posts.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome back to our third and final post on using the Visual Studio 3D Starter Kit! If you read our previous posts in this series (here and here), you&rsquo;ve got an app that has an animated die, and you&rsquo;re ready to make the last few changes to get this app to run on Windows RT [&hellip;]<\/p>\n","protected":false},"author":278,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[168,140,87,88,110,132,160],"class_list":["post-1593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-3d-starter-kit","tag-c","tag-direct3d","tag-directx","tag-games","tag-windows-8","tag-windows-store-apps"],"acf":[],"blog_post_summary":"<p>Welcome back to our third and final post on using the Visual Studio 3D Starter Kit! If you read our previous posts in this series (here and here), you&rsquo;ve got an app that has an animated die, and you&rsquo;re ready to make the last few changes to get this app to run on Windows RT [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/278"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=1593"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1593\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=1593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=1593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=1593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}