Chapter 23. Three-Dimensional Drawing

WPF relies on Microsoft's DirectX technologies for high-quality multimedia support. The DirectX libraries include methods to display images, present video, and play audio files that take advantage of the computer's hardware to provide the best performance and highest quality possible.

One of my favorite parts of DirectX is Direct3D, the three-dimensional (3D) drawing library. Direct3D lets a program display complex animated 3D scenes with multiple light sources, smooth color shading, and realistic textures — all in real time.

The TexturedBlock example program shown in Figure 23-1 displays a simple cube with sides made of various materials sitting on a brick and grass surface. You can use the sliders to rotate the scene in real time.

Figure 23-1

Figure 23.1. Figure 23-1

Unfortunately, writing Direct3D code to display these types of objects is fairly involved. One of the first and most annoying tasks is figuring out what graphics hardware is available on the user's computer. Determining which device objects you need to get the most out of the user's computer can be confusing.

Fortunately, WPF's 3D drawing objects handle this setup for you. Although they don't always give you quite the same performance you could achieve using Direct3D yourself, it's a lot easier to get a program up and running in WPF.

That doesn't mean that the rest of the process is easy. Producing ...

Get WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.