|Home About Us Services Clients Resources Blog Careers Orderbox™||contact us Site map links|
Managed DirectX via IronPython Part 1 - referencing the MDX 1.1 assemblies
UPDATE 2: If you have only installed the DirectX 9.0c runtime and not the SDK, or have installed from a recent SDK, there's a good chance that MDX 2.0 will no longer have been installed on your system. This means you don't have to worry about inadvertently loading these obsolete, disabled libraries. The following simpler method of loading will suffice:
clr.AddReference("Microsoft.DirectX") clr.AddReference("Microsoft.DirectX.Direct3D") clr.AddReference("Microsoft.DirectX.Direct3DX")
UPDATE: Almost immediately after writing this article, I realized I could use the following, shorter way to specifically import the MDX 1.1 assemblies even if the MDX 2.0 assembly was around. This article is still retained for the background information it gives.
>>> clr.AddReferenceByName( "Microsoft.DirectX, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ) >>> clr.AddReferenceByName( "Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" )
Gaining access to 3d hardware acceleration via DirectX under the programming language Python has long been a dream of mine. In theory, this should have been possible via COM using pythonwin but I never got around to figuring out how to do that. With the advent of IronPython v1.x and Managed DirectX, however, this is now a working reality!
DirectX is notorious for horribly verbose setup code that requires endless hours just to figure how it works even for a task as simple as creating a featureless window. Such frustrations are compounded by API and DLL version-related errors that seem to be a constant nuisance when developing for DirectX (and most other MS APIs in fact).
Well it seems that those bad old days are over. IronPython's very high level nature is perfect for taming DirectX's verbosity, while this article hopes to help you overcome the second problem.
Most of the Managed DirectX tutorials you will currently find on the web use Managed DirectX 2.0 (MDX 2.0). Unfortunately, none of these will run anymore as MS deliberately put a time bomb in the MDX 2.0 DLL causing it to stop working as of October 2006. The recommendation is to move on to XNA, but after a brief and extremely annoying experience trying to load in textures using the APIs in this still-in-beta and confusing, overengineered SDK, I quickly realized that I was being used as an unwitting guinea pig for MS' API experiments and thus decided to go instead with the well-supported and stabilized MDX 1.1 API.
The first thing you need to do is to correctly reference the MDX 1.1 assemblies. If the MDX 2.0 assembly is present in your system* - which I believe would be the case if you installed the .NET Framework 2.0 runtime - IronPython will default to using this DLL as it is more version-synchronized with it.
*e.g. if you see a Microsoft.DirectX.dll file under a 184.108.40.206*\ directory somewhere under \Windows\assembly, \Windows\Microsoft.NET or if the Administrative Tools\Microsoft .NET Framework 2.0 Configuration tool indicates its presence
The simplest route, would be of course
to remove this dead DLL via
import clr clr.AddReference("System") clr.AddReference("System.Drawing") clr.AddReference("System.Windows.Forms") from System.Reflection import Assembly clr.AddReference( Assembly.LoadFrom( "C:\\WINDOWS\\Microsoft.Net\\DirectX for Managed Code\\" "1.0.2902.0\\Microsoft.DirectX.Direct3D.dll")) clr.AddReference( Assembly.LoadFrom( "C:\\WINDOWS\\Microsoft.Net\\DirectX for Managed Code\\" "1.0.2902.0\\Microsoft.DirectX.dll"))
Due to the constant shuffle of SDKs and runtimes in my machine and possibly imperfect removals of such, I am no longer sure which SDK or runtime installed the 1.0.2902.0 (e.g. MDX 1.1) DLLs but if you don't have these, I believe almost all recent DirectX SDKs including the newest as of this writing, October 2006, will install this. The older SDKs might put the MDX 1.1 assemblies in a different location though.
Once you get this set up correctly, you are ready to begin learning Managed DirectX programming in IronPython using MDX 1.1.
© 2014 by Andy Sy
Web Development / Rich Internet Applications (RIA) Development
|© 2003-2014 Neotitans Technologies Inc.||contact/hire us|