{"id":13,"date":"2008-03-03T05:07:00","date_gmt":"2008-03-03T10:07:00","guid":{"rendered":"http:\/\/lukerymarz.com\/alearningexperience\/2008\/03\/xna-how-to-disable-bitmap-magnification-blending-blur.html"},"modified":"2008-03-03T05:07:00","modified_gmt":"2008-03-03T10:07:00","slug":"xna-how-to-disable-bitmap-magnification-blending-blur","status":"publish","type":"post","link":"http:\/\/lukerymarz.com\/alearningexperience\/2008\/03\/xna-how-to-disable-bitmap-magnification-blending-blur.html","title":{"rendered":"XNA &#8211; How to Disable Bitmap Magnification Blending (Blur)"},"content":{"rendered":"<p>In working on my code for Conway&#8217;s Game of Life, I ran into a problem with the default bitmap scaling behavior in XNA.  I&#8217;m generating a bitmap that I scale to the size of the window.  When this bitmap is displayed, it is shown as a blurry mess:<\/p>\n<p><a onblur=\"try {parent.deselectBloggerImageGracefully();} catch(e) {}\" href=\"http:\/\/4.bp.blogspot.com\/_6FCYONN4oMY\/R8vQbR1tFsI\/AAAAAAAAABw\/q9LGBSF4KXk\/s1600-h\/begin.jpg\"><img decoding=\"async\" style=\"margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;\" src=\"http:\/\/4.bp.blogspot.com\/_6FCYONN4oMY\/R8vQbR1tFsI\/AAAAAAAAABw\/q9LGBSF4KXk\/s320\/begin.jpg\" alt=\"\" id=\"BLOGGER_PHOTO_ID_5173457764028847810\" border=\"0\" \/><\/a><br \/>Removing that doggone blending is actually quite simple.  You have to modify your spriteBatch.begin() call, and modify the graphics device settings immediately after, like so:<br \/><!-- {\\rtf1\\ansi\\ansicpg\\lang1024\\noproof1252\\uc1 \\deff0{\\fonttbl{\\f0\\fnil\\fcharset0\\fprq1 Courier New;}}{\\colortbl;??\\red0\\green0\\blue0;\\red255\\green255\\blue255;\\red43\\green145\\blue175;}??\\fs20             spriteBatch.Begin(\\cf3 SpriteBlendMode\\cf0 .AlphaBlend, \\par ??                              \\cf3 SpriteSortMode\\cf0 .Immediate, \\cf3 SaveStateMode\\cf0 .None);} --> <\/p>\n<div    style=\"background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;\"><!-- {\\rtf1\\ansi\\ansicpg\\lang1024\\noproof1252\\uc1 \\deff0{\\fonttbl{\\f0\\fnil\\fcharset0\\fprq1 Courier New;}}{\\colortbl;??\\red0\\green0\\blue0;\\red255\\green255\\blue255;\\red43\\green145\\blue175;}??\\fs20             spriteBatch.Begin(\\cf3 SpriteBlendMode\\cf0 .AlphaBlend, \\par ??                              \\cf3 SpriteSortMode\\cf0 .Immediate, \\cf3 SaveStateMode\\cf0 .None);\\par ??            graphics.GraphicsDevice.SamplerStates[0].MagFilter = \\cf3 TextureFilter\\cf0 .None;} --> <\/p>\n<div    style=\"background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;\">\n<p style=\"margin: 0px;\">spriteBatch.Begin(<span style=\"color: rgb(43, 145, 175);\">SpriteBlendMode<\/span>.AlphaBlend, <\/p>\n<p style=\"margin: 0px;\">                  <span style=\"color: rgb(43, 145, 175);\">SpriteSortMode<\/span>.Immediate, <span style=\"color: rgb(43, 145, 175);\">SaveStateMode<\/span>.None);<\/p>\n<p style=\"margin: 0px;\">graphics.GraphicsDevice.SamplerStates[0].MagFilter = <span style=\"color: rgb(43, 145, 175);\">TextureFilter<\/span>.None;<\/p>\n<\/div>\n<div style=\"background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;\">\n<div style=\"background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;\"> <\/div>\n<\/p><\/div>\n<\/div>\n<p>The key in the spriteBatch.Begin() call is the <span style=\"color: rgb(43, 145, 175);\">SpriteSortMode<\/span>.  Setting this value to immediate causes any changes to the graphics device to be applied immediately.  And we want to make a change, as you can see in the next line of code.  I&#8217;m changing the magnification filter to <span style=\"color: rgb(43, 145, 175);\">TextureFilter<\/span>.None because I don&#8217;t want it to blue anything.  After this, you draw and scale your sprites like normal.  The result looks like this:<\/p>\n<p><a onblur=\"try {parent.deselectBloggerImageGracefully();} catch(e) {}\" href=\"http:\/\/3.bp.blogspot.com\/_6FCYONN4oMY\/R8vTMB1tFtI\/AAAAAAAAAB4\/lNjn_f-XMmg\/s1600-h\/end.jpg\"><img decoding=\"async\" style=\"margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;\" src=\"http:\/\/3.bp.blogspot.com\/_6FCYONN4oMY\/R8vTMB1tFtI\/AAAAAAAAAB4\/lNjn_f-XMmg\/s320\/end.jpg\" alt=\"\" id=\"BLOGGER_PHOTO_ID_5173460800570726098\" border=\"0\" \/><\/a><br \/>ahh&#8230; much better!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In working on my code for Conway&#8217;s Game of Life, I ran into a problem with the default bitmap scaling behavior in XNA. I&#8217;m generating a bitmap that I scale to the size of the window. When this bitmap is displayed, it is shown as a blurry mess: Removing that doggone blending is actually quite [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6,3],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-graphics","category-xna"],"_links":{"self":[{"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/lukerymarz.com\/alearningexperience\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}