<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Orange Day</title>
	<atom:link href="http://www.theorangeday.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theorangeday.com</link>
	<description>A Technical Jungle</description>
	<lastBuildDate>Sat, 21 Apr 2012 18:29:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>C++ Event System using Delegates</title>
		<link>http://www.theorangeday.com/tutorials/c-event-system-using-delegates/</link>
		<comments>http://www.theorangeday.com/tutorials/c-event-system-using-delegates/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 18:25:31 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/?p=136</guid>
		<description><![CDATA[Recently I&#8217;ve been working on an Event System in C++. You might be reading that right now and wonder why that small sentence makes it sound like a true endeavor. Well, it was. As many of you may know I&#8217;m a student at Champlain College, and in one of my classes, each of the students [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on an Event System in C++. You might be reading that right now and wonder why that small sentence makes it sound like a true endeavor. Well, it was. As many of you may know I&#8217;m a student at Champlain College, and in one of my classes, each of the students are tasked to use an event system or a messaging system in their game. The teacher provided us with one, and it&#8217;s really great and all, but I couldn&#8217;t help but feeling restricted, especially after having used C# for so long where the code is so forgiving, and easy.</p>
<p>I did some research and it turns out that a lot of event systems in C++ are organized in such a way that when you want to do events you must:</p>
<ul>
<li>Create an EventManager class (nothing wrong with this)</li>
<li>Create an EventListener class (for setting up events)</li>
<li>Create and Event base class</li>
<ul>
<li>Be restricted to use only one function to handle your events</li>
<li>Create a huge enum holding a key for each of your events (Can hash it for speed)</li>
</ul>
</ul>
<p>I saw those and my heart dropped. I immediately thought that is way to restrictive, there must be an easier way to get events to work. And so the researching began.</p>
<p><span id="more-136"></span></p>
<p>My first thought was about delegates (You can think of them as function pointers). I started browsing the Google results and quickly learned that C++ doesn&#8217;t have support for delegates (at least is wasn&#8217;t anything pretty). I thought well, function pointers? Can&#8217;t be too hard to set up. Oh dear, was I wrong. As it turns out, making (*) void function pointers (functions that are not in a class -&gt; not a member function) is really easy and super simple to do. This can be done literally in only a few lines (Delegate constructor omitted).</p>
<pre class="brush:cpp">class Delegate
{
public:
	void Link((*function)(int))
	{
		mFunction = function;
	}
	void Fire(int arg)
	{
		(mFunction)(arg);
	}
private:
	void (*mFunction)(int)
};</pre>
<p>What if I wanted to have an event that was linked to a member function? That is a whole other ball game. After hours of scouring the internet, it seemed that my only option (and true savior) was templates. Only recently in our classes have templates been introduced to us, but I know from my previously minor use of them, they ARE very very useful.</p>
<p>Let me break down how to set up a delegate that can link to a member function.</p>
<ul>
<li>Create a template definition that accepts a class parameter (C) for the class that the function is in</li>
<li>Create a second template type in that same definition that accepts a function(void (C::*Function)(TypeA*)) in the aforementioned type class</li>
<li>Set up a parameter in the function to pass a reference of an instance of class C to the function</li>
<li>Store the function and object reference.</li>
<li>Create a secondary function that when called will fire the function associated with the object</li>
</ul>
<p>Sounds easy right? Well, it is when you understand it, it&#8217;s much harder when you don&#8217;t especially when the &#8220;template magic&#8221; comes it. Understanding how to use templates with this was the most challenging, yet essential part of create a usable delegate class. I will admit that I did find some very good articles online that helped me a lot though.</p>
<pre class="brush:cpp">class Delegate
{
	typedef void *mInstance; // general instance. Not type specific
	typedef void (*mInternal)(mInstance, EventData*); // Link to internal func
public:
	template &lt;class T, void (T::*Function)(EventData*)&gt;
	void Link(T* obj)
	{
		mInst = obj;
		mInternalFunction = &amp;InternalLaunch&lt;T, Function&gt;;
	}
	void Fire(EventData* arg)
	{
		mInternalFunction(mInst, arg);
	}
	template &lt;class T, void (T::*Function)(EventData*)&gt;
	static inline void InternalLaunch(mInstance ptr, EventData* arg)
	{
		return (static_cast&lt;T*&gt;(ptr)-&gt;*Function)(arg);
	}
private:
	mInternal mInternalFunction;
	mInstance mInst;
};</pre>
<p>The above sample code only shows how to implement support for JUST member functions. Taking a look at the code you&#8217;ll see that it&#8217;s essentially just linking to an internal function that launches the templated outside member function. Adding the ability to link to (*)(void) functions is very easy and just requires the simple implementation of a few altered functions. Here is the actual delegate class that I use, and will provide in a download link:</p>
<p>&nbsp;</p>
<pre class="brush:cpp">class Delegate
{
	//Create some typedefs to manage references easier
	typedef void *InstancePtr;
	typedef void (*InternalFunction)(InstancePtr, EventData*); //This holds an internal function reference

public:

	template &lt;void (*Function)(EventData*)&gt;
	static Delegate* create(void)
	{
		Delegate* del = new Delegate();
		del-&gt;Bind&lt;Function&gt;();
        return del;
	}
	template &lt;class C, void (C::*Function)(EventData*)&gt;
	static Delegate* create(C* obj)
	{
		Delegate* del = new Delegate();
		del-&gt;Bind&lt;C, Function&gt;(obj);
        return del;
	}

	template &lt;void (*Function)(EventData*)&gt;
	void Bind(void)
	{
		mInst = NULL;
		mInternal = &amp;Method&lt;Function&gt;;
	}
	template &lt;class C, void (C::*Function)(EventData*)&gt;
	void Bind(C* obj)
	{
		mInst = obj;
		mInternal = &amp;ClassMethod&lt;C, Function&gt;;
	}

	void Invoke(EventData* ARG0)
	{
		return mInternal(mInst, ARG0);
	}

	template &lt;void (*Function)(EventData*)&gt;
	static inline void Method(InstancePtr, EventData* ARG0)
	{
		return (Function)(ARG0);
	}
	template &lt;class C, void (C::*Function)(EventData*)&gt;
	static inline void ClassMethod(InstancePtr ptr, EventData* ARG0)
	{
		return (static_cast&lt;C*&gt;(ptr)-&gt;*Function)(ARG0);
	}

private:

	Delegate(void) {}

	InternalFunction mInternal;
	InstancePtr mInst;

};</pre>
<p>Now using this with an event system is as easy as setting up a map to have references to each of the delegates that have been created. NOTE: You&#8217;ll notice that I&#8217;ve created two alternate create functions that are static. I&#8217;ve done this because I want to be able to create a delegate in one line and then pass that to the EventManager this way I don&#8217;t have to create it outside of the event definition.</p>
<p>Get all the files here: <a href="http://www.theorangeday.com/wp-content/uploads/2012/04/EventSystem.zip">Download Event System</a></p>
<p>If you have any questions feel free to post a comment!</p>
<p>-Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/tutorials/c-event-system-using-delegates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding C# 2D XNA HLSL &#8211; Part 2</title>
		<link>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl-part-2/</link>
		<comments>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl-part-2/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 02:28:04 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/?p=116</guid>
		<description><![CDATA[Read the first part here I know a lot of you loved the first part of this breakdown, and now I&#8217;m back to continue the explaining! Breakdown of Effect Parameter Continuing from the end of the first part: What the effect parameter does here is that it takes our effect and then applies it to [...]]]></description>
			<content:encoded><![CDATA[<p>Read the <a title="Understanding C# 2D XNA HLSL" href="http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl/">first part here</a></p>
<p>I know a lot of you loved the first part of this breakdown, and now I&#8217;m back to continue the explaining!</p>
<h3>Breakdown of Effect Parameter</h3>
<p>Continuing from the end of the first part: What the effect parameter does here is that it takes our effect and then applies it to all of the textures that you draw then on. This is effective for coloration effects such as black and white, or inverting colors, but if you have an effect that works based on certain coordinates or is constricted similarly, then you need to be  very careful! To avoid issues like that, there is a rather simple solution when you want to apply an aforementioned size/position constricted effect to the screen.</p>
<h3>Further Implementation</h3>
<p>Adjusting the Effect parameter of the SpriteBatch.Begin() function is not the only way to use HLSL effects in your projects. Another method that you can do is draw all of your textures to one RenderTarget2D (Think of this as an empty texture, or a blank canvas). After you&#8217;ve drawn all your textures to that, it&#8217;s really easy to apply your effect to &#8220;the screen&#8221;.</p>
<pre class="brush:csharp">RenderTarget2D MainTexture;

//In the Initialize function set up the rendertarget:
PresentationParameters pp = GraphicsDevice.PresentationParameters;
MainTexture = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);

        //Then create a function to draw your game textures to, and draw it all up       

        private void DrawGame(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(MainTexture);
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            spriteBatch.Draw(bg, GraphicsDevice.Viewport.Bounds, Color.White);
            spriteBatch.Draw(player, new Vector2(200, 300), new Rectangle(0, 0, 128, 128), Color.White);

            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);
        }

        /// &lt;summary&gt;
        /// This is called when the game should draw itself.
        /// &lt;/summary&gt;
        /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt;
        protected override void Draw(GameTime gameTime)
        {
            DrawGame(gameTime);

            GraphicsDevice.Clear(Color.Black);

            // Use Immediate mode and our effect to draw the scene again, using our pixel shader.
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            mainEffect.CurrentTechnique.Passes[0].Apply(); // for every pass that you have you can apply
                                                           // all them to the texture if you want.
            spriteBatch.Draw(MainTexture, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }</pre>
<p>Alternatively, you can use the effect parameter in the spriteBatch.Begin() function when drawing MainTexture, because remember: The effect is applied to the texture in every Draw() function call. If you only have to draw one texture and want all the passes applied when drawn, then you can use the Effect parameter.</p>
<h3>Why do this?</h3>
<p>In a project I was working on I really wanted to have an INFINITE amount of 2D lights in my game, and after countless attempts at getting a high number lights (higher than 5) from all HLSL effects, I found that by drawing a my lights to a texture, and then my game to another, I could then use an HLSL effect to blend my lights together.</p>
<p>&nbsp;</p>
<p>I hope this helped.</p>
<p>-Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Git with a Subversion Repository</title>
		<link>http://www.theorangeday.com/tutorials/using-git-with-a-subversion-repository/</link>
		<comments>http://www.theorangeday.com/tutorials/using-git-with-a-subversion-repository/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 20:36:55 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/?p=125</guid>
		<description><![CDATA[Using git bash with a subversion repository is very easy when you know how to use it! First, you&#8217;ll want to head over to the Git Website and get the latest release of the git application (we&#8217;ll be using git bash) NOTE: when you install, consider checking &#8220;Git Bash Here&#8221; as a context menu option: [...]]]></description>
			<content:encoded><![CDATA[<p>Using git bash with a subversion repository is very easy when you know how to use it!</p>
<p>First, you&#8217;ll want to head over to the <a title="git client" href="http://git-scm.com/" target="_blank">Git Website</a> and get the latest release of the git application (we&#8217;ll be using git bash)</p>
<p>NOTE: when you install, consider checking &#8220;Git Bash Here&#8221; as a context menu option:</p>
<p><a href="http://www.theorangeday.com/wp-content/uploads/2012/01/gitinstall.png"><img class="alignnone size-full wp-image-126" title="gitinstall" src="http://www.theorangeday.com/wp-content/uploads/2012/01/gitinstall.png" alt="" width="503" height="388" /></a></p>
<p>After it&#8217;s installed, go ahead and open git bash and cd to a directory where you want to download the repo to, or if you chose to install that context menu option, navigate to your folder in explorer (or finder) and right click on it then &#8220;Git Bash here&#8221;.</p>
<p>After that go ahead and run the &#8220;git svn clone&#8221; command on your repo, example:</p>
<pre class="brush:plain">git svn clone https://svn.webhost.com/svn/sp12egp31001</pre>
<p>Alternatively, you can clone a subdirectory of the svn repository by simply writing the directory name at the end of the repo address. This is particularly useful when you&#8217;re working on a large project and don&#8217;t want to download all the files on the server.</p>
<pre class="brush:plain">git svn clone https://svn.webhost.com/svn/sp12egp31001/subdirectory</pre>
<p>After you run the command you&#8217;ll be prompted for authentication, go ahead and fill that out and your repository will be downloaded onto your machine.</p>
<p>From there you&#8217;ll be able to modify the code, or whatever it is as you would regularly, then when you are ready to push changes back to the server, all you have to do is add these changes, and get them ready for commiting.</p>
<p>To start, go ahead and run this command:</p>
<pre class="brush:plain">git status</pre>
<p>That should list out all the files you&#8217;ve modified, added, or deleted.</p>
<p><a href="http://www.theorangeday.com/wp-content/uploads/2012/01/gitexample.png"><img class="alignnone size-full wp-image-130" title="gitexample" src="http://www.theorangeday.com/wp-content/uploads/2012/01/gitexample.png" alt="" width="677" height="392" /></a></p>
<p>To track these changes run the add command:</p>
<pre class="brush:plain">git add .</pre>
<p>The &#8220;.&#8221; at the signifies that you would like to track all the changes that were made. Another thing to note is that if you deleted a lot of files you would want to run the add command with another optional parameter:</p>
<pre class="brush:plain">git add -u .</pre>
<p>This should track all the changes made, regardless of deleted, added, or changed.</p>
<p>Once you are satisfied you will need to make a commit to your local git repository by running the git command:</p>
<pre class="brush:plain">git commit -m "Your message goes here!"</pre>
<p>Something to note about the commit command: You don&#8217;t have to use the -m parameter, it&#8217;s just that it&#8217;s much easier to do this, rather than being taken to a command line text editor to write a message.</p>
<p>Once you&#8217;ve commited your changes to your local git repository, you&#8217;re ready to push them to online subversion repository!</p>
<p>When pushing your git changes back to the online repository, you&#8217;ll want to run the subversion rebase command. What this command does is download all the changed files from the repository. You won&#8217;t be able to add your changes to the online repository if you don&#8217;t do this:</p>
<pre class="brush:plain">git svn rebase</pre>
<p>After you&#8217;ve run that command, the only thing left is to commit those changes to your online svn repository:</p>
<pre class="brush:plain">git svn dcommit</pre>
<p>And, that&#8217;s it! You&#8217;ve successfully learned to use the git bash with a subversion repository!</p>
<p>One more thing to note if you work on multiple machines. If you&#8217;ve cloned your repository on multiple machines you&#8217;ll need to run the rebase command:</p>
<pre class="brush:plain">git svn rebase</pre>
<p>to download any changes from the server that you&#8217;ve commited from your other machine BEFORE you start working on your code on your current machine.</p>
<p>&nbsp;</p>
<p>Now you&#8217;re ready to get working with git on your subversion repositories!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/tutorials/using-git-with-a-subversion-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minecraft-Style Engine in XNA 4.0</title>
		<link>http://www.theorangeday.com/xna/minecraft-style-engine-in-xna-4-0/</link>
		<comments>http://www.theorangeday.com/xna/minecraft-style-engine-in-xna-4-0/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 22:51:55 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/?p=119</guid>
		<description><![CDATA[Hey gang, So lately I&#8217;ve been messing around with creating a minecraft-styled engine in XNA 4.0. Currently I think it&#8217;s going really well. Check it out and let me know what you think: One of the most important things about this project for me is optimization. What&#8217;s great about minecraft is that there are so [...]]]></description>
			<content:encoded><![CDATA[<p>Hey gang,</p>
<p>So lately I&#8217;ve been messing around with creating a minecraft-styled engine in XNA 4.0. Currently I think it&#8217;s going really well. Check it out and let me know what you think:</p>
<p><iframe src="http://www.youtube.com/embed/sUoLcRUEvFU?rel=0" frameborder="0" width="480" height="360"></iframe></p>
<p>One of the most important things about this project for me is optimization. What&#8217;s great about minecraft is that there are so many things on the screen and there is virtually no lag at all. This isn&#8217;t just about me making a minecraft clone, I really want to become better at working in large environments, and allowing them to run as fast as they can!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/xna/minecraft-style-engine-in-xna-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding C# 2D XNA HLSL</title>
		<link>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl/</link>
		<comments>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 16:23:38 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[Shader]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=13</guid>
		<description><![CDATA[Introduction Firstly, what is HLSL? What can we use it for? HLSL is an acronym for High-Level Shader Language, and because it is a shader language, it runs on the GPU of the computer. With HLSL you can perform many post-processing effects, such as: blur, point lights, black and white, bloom, and pretty much any [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>Firstly, what is HLSL? What can we use it for? HLSL is an acronym for High-Level Shader Language, and because it is a shader language, it runs on the GPU of the computer. With HLSL you can perform many post-processing effects, such as: blur, point lights, black and white, bloom, and pretty much any filter you can think of that can be done in Adobe Photoshop.</p>
<p>When working with HLSL on the Xbox 360, you are limited to using Pixel Shader 2.0 (This way you can support all Xbox&#8217;s) rather than 3.0, which isn&#8217;t terribly bad, but it could be so much better. You can do a lot with pixel shader 2.0 with up to 64 mathematical operations per-pixel. Because it is a pixel shader, the code that you write will be executed on every single pixel that is on the texture you&#8217;re working with. If your game resolution is 720&#215;360, totalling to 259200 pixels, and if you have 3 mathematical operations per pixel (for example you are using sin, cos, and +), totalling to 777600 mathematical operations done for every time this shader code is ran (typically the total amount of times you draw the effect to the screen).</p>
<p>&nbsp;</p>
<p><strong>Examples</strong></p>
<p>Nearly any filter that can be done in photoshop can be done with a shader. So, check out an example (more to come):</p>
<div id="attachment_35" class="wp-caption alignnone" style="width: 310px"><a href="http://www.theorangeday.com/wp-content/uploads/2011/10/radialblur.jpg"><img class="size-medium wp-image-35" title="Radial Blur Example" src="http://www.theorangeday.com/wp-content/uploads/2011/10/radialblur-300x120.jpg" alt="Radial Blur Example" width="300" height="120" /></a><p class="wp-caption-text">fig. 1.0: Radial Blur</p></div>
<p><span id="more-13"></span></p>
<p><strong>Structure &amp; Creation</strong></p>
<p>A typical HLSL file has the extension .fx, and can be named pretty much anything, myFilter.fx, or blur.fx, etc.. An HLSL file is a lot like a C/C++ file in the idea that functions must be predefined, and cannot be defined before the main pixel shader function, it also shares similar syntax to C/C++. If you need to find see a code reference for some of the built-in methods, why don&#8217;t you check out the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff471376%28v=vs.85%29.aspx" rel="nofollow" target="_blank">XNA Intrinsic Methods</a><strong>. </strong>I think the best way to learn to program a shader is to first see a sample, then start to break it down.</p>
<p>Before we start, I need to point you to a realtime HLSL editor that was essential to my shader development. Here&#8217;s a youtube video showing it in action:</p>
<p><object width="560" height="315" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/7dfq9aiMpJs?version=3&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed width="560" height="315" type="application/x-shockwave-flash" src="http://www.youtube.com/v/7dfq9aiMpJs?version=3&amp;hl=en_US" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<p>And link to the apphub forum topic is <a href="http://forums.create.msdn.com/forums/t/87980.aspx" target="_blank">here</a>, and the you can <a href="http://foxprods.net/experimentalists/PixelShaderEditor.rar" target="_blank">download it here</a>. Some of the code I show here won&#8217;t necessarily work perfectly with the editor, but it gives you good base to work from, and it isn&#8217;t exactly rocket science to get things working either.</p>
<p>Let&#8217;s get started. The first thing we are going to make is a shader that turns the whole screen black and white. First, we&#8217;ll see the code. Then I&#8217;ll go through it and explain what everything does.</p>
<pre class="brush:cpp">uniform extern texture ScreenTexture;	

sampler screen = sampler_state
{
	Texture = &lt;ScreenTexture&gt;;
};

float4 PixelShaderFunction(float2 inCoord: TEXCOORD0) : COLOR
{
	float4 color = tex2D(screen, inCoord);

	color.rgb = (color.r+color.g+color.b)/3.0f;

	return color;
}

technique
{
	pass P0
	{
		PixelShader = compile ps_2_0 PixelShaderFunction();
	}
}</pre>
<p><strong>The Breakdown</strong></p>
<p>Lines 1-6: Defining a texture that we will be using in our function. To note, you can have more that one texture in your shader, you aren&#8217;t limited to having only that one. For example, some people use multiple textures when creating a toon (cel) shader. The texture that is typically loaded has a few colors to choose from. Another example of multiple textures is used in lights, rather than calculating attenuation, they just reference the pixel position on the texture and adjust accordingly.</p>
<p>Lines 8-15: This is the good stuff. We&#8217;ve defined our actual shader function, PixelShaderFunction, we then gave a parameter that holds the position of the current pixel on the screen we are working with. From there we can do anything. I took this position, plugged it into a built in function that returns a color from any texture. Keeping in mind that we want all pixels to be in black and white, I added all the color channels together, then averaged them, returning a grey-scale value.</p>
<p>Lines 10-End: This is the technique that will be used in drawing our shader, and it only has one pass. Something to note about the technique and passes are that you can have as many as you want. So let&#8217;s say you have another function that pixelates the texture, and the current black and white function. You can create a second pass that has the pixelate function in it, and then run a loop doing all the passes, meaning that first the texture will be turned black and white, and then that black and white texture will then be pixelated.</p>
<p><strong>HLSL Specifics</strong></p>
<p>The coordinate that is passed into the PixelShaderFunction is not a pixel-based number, it is actually a position that is a relative percentage of the texture. IE, {0.5, 0.5} is the center of the texture. A couple of work arounds are to create 2 variables, one that holds the texture width, and one that holds the texture height, then mutliple the inputed coordinate by those values.</p>
<p>Positions aren&#8217;t the only thing that are 0 &#8211; 1, colors are also 0 &#8211; 1.</p>
<p>Properties of floats: If you have a float4, you can access all four values as if it was an array, myFloat[2] (this modifies the blue value because the index does start at 0), or you can use &#8220;r&#8221;, &#8220;g&#8221;, &#8220;b&#8221;, or &#8220;a&#8221;, myFloat.b = 0.5, If you want to modifiy the RGB values at the same time, you can do that too: myFloat.rgb *= 0.5;.</p>
<p><strong>How to use shaders in XNA 4.0</strong></p>
<p>Using shaders in XNA 4.0 is EXTREMELY easy. Look:</p>
<pre class="brush:csharp">// Create our effect variable:
Effect mainEffect;

//In the LoadContent function, load your fx file
protected override void LoadContent()
{
    spriteBatch = new SpriteBatch(GraphicsDevice);

    mainEffect = Content.Load&lt;Effect&gt;("bnw");
}

// When you initialize spriteBatch.Draw(...) pass in your effect as a param
protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin(0, null, null, null, null, mainEffect);
    // Draw things here.
    spriteBatch.End();

    base.Draw(gameTime);
}</pre>
<p>Now, this is great and all, but what if you want a few textures to have the shader applied to them, and the rest to display regularly. Well, it&#8217;s easy enough:</p>
<pre class="brush:csharp">protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin();
    // Draw things regularly here.
    spriteBatch.End();

    spriteBatch.Begin(0, null, null, null, null, mainEffect);
    // Draw things here that will have the shader applied to them.
    spriteBatch.End();

    base.Draw(gameTime);
}</pre>
<p>You can&#8217;t only have one SpriteBatch and still apply effects to specific textures. Pretty much if you&#8217;re gonna use shaders, then you you have to draw it separately from other things being drawn.</p>
<p>&nbsp;</p>
<p>More to come about doing specific passes and techniques to have full control over your shaders.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/xna/understanding-c-2d-xna-hlsl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crate Crash 2 and More</title>
		<link>http://www.theorangeday.com/flash/crate-crash-2-and-more/</link>
		<comments>http://www.theorangeday.com/flash/crate-crash-2-and-more/#comments</comments>
		<pubDate>Thu, 26 May 2011 18:01:25 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Arcade Script]]></category>
		<category><![CDATA[Arcades]]></category>
		<category><![CDATA[Crate Crash]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=75</guid>
		<description><![CDATA[Hey, It&#8217;s been a pretty long time since I last updated. I&#8217;ve been up to a few things lately. One of the biggest things I want to address is the development of Crate Crash 2. A few of you know of the first Crate Crash game, but for those of you who don&#8217;t, you can [...]]]></description>
			<content:encoded><![CDATA[<p>Hey,</p>
<p>It&#8217;s been a pretty long time since I last updated. I&#8217;ve been up to a few  things lately. One of the biggest things I want to address is the  development of Crate Crash 2. A few of you know of the first Crate Crash  game, but for those of you who don&#8217;t, you can play it here: <a href="http://www.topphysicsgames.com/block-removal/play-crate-crash" target="_blank">Crate Crash at TopPhysicsGames.com</a>.  The first Crate Crash game is all about clicking the game screen to  apply impulses or little explosions that launch the crates. The goal of  the game was to get the crates off of the screen, and this goal is still  pertinent in the second game, BUT there are more crazy levels,  obstacles, and challenges to get through.</p>
<p>The biggest issue that I noticed that people were having was that the  game was way too damn hard. Now that I go back and play it again, I  think it&#8217;s too hard. What I&#8217;m going to do with CC2 is create different  difficulties. By default users will be playing on casual mode which will  allow you to just play the game with no limits of restrictions (that  means no medals on the levels, and no click limit). I&#8217;ve found having a  sandbox-type mode allows the user to have a more enjoyable experience, I  know that for a fact because sometimes in developing the game I get  distracted just messing with the physics.</p>
<p>Another change from the original is that there will be less levels. It  isn&#8217;t completely final how many levels there will be, but right now I  have a 45 level cap. It could increase, but I don&#8217;t think it will.</p>
<p>The biggest feature of Crate Crash 2 will be the level editor. Users  these days like to create their own content, and with the level editor  that I&#8217;ve made, creating your own content should be VERY easy. I&#8217;ve had a  few ideas of how I wanted to share these levels and I have few ideas  going on in my head.</p>
<p>In other news, I am developing my own arcade script, Custom Arcade  Script (Pretty cool name, right?). After being in the arcade scene for  nearly 2 years now, and having mild success, and looking at how the  arcade business is being handled, I&#8217;m not 100% satisfied with the way  that arcade scripts work today. I&#8217;ve tried a few arcade scripts, and  none of them are particularly great. They all their ups and downs, but  none of them are a one-stop solution. Custom Arcade Script looks to  provide just that. CAS will encompass some of the newest and most  reliable arcade-related code available. With its streamlined interface,  and easy to use admin panel, I have no doubt that Custom Arcade Script  will be a huge contender in the arcade script market when it&#8217;s released!</p>
<p>-Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/flash/crate-crash-2-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Review of 1upmedia.biz</title>
		<link>http://www.theorangeday.com/reviews/a-review-of-1upmedia-biz/</link>
		<comments>http://www.theorangeday.com/reviews/a-review-of-1upmedia-biz/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 17:59:10 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Arcade Script]]></category>
		<category><![CDATA[Arcades]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=72</guid>
		<description><![CDATA[Hey everybody, it&#8217;s been a long time since I last updated, nearly a year! One of the things I&#8217;ve been doing a lot lately is focusing on website promotion. As many of you may or may not know, I&#8217;ve been getting into flash arcades and the monetization behind them quite a bit lately, and I&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>Hey everybody, it&#8217;s been a long time since I last updated, nearly a year!</p>
<p>One of the things I&#8217;ve been doing a lot lately is focusing on website  promotion. As many of you may or may not know, I&#8217;ve been getting into  flash arcades and the monetization behind them quite a bit lately, and  I&#8217;d like to touch upon a new <a href="http://1upmedia.biz/" target="_blank">online games advertising</a> company that I started using in early June of this year (2010).  1upMedia.biz is an arcade and flash game advertising platform looking to  deliver quality and targeted ads on your arcade sites. I&#8217;ve used both  the Publisher and Advertising features on the site, and I&#8217;d have to say  for what I&#8217;ve used them for, I&#8217;m pretty pleased. On the Publisher side  of 1upMedia you get an easy to use and comprehensive overlook of the  months earnings, clicks, and impressions, as well as other miscellaneous  details. The best part about this is that the data is presented on an  interactive flash graph, and allows you seamlessly and easily check your  earnings for the previous day or whichever. Another thing I liked about  1upMedia.biz is that minimum payouts are at $25. Just this month I&#8217;ve  actually reached the $25 minimum payout, and I think Eddie (the owner  and CEO of 1upMedia) pays on a NET30 basis, meaning I&#8217;ll receive my  payment by the end of November. You may be thinking that earning $25 in 4  months is not that great at all, however, this is not really that bad  at all, I mainly use 1upMedia as a filler ad, and a footer ad. Really,  1upMedia is just an extra ad to try to fetch me some more money, and  really, it does work. Currently, I only have a 728&#215;90 banner on the top  of every pre-game page, and two 728&#215;90 ads at the top of my play pages.  The ads that are delivered are not intrusive, don&#8217;t spawn popups, and  give my users (or me) viruses. I can attest to the fact that anyone who  uses 1upMedia&#8217;s advertising platform doesn&#8217;t have the chance to create  an intrusive ad, or anything that will truly annoy a user. I started  advertising at the same time I signed up for the publisher program, and  from the time I started using it, and the time I stopped advertising  with them (for financial reasons, not because of anything to do with  1upMedia) I was very pleased. I had a great conversion rate, and  earnings on quite a few days were greater than what I had spent for the  users from 1upMedia.</p>
<p>For anyone who is looking for a great filler ad with great earning potential look no further than the <a href="http://1upmedia.biz/" target="_blank">Flash ads</a> company, 1upMedia.</p>
<p>Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/reviews/a-review-of-1upmedia-biz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make a platform engine in QuickBox2D &#8211; Part 2</title>
		<link>http://www.theorangeday.com/flash/how-to-make-a-platform-engine-in-quickbox2d-part-2/</link>
		<comments>http://www.theorangeday.com/flash/how-to-make-a-platform-engine-in-quickbox2d-part-2/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 17:58:06 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[Platform]]></category>
		<category><![CDATA[QuickBox2D]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=69</guid>
		<description><![CDATA[Read Part One of the article, it covers some of the basics, and explains a few things. With the release of QuickBox2D 1.0 I figure I should update my game engine articles. I won&#8217;t actually update the first one, but instead I will provide updated versions here, with links to download the files (source). One [...]]]></description>
			<content:encoded><![CDATA[<p>Read <a title="How to make a platform engine in QuickBox2D" href="http://www.theorangeday.com/wordpress/2009/07/14/how-to-make-a-platform-engine-in-quickbox2d/">Part One</a> of the article, it covers some of the basics, and explains a few things.</p>
<p>With the release of <a href="http://actionsnippet.com/?p=2187" target="_blank">QuickBox2D 1.0</a> I figure I should update my game engine articles. I won&#8217;t actually  update the first one, but instead I will provide updated versions here,  with links to download the files (source).</p>
<p>One of the best things about the new QuickBox2D is the addition of QuickContacts.</p>
<pre class="brush:as3">var contacts:QuickContacts = sim.addContactListener();
contacts.addEventListener(QuickContacts.ADD, onAdd);
contacts.addEventListener(QuickContacts.PERSIST, onPersist);
contacts.addEventListener(QuickContacts.REMOVE, onRemove);

function onAdd(evt:Event):void{
	if(contacts.currentPoint.shape1 == main.shape || contacts.currentPoint.shape2 == main.shape){
		if(contacts.currentPoint.normal.y &gt;= -1 &amp;&amp; contacts.currentPoint.normal.y &lt; 0){
			grounded = true;
		}
	}
}
function onPersist(evt:Event):void{
	if(contacts.currentPoint.shape1 == main.shape || contacts.currentPoint.shape2 == main.shape){
		if(contacts.currentPoint.normal.y &gt;= -1 &amp;&amp; contacts.currentPoint.normal.y &lt; 0){
			grounded = true;
		}
	}
}
function onRemove(evt:Event):void{
	grounded = false;
}</pre>
<p>QuickContacts is a class that uses the b2ContactListener class that  comes stock with Box2D. If you remember, we actually modified that class  so we could detect if we were touching things (this way our character  could jump). With this addition, we won&#8217;t actually need to modify that,  AND we won&#8217;t have to make that global class. We can just do all the code  on the timeline.</p>
<p>On the first part of the series, someone commented saying that if you  add an object that does NOT have a zero density, that game would get  pretty messed up. Well, he was right. That was because in the  b2ContactListener, when we checked to see if we were grounded, the class  was actually checking every single object against each other. Meaning  that any object with zero density was being checked, and since it was  sitting on the boxes right, it would set our grounded variable to true.</p>
<p>One more addition to the platform engine is the ability to make  platforms that you can jump through the bottom, this isn&#8217;t really new  feature, but it&#8217;s pretty nice. To be honest, the code that actually  makes it so you can jump through the bottom of platforms was originally  taken <a href="http://actionsnippet.com/?p=2114" target="_blank">from a snippet</a> on Actionsnippet.com, the creator of QB2D. So, thanks Zevan.</p>
<p>I also made numerous fixes to the code from the last version. One of  these fixes include changing direct modification of gravity, to setting  the main character object to sleep. I would change the gravity to 0 when  the main character was standing on a platform, specifically on a slope,  so that the character wouldn&#8217;t slide down. However, it turns out to be a  better plan to set the object to sleep. Why? Well, if you push one of  those non-zero density spheres off a platform, it won&#8217;t actually fall  with the old system, whereas the new system fixes that.</p>
<p><a href="../../content.php?type=flash&amp;file=/Content/Demo/phystest2.swf" target="_blank">Test the QB2D Engine</a></p>
<p><a href="../../Content/Full/PhysicsPlatformer2.zip" target="_blank">Download the source</a></p>
<p>What should I add to the new version? Suggestions?</p>
<p>Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/flash/how-to-make-a-platform-engine-in-quickbox2d-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 Ways to Improve Your Flash Game</title>
		<link>http://www.theorangeday.com/flash/5-ways-to-improve-your-flash-game/</link>
		<comments>http://www.theorangeday.com/flash/5-ways-to-improve-your-flash-game/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 17:55:48 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[Improve]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=66</guid>
		<description><![CDATA[You just made the best flash game ever, huh? Is that so? Before releasing your game into the wild, make sure you try some of the following: Add a Highscore Table Highscores are a great way to get people to play your game more, and enjoy it. A highscore table in this day and age [...]]]></description>
			<content:encoded><![CDATA[<p>You just made the best flash game ever, huh? Is that so? Before releasing  your game into the wild, make sure you try some of the following:</p>
<p><strong>Add a Highscore Table</strong></p>
<p>Highscores are a great way to get people to play your game more, and  enjoy it. A highscore table in this day and age is becoming more of a  standard for flash games than ever before. The player practically lives  to be &#8216;the best&#8217;, so why not help them the best by letting them show it.</p>
<p><strong>Add Achievements</strong></p>
<p>This practically goes hand in hand with having a highscore a table.  Users lately have been expecting a rewards for actions they perform in  games. Major consoles have them, and if they have them, there&#8217;s no doubt  that Flash game players will be expecting them as well.</p>
<p><strong>Have Good Audio</strong></p>
<p>Some people totally skip this part. This is a vital part of creating a  great game. Games that totally skimp out on taking the time to get audio  that fits the game are only hurting themselves. I&#8217;m not saying throw a  sound effect on every little thing in the game, I&#8217;m just saying don&#8217;t be  too intrusive on how it&#8217;s played out. Menu&#8217;s should have their own  music, different locations in the game should have different music.  Every viral and popular game has great audio that adds to feeling of the  game. Imagine you&#8217;re doing the final level of Halo to vivaldi, not very  epic is it? Vivaldi would definetly ruin the mood.</p>
<p><strong>Use less text!</strong></p>
<p>One mistake that most developers make is that they use too much text.  People going online looking to play some free flash games after a hard  day aren&#8217;t looking to read, they want to relax and have some fun. So,  try to avoid lengthy instruction screens. Players are looking for simple  intuitive controls. If you absolutely need to have directions in the  game, so be it. But, add a skip button so they don&#8217;t have to sit through  it. Then, show a graphics, or something real quick to tell the  controls. Just so they know.</p>
<p><strong>Spend a day or two tweaking</strong></p>
<p>You don&#8217;t know how many developers skip this step and are just so eager to  get they&#8217;re game out there that they forget to bug check, and as a  result lose fans. Let&#8217;s say a developer gave the boss on level 12 too  much health, resulting in half the people playing getting frustrated.  Five minutes of adjustment could have made the game that much more  enjoyable. Other things could be added to keep the players hooked are  save games, cutscenes, special effects, and etc.</p>
<p>Making a great viral flash game can be a daunting task, but I hope this guide/outline will help make that task a little easier.</p>
<p>Please, don&#8217;t hesitate to comment. Your opinions are always welcome.</p>
<p>-Tom</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/flash/5-ways-to-improve-your-flash-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Unsigned Integers to Hexadecimal Strings</title>
		<link>http://www.theorangeday.com/flash/convert-unsigned-integers-to-hexadecimal-strings/</link>
		<comments>http://www.theorangeday.com/flash/convert-unsigned-integers-to-hexadecimal-strings/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 17:52:58 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[Convert]]></category>
		<category><![CDATA[Hexadecimal]]></category>

		<guid isPermaLink="false">http://www.theorangeday.com/wordpress/?p=63</guid>
		<description><![CDATA[So, you wanna convert a uint to hex in AS3, huh? Well, this is how you do it: function uintToHex(val:uint):String { var pref:String = "000000"; var str:String = String(pref + val.toString(16)); return "#" + str.substr(-6).toUpperCase(); } What I think this is really useful for is converting randomly generated colors to hexadecimals so that you can [...]]]></description>
			<content:encoded><![CDATA[<p>So, you wanna convert a uint to hex in AS3, huh? Well, this is how you do it:</p>
<pre class="brush:as3">function uintToHex(val:uint):String {
	var pref:String = "000000";
	var str:String = String(pref + val.toString(16));
	return "#" + str.substr(-6).toUpperCase();
}</pre>
<p>What I think this is really useful for is converting randomly generated  colors to hexadecimals so that you can access them later. I mean, it&#8217;s  not that the uint equivalents are bad or anything, but the hex codes are  generally easier to work with.</p>
<p>Also, awhile back I was browsing the web seeing how other people managed to do this, and I found this post: <a href="http://www.tylerbeck.com/2009/04/22/convert-unsigned-integers-to-hexadecimal-strings/" target="_blank">Tylerbeck.com</a><br />
Feel free to check it out. It&#8217;s really great for understanding  hexadecimals a bit more. It&#8217;s a longer function, but does the exact same  thing as this one.</p>
<p>Good Luck,<br />
Thomas</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theorangeday.com/flash/convert-unsigned-integers-to-hexadecimal-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

