Web Hosting Philippines, Offshore Programming, Offshore SEO Philippines, Cheap Webhosting Manila Philippines
Home -> Resources -> .NET -> Managed DirectX via IronPython Tutorial - Part 1

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:

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*\ 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 gacutil or the .NET Framework 2.0 Configuration Tool and IronPython would automatically fall back to using the older MDX 1.1 DLLs. But, as is familiar to anyone who has dealt with MS technologies by now, in their typical Dilbert, perverse fashion, they put in your system and made non-removable, (short of a full .NET Framework 2.0 uninstall), a beta DLL which they knew would disable itself someday and cause all sorts of confusion and wasted time, sigh..... Thus, you need all the gunk below to point IronPython to the older, working version 1.1 DLL. ( For clarity, I should also mention that in MDX 2.0, the Microsoft.DirectX.Direct3D.dll assembly was folded into Microsoft.DirectX.dll, so there is no separate 2nd assembly for Direct3D. )

import clr


from System.Reflection import Assembly

    "C:\\WINDOWS\\Microsoft.Net\\DirectX for Managed Code\\"

    "C:\\WINDOWS\\Microsoft.Net\\DirectX for Managed Code\\"
How to import the MDX 1.1 assemblies correctly for IronPython

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.

Part 2 - Interactive control of a Managed Direct3D Device

Part 3 - 2-D Alpha-blended Sprite Rendering


Back to Top

© 2014 by Andy Sy
last updated: 2006-Sep-9

Web Development / Rich Internet Applications (RIA) Development

Programming Languages


Database Development

Web Hosting Philippines, Offshore SEO, Guaranteed SEO Philippines
   © 2003-2019 Neotitans Technologies Inc.