Utah Code Camp: September 19th, 2009

I’ll be talking about Direct2D, DirectWrite and WiX at the Fall 2009 Utah Code Camp on September 19th at Neumont University.

Read the rest of this entry »

Direct3D Programming Tip #8: Use Find in Files To Locate API Call Examples

The Direct3D API covers quite a bit of ground, particularly if you include D3DX. A question that arises fairly often in discussion forums is “where can I find an example of xxx?” for some particular API function or method named xxx.

Read the rest of this entry »

SlimDX Presentation on August 13th, 2009

I’ll be presenting a talk on SlimDX at the Utah .NET User Group meeting for August, 2009.

The Utah .Net User Group meets the 2nd Thursday of every month at 6:00 PM. Meetings are held at Neumont University in the South Jordan area about 20 minutes from downtown Salt Lake City. If you are traveling on I-15: exit on 106th south, head west, and they are right on the left hand side of the road in the grey 4-story buildings right there on the 3rd floor.

Utah .NET User Group meetings are free and open to everyone. Pizza and soda is usually provided free!

Description Helpers For Direct3D 10, 10.1 and 11

In Direct3D 10, a number of device render states were aggregated into immutable objects. These immutable objects simplify state management on the device for the runtime and the driver, making it quicker to switch between state configurations on the device. These immutable state objects are created by filling in a description structure and creating the object. This mechanism is present in Direct3D 10.1 and Direct3D 11 as well. In this post, I will discuss some helper classes for constructing these state objects in a manner that more clearly reveals your intention.

Read the rest of this entry »

Direct3D Programming Tip #7: Use Smart Resource Locks

In Direct3D9, direct CPU access to a resource is obtained by obtaining a lock on the resource. Every time you obtain the lock, you must make sure that you release it. In Direct3D10 and Direct3D11, a similar situation is faced with resources, but the terminology has changed to mapping the resource. Using a helper class to handle the lock and unlock operations on a resource helps you create exception safe code in C++.

Read the rest of this entry »

Direct3D Programming Tip #6: Link Against The Debug D3DX

Just as important as using the Direct3D debug runtime is using the debug D3DX library. D3DX is provided as a DLL library and like the runtime it is provided in two versions: release and debug builds.

Read the rest of this entry »

Direct3D Programming Tip #5: Use The Debug Runtime

Direct3D is a large API that reflects the complex nature of 3D graphics rendering and the complexities of modern video cards.  As one of my peers puts it:

The hard part about computer graphics is that there are too many ways to draw a black screen. — Russ Fish

Read the rest of this entry »

Direct3D Programming Tip #4: Check All HRESULTs

Checking for errors is a good programming habit, but new programmers haven’t yet learned this habit. Most of the methods and functions you can call in Direct3D return an HRESULT, or a COM “handle to a result”, that indicates success or failure. Most of the time, your expectation is that these calls should succeed. This leads people to write “happy path” code that assumes that the call will succeed instead of verifying that it succeeded.

Read the rest of this entry »

Direct3D Programming Tip #3: Use Smart Pointers

Direct3D exposes functionality through COM interface pointers. Managing the reference counts on the obtained interfaces is a common problem for new Direct3D programmers. Managing the reference count on an interface becomes trivial if you use a smart pointer wrapper class, such as CComPtr<T> or boost::shared_ptr<T> and keep in mind the ownership policies established by the smart pointer class.

In addition to managing reference counts for you, smart pointers can make your code exception safe. When an exception is thrown, if an interface pointer is held within a CComPtr declared on the stack, then its destructor will be run when the stack is unwound. The destructor for CComPtr will call IUnknown::Release on any interface pointer it holds, thus cleaning up any locally obtained resources as the exception unwinds the stack to the nearest exception handler.

Read the rest of this entry »

Direct3D Programming Tip #2: Use the Documentation

This is a programming tip? Well yeah, I’m sorry to report that often times its obvious from the questions people post that they either don’t know the documentation exists or they don’t use it. Personally, I don’t know how they can get anything done without the documentation. 3D graphics is hard! I put the shortcut to the documentation in my Quick Launch toolbar on the task bar:

  1. Click Start / Programs… and find the entry for the DirectX SDK.
  2. With the cursor over the DirectX SDK entry, right click to display the context menu and select Open
  3. While holding the Ctrl key, drag and drop the shortcut for the DirectX Documentation on the Quick Launch toolbar. A plus (+) sign should appear as you drop the shortcut to let you know that you’re making a copy of the shortcut and not moving it.

OK, now you’ve got the documentation at your fingertips ready to consult at any time. When I’m writing code that is talking directly to Direct3D interfaces, I usually leave the help browser open and just minimize it when I’m not using it. That way its only a quick Alt+TAB away while I’m coding.

Read the rest of this entry »

White Paper about D3D WARP 10

Andy Glaister at Microsoft has written a white paper about the Windows Advanced Rasterization Platform (WARP). For those of you interested in this new feature that appeared in the November 2008 DirectX SDK, check out this white paper as it is not included in the SDK.

Direct3D Programming Tip #1: Getting Started

Inspired by Sara Ford’s Visual Studio Tips, I thought I would start writing a series of tips for Direct3D programmers. I doubt I will be able to be as prolific as Sara, with a new tip each and every single day.

So where do we start? Let’s start with the very basics for a native Direct3D programmer. You will need:

  • A C++ development environment.
  • A DirectX SDK.
  • A version control system.

Once you have these in place, you’re ready to get started writing your own Direct3D programs.

Read the rest of this entry »

November 2008 DirectX SDK

The November 2008 DirectX SDK is available for download.

Direct3D 11 Preview @ Utah Code Camp

I gave a talk at the Fall 2008 Utah Code Camp going over the information that’s been publicly released about Direct3D 11. Direct3D 11 will be first available in the November 2008 DirectX SDK. When that is released, I’ll be able to talk more about the features in Direct3D 11.

For now, you can look at the slides for my code camp talk, which are mostly cribbed from presentations at GameFest 2008. (Again, not all the details of Direct3D 11 have been made public yet.)

August 2008 DirectX SDK available

The August 2008 release of the DirectX SDK is now available for download. (Actually, it has been available for a while if you snoop the downloads area frequently.) Don’t forget to check the release notes for a list of known issues. New features of this release:

  • A much improved PIX for Windows with some excellent new timing features
  • Games for Windows branding tool for testing against many of the Games for Windows Technical Requirements
  • Two new Direct3D 10 samples: DepthOfField10.1 and RaycastTerrain

The next release of the DirectX SDK is scheduled for November 2008.

Direct3D Graphics Pipeline Sample Code Installer Bug Found

OK, I was finally able to reproduce this problem with the installer and the issue comes down to something downright weird. If I’m running dbmon or DebugView while the installer is running, then the code installs fine. If I’m not running a debug monitor, then the installation fails with no useful information in the log message (other than the custom action return code is 3, which indicates an error).

So now that I’ve found the bug, I’ll investigate getting an updated installer uploaded that corrects the problem.

Writing Unit Tests Against Direct3D

Writing a unit test involves holding the “system under test” in a software vise and controlling all the other interactions of the system under test with the rest of the system. In an object-oriented programming language, the easiest way to control the interactions of your system under test with the rest of the universe is to interact with the universe through polymorphic interfaces. Because your system under test is collaborating with the universe through interfaces, it is not coupled to other concrete classes in your application. To unit test the system and its interactions, you provide “fake” or “mock” objects implementing the interfaces of the system’s collaborators. The system under test has no idea its collaborating with fake objects because it is coupled to an interface, not a concrete class.

Read the rest of this entry »

Direct3D Graphics Pipeline Update

Its been quite a while since I uploaded a new version of the draft of my book. Rest assured, I’m still working on the book and I really do plan on finishing it someday! However, I’ve gotten some feedback that the installer for the samples will sometimes fail. Since I haven’t gotten any detailed log files back from anyone who experienced the failure, I’ve been trying to figure out how to diagnose the problem and correct it. The samples also needed updating to Visual Studio .NET 2005 — and I guess now they’ll need updating to Visual Studio .NET 2008! So I’ve been working on my installer code by fitting unit tests to the code in an attempt to find the underlying problem that people have reported. My manual testing with old versions of Windows (that need updating of their DirectX runtime) with VMWare haven’t reproduced the problem that people have described, so I’m hoping that fitting everything in the installer with unit tests will help me identify the problem. I’ll also be converting the installer for the sample code to use WiX (Windows Installer XML) instead of the deployment project type in Visual Studio. This will make the installer more robust and will eliminate the script hackiness I had to do in my white paper. It will also make the installer source accessible to people who don’t have the Professional edition of Visual Studio since it will use only free tools. Once all the samples and source have been appropriately updated, I’ll go back to incorporating 9.0c changes into my manuscript.