This is a mirror of official site: http://jasper-net.blogspot.com/

Managed DirectX via F#

| Monday, October 25, 2010
Referencing DirectX Libraries in an F# Application

Despite the fact that WPF has a more powerful graphics engine that Windows Forms, developing commercial game software is accomplished via DirectX or, in some cases, the OpenGL. Microsoft provides a high-level interface to DirectX from the .NET Framework: Managed DirectX. Even though this a high-level interfaces, programs using Managed DirectX contain a significant amount of "boiler plate" code that is required to get anything working. This article will focus on writing F# code to draw from that Managed DirectX reusable libraries. When using Visual Studio, F# code is normally tested by highlighting that code to the press Alt-Enter to send the code into the F# interactive. The directory that contains these DLLs is C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0. Therefore if we use F#, a functional programming language that is said to have significant future, we could load the libraries to an include by doing this :

#I @"C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0"
#I @"C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2903.0"
#I @"C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2904.0"
#I @"C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2907.0"
Those lines specify the include path and are the equivalent of the -I switch to the F# compiler. Now having specified those paths, we would then reference the appropriate DLLs:

#r @"Microsoft.DirectX.dll"
#r @"Microsoft.DirectX.Direct3D.dll"
#r @"Microsoft.DirectX.Direct3Dx.dll"
Those specify the DLL reference, the equivalent to the -r command line option. As with any Visual Studio managed code solution container, we would also right-click the references, browse to the folder containing those DLLs, and add them to the references section. The program we are going to examine is user interactive, having mouse-clicks perform some basic adjustments in the position of the graphical display. This collection of shapes will work to exhibit motion depicts animation, but is normally not documented that way. But how to managed source code files to execute the F# file that contains the above specification for referencing the DLLs? We use the load command:

#load @"BindAsLegacyV2Runtime.fs"
#load @"dxlib.fs"
These two files are contained in the solution to load into the interactive upon executing the Script.fsx file. Normally it would not sense to highlight lines or blocks one at a time in order to build an executable, but doing this results in a remarkable graphics display DirectX style.

This sample contains a script that begins by guiding the user through setting up a DirectX enabled window suitable for rendering 3D functions. Then the user is shown how to plot and animate several functions of varying complexity. Finally, physics routines are provided that allow the user to simulate objects sliding around the surface of the plotted curves. Some helpful utility functions that help setup the window, perform some of the matrix calculations, and handle vertex coloring are provided in a module outside of the script file.

Read more: Codeproject

Posted via email from .NET Info

2 comments:

Anonymous said...

Please let me know if you're looking for a author for your site. You have some really great articles and I feel I would be a good asset. If you ever want to take some of the load off, I'd absolutely love to write some content for your
blog in exchange for a link back to mine. Please blast me an e-mail if interested.
Thank you!

my site; VC components

Anonymous said...

Great goods from you, man. I have be aware your stuff previous to
and you are just too wonderful. I actually like what you have got here,
certainly like what you're stating and the way in which you say it. You are making it entertaining and you continue to care for to stay it smart. I can not wait to read far more from you. This is actually a tremendous website.

My web page: trans Resveratrol supplements