Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


Direct3DRM: The Master Interface

As I mentioned earlier, Direct3D is a collection of COM interfaces. All the various interfaces that make up Direct3D depend on a single master object: Direct3DRM (RM stands for Retained-Mode). The Direct3DRM object represents Direct3D itself. The interface is created with the Direct3DRMCreate() function. For example:

LPDIRECT3DRM d3drm;
Direct3DRMCreate( &d3drm );

The LPDIRECT3DRM type is a pointer to a Direct3DRM interface. The Direct3DRMCreate() function creates the object and initializes the interface pointer. Once the Direct3DRMCreate() function returns successfully (we’ll talk about return codes later in this chapter), the Direct3DRM interface is ready to use.

Creating Direct3D Objects

The primary purpose of the Direct3DRM interface is the creation of other Direct3D objects. Most of the Direct3DRM member functions have “Create” prefixes. The object creation member functions are:

  CreateAnimation()
  CreateAnimationSet()
  CreateDeviceFromClipper()
  CreateDeviceFromD3D()
  CreateDeviceFromSurface()
  CreateFace()
  CreateFrame()
  CreateLight()
  CreateLightRGB()
  CreateMaterial()
  CreateMesh()
  CreateMeshBuilder()
  CreateObject()
  CreateUserVisual()
  CreateShadow()
  CreateTexture()
  CreateTextureFromSurface()
  LoadTexture()
  CreateViewport()
  CreateWrap()

It is certainly not necessary to use all of these functions. Some are virtually identical to each other. For example, the only difference between the CreateLight() and CreateLightRGB() member functions is how the color of the light source is specified.

Because the Direct3DRM interface is needed in order to create other Direct3D objects, Direct3DRM is usually the first object that a program creates.

Modifying The Search Path

Another role of the Direct3DRM interface is to allow you to modify the search path that Direct3D uses to look for files. The path can be examined and modified with these member functions:

  AddSearchPath()
  GetSearchPath()
  SetSearchPath()

By default, Direct3D installs c:\dxsdk\sdk\media as the search path. You can override or append this path using the search path member functions, but the changes that your program makes will take effect only during the course of your program’s execution. This path will not be installed on an end user’s machine, so your programs should not rely on its existence.


Tip:  Changing the default search path
The default search path is stored in the Windows registry and can be changed using REGEDIT, the Windows 95 registry editor. You can find the search path entry by searching for the “D3D Path” entry.

Controlling The Update Pace

Finally, the Direct3DRM object defines a Tick() member function. Tick() controls the rate at which a program runs. Each time the Tick() function is called, Direct3D updates animated elements in a scene and renders the results. Calling Tick() often updates the scene often; calling Tick() infrequently slows the program. In addition, the Tick() member function takes a single parameter that controls the animation rate within a scene. For most situations, using a value of 1.0 is desirable, but a program’s pace can be fine-tuned at runtime by using different values.

Direct3DRMDevice: The Device Interface

Direct3D devices are objects that create rendered output. Direct3D supports a number of device types. Programs can either choose a device from a list of available devices, or instruct Direct3D to select a device automatically. The two main types of devices are software devices and hardware devices. Software devices allow programs to run on computers that are not equipped with 3D accelerated video hardware. Hardware devices are available only on computers with 3D hardware and allow Direct3D to make full use of the features that are present on the hardware.

A device is represented with the Direct3DRMDevice interface and can be created using the Direct3DRM member functions. There are three ways to create a device:

1.  Create a DirectDraw “clipper” object, and then create the device with the CreateDeviceFromClipper() member function. This is the simplest and most reliable method to create a device.
2.  Create a DirectDraw primary surface with a back-buffer (to allow page-flipping), and create the device with the CreateDeviceFromSurface() member function. This method is used to initialize Direct3D applications that will be running in full-screen mode.
3.  Initialize Direct3D Immediate Mode, and create a device with the CreateDeviceFromD3D() member function.

Once a device has been created it is used to specify rendering settings and perform the rendering of scenes.

Color Models

Both software and hardware devices come in two varieties: RGB and Ramp. The RGB color model supports colored lighting, while the Ramp color model does not. Reduced overhead allows Ramp devices to out-perform RGB devices. Ramp devices are also called “mono” devices because of their monochromatic treatment of light sources. This can be misleading, however, since only the light sources are monochromatic in Ramp mode. Meshes and faces enjoy full color capability in Ramp mode.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.