views:

354

answers:

3

I have a small 2D game engine written in C#, using DirectX. Is it possible to somehow run it in a browser as a plugin? Like for example Flash and others, where you go to a site with a game and it will ask you to install a certain plugin and then you can play the game in the browser, with mouse and keyboard input. I have searched around for hours and I still don't know what I'm looking for. I have so far primarily focused on Internet Explorer, but there are plugins, addons, extensions, etc I don't know what I need really.

+2  A: 

Look for Silverlight.. It is maybe not exactly what you need but it is a browser plugin capable of running C# code ;)

Thomas Wanner
except no DirectX for silverlight, right
qntmfred
I began my search by looking at Silverlight and it seemed really promising until I saw that it has no hardware accelerated graphics, which I require.
Decept
That's what I meant by not being exactly what you need :( If you already have a large code base and rewriting it is not an option then you probably need to look for other options as ActiveX plugins for IE etc.
Thomas Wanner
+3  A: 

Yes I think it is possible.

For example, I have an HTML page which includes an element like this:

<object id="simpleControl1"
classid="http:RenderTextProject5.dll#RenderTextProject.ScrollableControl"
height="300"
width="300">
</object>

The 'classid' attribute value has the following meaning/syntax:

  • RenderTextProject5.dll is the filename of a compiled .NET assembly
  • RenderTextProject.ScrollableControl is the qualified name (namespace plus classname) of a class which subclasses System.Windows.Forms.Control

I can then see the control being rendered in the browser.

I'm using IE (IE8, but it used to work with IE6 too), and I have the .NET framework installed on my machine (but I think I needn't have the RenderTextProject5 assembly installed on the client machine).

There may be some other caveats too (e.g. I needed to run in the Intranet security zone).

See Return of the Rich Client: Code Access Security and Distribution Features in .NET Enhance Client-Side Apps.

ChrisW
That looks really interresting, I tried a simple example based on what I read from the link you posted, but I can't get a simple control to show up in the browser.
Decept
I was finally able to show my control by adding my site to the trusted site list. I'm having a hard time testing stuff though, as everytime I have to clear the assembly download cache, which doesn't always work.I still haven't been able to enable DirectX inside if the usercontrol
Decept
"as everytime I have to clear the assembly download cache" - try renaming the DLL each time you want a new one ... note that my example says "RenderTextProject5.dll", because I guess that's the 5th of the versions I'd tried.
ChrisW
I'm having problems using an object (derived from usercontrol) from the dll. Whenever I try to call a function on the object from JavaScript I get error on page when loading it in IE8.
Decept
It's been years since I read about this feature and I've never tried calling it from JavaScript; but I think I remember that JavaScript ought at least to be able to read and write public properties of the object: maybe try a property instead of or as well as a method.
ChrisW
I tried properties aswell with no luck. I tried creating a simple control that I could show debug messages inside, so that I could debug my D3D efforts, but nothing happens when I call it.I have also made a usercontrol that starts a small 3D scene. I tried it by creating a new WinForm app and added the usercontrol and it works immediately. But when I add the usercontrol to html using the object tag, I get an empty area with a small icon in the top left corner. Like it wasn't able to load. But I don't know how to debug this at all.
Decept
@Decept See [Windows Forms Controls in IE Troubleshooting Guide](http://blog.jonschneider.com/2007_04_01_archive.html) for how to debug load errors. Mine is loading as shown at http://www.modeltext.com/html/demonstration.aspx
ChrisW
A: 

There is a relatively new plugin called Unity. It is a bit more complex, as it is a dev/3D authoring environment on its own, but uses C# as its language as far as I know. However I don't know if pure 2D programming is possible (well, may be worked around using ortho 3d?).

The basic version is free to download recently, maybe worth a check.

ron