/Silverlight-WebGL

Access web browser WebGL functionality in Silverlight with C#

Primary LanguageC#

Silverlight.WebGL

Sliverlight.WebGL is a C#/.NET wrapper for in-browser access to WebGL functionality using Silverlight 5.

Features

  • Create 3D web browser applications using Silverlight plugin on Windows and Mac OSX.
  • Easily port existing WebGL JavaScript code to Silverlight.
  • Enable C# developers to put cross platform 3D applications in a web browser.

Restrictions

  • Cannot use as a Silverlight Control and mix with other Silverlight controls.
  • Cannot hide Silverlight control, it must be visible somewhere even if only 1x1 pixels.
  • Cannot be used for out-of-browser 3D applications.
  • Cannot show file:// URL based textures in IE9 or Chrome, but Firefox works OK.

How it works

The HTML5 canvas has a WebGL context on recent releases of Firefox, Chrome and Safari, and it can be faked on Internet Explorer with a plugin. The Silverlight HTML Bridge allows typesafe wrappers to be created around this JavaScript API so your application/game loop can be written and compiled in C#/VB.NET with the 3D being fully hardware accelerated
by the WebGL support in the browser.

Here's an example WebGL called from the C# wrapper:

public void clearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
    Invoke("clearColor", red, green, blue, alpha);
}

Getting Started

  • Install the Runtime and Developer Requirements

  • Download the latest source code from Silverlight-WebGL from GitHub. On Windows I used TortoiseGit following these instuctions.

  • Open up the solution file LearningWebGL/LearningWebGL.sln in Visual Web Developer 2010 Express (it's free).

  • Press Start Debugging (F5).

  • Edit App.xaml.cs and change Lesson03 in this method to select a different lesson to view:

      private void Application_Startup(object sender, StartupEventArgs e) {
          this.RootVisual = new Canvas();
          new Lesson03() { Id = "Lesson" };
      }
    

Runtime Requirements

Developer Requirements

Licenses

  • The source code for Silverlight.WebGL is released under the MIT License.
  • The source code for the LearningWebGL samples is ported from the original JavaScript WebGL samples on the Learning WebGL website which is largely based on the Nehe OpenGL Tutorials samples.
  • The source code for GlMatrix is ported from the original JavaScript gl-matrix.js library by Brandon Jones.
  • The iPhone graphic used in the sample pages is taken from openclipart.org by Ben Bois.
  • The Silverlight.js file is the standard script from Microsoft.
  • The WebGLHelper.js file is from IEWebGL to allow loading of their plugin for internet explorer, or the built-in WebGL if it's available.

TODO:

  • Fill in missing implementations of WebGL methods.
  • Port the remaining samples from Learning WebGL.
  • Test on Mac OSX in Safari, Chrome and Firefox and add browser matrix to this README.md file.