Tuesday, 3 July 2012

Generic XNA - Movies in your Windows games


Well, I started looking into this after a friend of mine asked if it could be done. I remembered the other week on Ziggyware that someone got a web cam to stream in an XNA app and so thought that the principle should be the same, taking the output, rendering it as a texture then applying it as you required. So started to try and do it myself, well I came a cropper as the examples I came across were for the old MDX and not XNA (I am not bright enough to do a full port), having to use unsafe code to get handles to the Game.Graphics device etc... but then I came across this post on codeplex as well as a few others which gives a class in XNA to do just this usingDirectShow. Now all the examples I found seem to have originated from this post on CodeProject, as does the class I am using here.

Now you may be wondering, where is the movie clip for this....well fraps does not seem to play well with the method I am using to do this and so does not generate a nice clip for me to put up, wish it did because I think it's pretty cool.

Anyway, all I have done is got this lovely class's output image on a 3D surface. This means you can have movies playing in your games in a virtual cinema, have adverts playing on an advertising billboard as you race past in your racer game, have a television like in GTA IV (I love the cartoons!)

Clip of the Web Cam in XNA done by MirageProject on YouTube, this gives you an idea of what my implementation looks like, but instead of giving it a device to read from you give it a *.wmv, *.mpg or any other supported format. Also, notice in my image above that the clip on the left is in black and white, this is down to the shader effect applied, not the clip.


You can get the solution zip here. (You have to supply your own clips or the zip would have been huge!!)

No comments:

Post a Comment