{"id":426,"date":"2010-10-31T19:04:31","date_gmt":"2010-10-31T18:04:31","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=426"},"modified":"2010-10-31T19:04:31","modified_gmt":"2010-10-31T18:04:31","slug":"experience-converting-xna-game-studio","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2010\/10\/experience-converting-xna-game-studio\/","title":{"rendered":"My Experience Converting from XNA Game Studio 3.1 to 4.0"},"content":{"rendered":"<p>Microsoft released a big update to XNA Game Studio with version 4.0. The main improvement is Windows Phone 7 support. I will probably not develop for WP7 (see reasons below) but I still need to upgrade my current Xbox 360 project from XNA 3.1 to 4.0.<\/p>\n<p>The process was not as smooth as I though it would be, so I wrote this article to help people transitionning from 3.1 to 4.0.<\/p>\n<h3><strong>Upgrading to XNA 4.0<\/strong><\/h3>\n<p>To install Game Studio 4.0, you normally need Windows Vista or Windows 7. However, Microsoft made a version for Windows XP working only for Windows and X360 projects. I don&#8217;t want to buy a new OS, therefore I am going with this &#8220;light&#8221; version. However, this version does not support Windows Phone 7. That&#8217;s a shame as I&#8217;d be interested to try things with a touch screen but upgrading to Windows 7 is expensive.<br \/>\nTo install GS 4.0, you need Visual C# 2010 Express, and to get Visual C# 2010 Express on XP, you need the Service Pack 3. <span style=\"text-decoration: underline;\">Problem<\/span>:\u00a0SP3 install failed for some strange reason. I could find this article on Microsoft&#8217;s site: <a href=\"http:\/\/support.microsoft.com\/kb\/949377\/\">When you try to install Windows XP Service Pack, you receive the error message &#8220;Access is denied&#8221;<\/a> and the third solution consisting in running command line utilities solved my problem. I was not really sure what I was doing, but it finally worked \ud83d\ude42<\/p>\n<h3>Converting the Project<\/h3>\n<p>When opening a GS3.1 project with Visual C# 2010, it automatically tries to convert it to GS4.0. Each project of the solution is converted. Of course, if you are using a compiled library (dll), you need to get or compile a 4.0 version. I had to re-compile <a href=\"http:\/\/box2dxna.codeplex.com\/\">Box2D.XNA<\/a> and download the latest version of <a href=\"http:\/\/tiledlib.codeplex.com\/\">TiledLib<\/a>&#8216;s dlls.<\/p>\n<p>However, I had a problem when compiling for the first time, with the following error: <em>&#8220;The referenced assembly &#8220;Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553&#8221; could not be resolved because it has a dependency on &#8220;Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#8221; which is not in the currently targeted framework &#8220;.NETFramework,Version=v4.0,Profile=Client&#8221;. Please remove references to assemblies not in the targeted framework or consider retargeting your project.&#8221;<\/em><br \/>\nLuckily, one guy had the same problem on <a href=\"http:\/\/forums.create.msdn.com\/forums\/t\/60833.aspx\">Creators Club forums<\/a> and the solution given by <a href=\"http:\/\/badcorporatelogo.wordpress.com\/\">Stephen Styrchak<\/a> solved my problem. It should be solved by changing the Target Framework in the application properties, but the option is greyed out. I had to edit my csproj manually with a text editor.<\/p>\n<h3>API changes<\/h3>\n<p>Ok, this is where the conversion really starts: fixing compiling errors due to numerous API changes in the framework. Here is a list of the main changes that affected my project:<\/p>\n<p><span style=\"text-decoration: underline;\">Color struct<\/span>: The Color struct has moved to XNA.Framework (from Xna.Framework.Graphics). A few constructors have also been removed, such as this one: <em>Color( Color, float)<\/em>. I used it a lot. Easy to fix but Color is widely used in my project so that involved many changes.<\/p>\n<p><span style=\"text-decoration: underline;\">Vertex buffers and Effects<\/span>: There has been a few changes with vertex buffers and effects. There are many portions of code to update because of that but the new API is really simpler and better. For instance, you do not have to do <em>Begin\/End<\/em> on effects and each pass, but you just use <em>Pass.Apply<\/em>: Less code to write for the same result. Also, when you have standard vertex types, you do not need to use <em>VertexDeclaration<\/em>s. The <em>GraphicsDevice.VertexDeclaration<\/em> member has been removed. Again, less code to write!<\/p>\n<p><span style=\"text-decoration: underline;\">Pixel\/Vertex Shader compiler<\/span> : I found the compiler more strict. For instance, I had a texture and a technique with the same name, it did compile with GS 3.1, but not with GS 4.0. I also had a pixel shader function called <em>PixelShader <\/em>and it does not compile on GS 4.0.<\/p>\n<p><span style=\"text-decoration: underline;\">Point Sprites<\/span>: They simply have been removed. I don&#8217;t use them in my current project, but my last game <a href=\"http:\/\/marketplace.xbox.com\/fr-FR\/Product\/Spring-Up-Harmony\/66acd000-77fe-1000-9115-d802585505d3\">Spring Up Harmony<\/a> used point sprites for the back ground effect. It takes some time to update to triangles.<\/p>\n<p><span style=\"text-decoration: underline;\">Render Targets<\/span>: In addition to a few simple API changes when setting render targets, the most notable change is the removal of the <em>ResolveTexture2D <\/em>class. You now need to use a <em>RenderTarget2D<\/em> and can&#8217;t directly get a texture from the backbuffer.<\/p>\n<p><span style=\"text-decoration: underline;\">Storage changes<\/span>: A few API changes have been made in the storage too. Biggest change is the OpenContainer method that is now asynchronous (<em>Begin\/EndOpenContainer<\/em>). A few functions have been renamed too.<\/p>\n<h3>Executing of the Game<\/h3>\n<p>Ok, now that the game compiles, let&#8217;s run it! And another <span style=\"text-decoration: underline;\">problem <\/span>occured here: The game does not run at all and asks for a DX 10 graphics card. Easy to fix: modify the XNA project properties and choose &#8220;Reach&#8221; instead of &#8220;HiDef&#8221;. Difference is that Reach has a limited API for WP7 but should be enough for me.<\/p>\n<h3><strong>References<\/strong><\/h3>\n<p>Here is a list of resources\/blogs that I found very useful while converting my game to GS 4.0. You should read them all \ud83d\ude09<\/p>\n<p><span style=\"text-decoration: underline;\">MSDN Page<\/span>: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb417503.aspx\">What&#8217;s new in XNA Game Studio 4.0<\/a><\/p>\n<p><span style=\"text-decoration: underline;\">Shawn Hargreaves&#8217; blog<\/span>: articles on\u00a0<a href=\"http:\/\/blogs.msdn.com\/b\/shawnhar\/archive\/2010\/04\/19\/vertex-data-in-xna-game-studio-4-0.aspx\">Vertex Buffers<\/a>,\u00a0<a href=\"http:\/\/blogs.msdn.com\/b\/shawnhar\/archive\/2010\/04\/22\/effect-api-changes-in-xna-game-studio-4-0.aspx\">Effects<\/a>, <a href=\"http:\/\/blogs.msdn.com\/b\/shawnhar\/archive\/2010\/03\/22\/point-sprites-in-xna-game-studio-4-0.aspx\">removal of point sprites<\/a>, <a href=\"http:\/\/blogs.msdn.com\/b\/shawnhar\/archive\/2010\/03\/26\/rendertarget-changes-in-xna-game-studio-4-0.aspx?PageIndex=2\">render targets<\/a>.<\/p>\n<p><span style=\"text-decoration: underline;\">Nick Gravelyn&#8217;s blog<\/span>: article on <a href=\"http:\/\/blogs.msdn.com\/b\/nicgrave\/archive\/2010\/07\/23\/storage-in-xna-game-studio-4-0.aspx\">storage in GS4.0<\/a><\/p>\n<h3>Done<\/h3>\n<p>And voil\u00e0! Conversion is done and the game runs properly (I did not test thoroughly yet). I was worried the new default use of premultiplied alpha would cause problem but I haven&#8217;t found any. If you had a problem converting your project that is not mentioned here, feel free to comment!<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F10%2Fexperience-converting-xna-game-studio%2F&amp;linkname=My%20Experience%20Converting%20from%20XNA%20Game%20Studio%203.1%20to%204.0\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F10%2Fexperience-converting-xna-game-studio%2F&amp;linkname=My%20Experience%20Converting%20from%20XNA%20Game%20Studio%203.1%20to%204.0\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F10%2Fexperience-converting-xna-game-studio%2F&amp;linkname=My%20Experience%20Converting%20from%20XNA%20Game%20Studio%203.1%20to%204.0\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2010%2F10%2Fexperience-converting-xna-game-studio%2F&amp;linkname=My%20Experience%20Converting%20from%20XNA%20Game%20Studio%203.1%20to%204.0\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Microsoft released a big update to XNA Game Studio with version 4.0. The main improvement is Windows Phone 7 support. I will probably not develop for WP7 (see reasons below) but I still need to upgrade my current Xbox 360 project from XNA 3.1 to 4.0. The process was not as smooth as I though&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2010\/10\/experience-converting-xna-game-studio\/\">Continue reading <span class=\"screen-reader-text\">My Experience Converting from XNA Game Studio 3.1 to 4.0<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,12,21],"tags":[22,23,69,83,141],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/426"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=426"}],"version-history":[{"count":0,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/426\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}