Click here to Skip to main content
13,510,146 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 7 Feb 2013

Does Lightning Really Strike Twice?

, 7 Feb 2013
Rate this:
Please Sign up or sign in to vote.
Does lightning really strike twice?

It all started one sunny morning when Michael Hoffman who wrote a shocking article on some fantastic lighting effects all done with XNA. I read this and was immediately impressed by just how simple his solution was.

Not long after this, a guy down under called Jose Fajardo was so impressed, he went and got the same framework running on Windows 8 /Windows RT using Sharp DX combined with XAML.

Both demos really show the power and ease of building projects using XNA, I was tempted to follow up like Jose following Michael’s article but was busy with other projects. With Jose’s article, I felt freshly invigorated in the light of my XNA futures series to show both how easy it is to use this solution, but also to go further, e.g. BEYOND!!! Open-mouthed smile

The source for the series can be found here on Codeplex as well as the code drop for this stage here.

Going Portable with MonoGame

As you would expect, porting Michael's solution over to MonoGame is very simple since MonoGame is just a direct replacement for XNA at present. Not all plain sailing as especially with the Windows version, not all graphical capabilities are available, usually because they didn’t make sense (a bridge too far) or where further work is still required either in SharpDX (the graphical underlay of MonoGame) or the current implementation.

First off, you had better swing over to the new MonoGame website and grab the latest MonoGame installer, they updated it in January and added a host of new features and supported platforms.


(Pretty Ain’t it Open-mouthed smile,I especially like the rotating images of popular MonoGame projects.)

With the new version installed, you’ll be presented with the new project templates when starting a new project:


As expected, the Android and Linux builds are still there, there is a new player to the party with the Ouya (be sure to check on the requirements as Ouya deployment will also need a Xamarin Android license to deploy), two features to existing users that will catch your eye is that the Windows Project has now been renamed to OpenGL (unknown as yet whether there will be a DX variant or if this is a permanent shift?), the other thing of note is that there has been significant work on the Content building side (also now supported in VS 2012 but more on that later). After much criticism, the content project has been simplified and updated to support more traditional content plus the addition of content building for the new platforms.

After you have started your new Windows project, just add an additional project for the Content to the solution and you should have a clean setup as below:


**Note, at the time of writing, there is an issue in the new "Windows OpenGL" project template which incorrectly references the SDL.DLL. The MonoGame team is aware of the issue and no doubt it will be resolved shortly. For now, you can simply remove the SD.dll.

As with any simple conversion project like this with MonoGame, getting started is easy, just copy over all the class files to your new project (except for the Game class, always best to port that manually, just in case), then copy over all the content from the original project in to the Content Project solution and you should have something now looking like this:


(*Note: Don’t forget to update the namespace in the copied files.)

All that’s left is to copy over all the Game Class code:

  • Class properties
  • Constructor code
  • Content loading in "LoadContent"
  • Game Update method
  • Game Draw method
  • And any additional helper classes / functions

All in all, it took me all of 3 minutes to get it copied across to the new solution, all that’s left is to build and link the content files and you are ready to go, well almost.

Final Steps

To finish things off, you just need to link the content to your project and sort out any incompatibilities, likely both are only minor tweaks.

For Content, I prefer to just "Link" the compiled filed from the content project but of course you can just copy the content files over to the build directory or setup a Build time task to copy them across, all methods have been mentioned before when I went through MonoGame, if you need to look back, check here.

For now, just right click on the folder named "Content" and select "Add –> Existing Item", browse to the build folder for the content project (note the Builder Project not the content project itself) but instead of just clicking on "Add", hit the down arrow next to the button and select "Link Files".

Once you have linked the files, make sure you also:

  • Change the "Build Action" of the .XNB files to "Content"
  • And the "Copy to Output Directory" option to "Copy if newer"



If you cannot see the build files, ensure you have:

  • Clicked on the Content or Content builder project and selected the correct "Solution Configuration" in the  drop down, in this case "Windows"
  • Build the content project builder project by right clicking on it and selection "Build"
  • Selected "All Files" in the file browser, else you’ll see nothing Open-mouthed smile

As for fixes, in this case, I found only one in the Windows project which was to do with the RenderTargets used for the Lightning Text renderer, use a mode that is not implemented in MonoGame for Windows (strangely enough, the mode is supported in Windows 8, odd, but more on that later), to fix this, just change the following lines from:

lastFrame = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y, false, 
            SurfaceFormat.HdrBlendable, DepthFormat.None);
currentFrame = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y, false, 
               SurfaceFormat.HdrBlendable, DepthFormat.None);

And replace it with:

lastFrame = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y, false, 
            SurfaceFormat.Color, DepthFormat.None);
currentFrame = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y, false, 
               SurfaceFormat.Color, DepthFormat.None);

All that has changed is the "SurfaceFormat" used to prepare the render target for use from "HdrRenderable" (a High def format) with "Color" (a more basic variant).

Now fire it up and you’ll get the same experience as you saw in the previous demos, but now running smoothly in MonoGame:


To Be Continued

So that’s the first stage of many, sure it’s working in MonoGame but we can do better than that, first let's add a bit more and then go fully Multi-Platform.


The source for the series can be found here on codeplex as well as the code drop for this stage here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Simon Jackson
Architect ZenithMoon Studios
United Kingdom United Kingdom
Long time game developer / IT maniac.
By day working as a lowly Technical Architect for a healthcare software firm, by night Masquerading as the Master Chief of ZenithMoon Studios.

At heart I'm a community developer breaking down lots of fun and curious technologies and bringing them to the masses.

I'm also a contributor to several open source projects, most notably the AdRotator advertising rotator project for Windows and Windows Phone.

After a hefty break with Windows Phone and Windows 8 I'm heading back to my XNA roots to show how beginners and current XNA devs can take their skills forward with XNA's bleak future.

ID&Xbox MVP & Best selling author
[Mastering Unity 2D Game Development] (
[Unity 3D UI Essentials] (

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Max_Power_Up11-Feb-13 23:55
memberMax_Power_Up11-Feb-13 23:55 
GeneralRe: My vote of 5 Pin
Simon Jackson12-Feb-13 13:04
memberSimon Jackson12-Feb-13 13:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180417.1 | Last Updated 7 Feb 2013
Article Copyright 2013 by Simon Jackson
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid