Wednesday, 29 November 2006

Graphics with .NET

I've spent the past couple of weeks developing graphical demos using F# and .NET. My previous blogs mention the ray tracer and spinning teapot Direct X demo.

Under .NET, developers are spoiled for choice when it comes to graphics. You can use WinForms and bitmaps, as I did for the ray tracer. There's managed DirectX, which I used for the teapot. More recently, Microsoft have create XNA and WPF.

However, none of these systems are as easy to use from languages like C# and F# as competing systems, such as OCaml and OpenGL. In my book "OCaml for Scientists" I introduce OpenGL visualisation with a 6-line program that reliably displays a blank window. That takes over 80 lines of code with managed Direct X because you must limit the minimum size of the Direct X widget or it will crash and you must handle device losses and resets yourself. To make matters harder, it is almost impossible to find accurate information on how this is accomplished.

I appreciate that this is boiler-plate code, you get it working once and then cut and paste it into every one of your programs but it is too much to expect users to write those 80 lines of code everytime they want to see a triangle.

In Mathematica, for example, you can write a single line of code to get a 3D surface plot that you can then export as a PostScript or PDF file:

Plot3D[Sin[x^2+y^2], {x, -3, 3}, {y, -3, 3}]

I want to be able to do this from F#, 100x faster and with .NET interoperability.

So I set about writing a library to make it as easy as possible to do real-time, interactive, 2D and 3D visualisation from F#. The foundation comes from the code base of our presentation software Presenta:

In addition to compiling and running programs to create visualisations, you can now slice and dice your data in the F# interactive mode and have it throw up windows visualising your data as you go. You can even control the contents of the windows after they've been created!

Needless to say, I'll be commercialising this as soon as its done. One thing is ringing true though - F# is the next stage in the evolution of programming languages!


1 comment:

alpa said...
This comment has been removed by a blog administrator.