Microsoft DirectX 9.0

Moire Sample


The Moire sample shows how to use the Microsoft?Direct3D® software development kit (SDK) screen saver framework to write a screen saver that uses Direct3D. The screen saver framework is similar to the sample application framework, using many methods and variables with the same names. After writing a program with the screen saver framework, you end up with a fully-functional Microsoft Windows?screen saver, rather than with a regular Windows application.

The moire screen saver appears as a mesmerizing sequence of spinning lines and colors. It uses texture transformation and alpha blending to create a highly animated scene, even though the polygons that make up the scene do not move at all.


Source: (SDK root)\Samples\C++\Direct3D\ScreenSavers\Moire

Executable: (SDK root)\Samples\C++\Direct3D\Bin

User's Guide

Moire.scr can be started in five modes: configuration, preview, full, test, and password change. You can choose some modes by clicking the right mouse button (right-click) on the Moire.scr file and choosing Configure or Preview. Or you can start Moire.scr from the command line with the following command-line parameters:
-cConfiguration mode
-tTest mode
-pPreview mode
-aPassword-change mode
-sFull mode

When the screen saver is running in full mode, press any key or move the mouse to exit.

Programming Notes

Programs that use the screen saver framework are very similar to programs that use the Direct3D sample application framework. Each screen saver needs to create a class derived from the main application class, CD3DScreensaver. To provide functionality specific to each screen saver, the screen saver implements its own versions of the virtual functions FrameMove, Render, InitDeviceObjects, and so forth.

Screen savers can be written to be multimonitor-compatible, without much extra effort. If you do not want your screen saver to run on multiple monitors, you can just set the m_bOneScreenOnly variable to TRUE. This value is set to FALSE by default. The function SetDevice will be called each time the device changes. The way that moire deals with this is to create a structure called DeviceObjects, which contains all device-specific pointers and values. CMoireScreensaver holds an array of DeviceObjects structures, called m_DeviceObjectsArray. When SetDevice is called, m_pDeviceObjects is changed to point to the DeviceObjects structure for the specified device. When rendering, m_rcRenderTotal refers to the rendering area that spans all monitors, and m_rcRenderCurDevice refers to the rendering area for the current device's monitor. The function SetProjectionMatrix shows one way to set up a projection matrix that makes proper use of these variables to either render a scene that spans all the monitors, or display a copy of the scene on each monitor. The projection matrix used depends on the value of m_bAllScreensSame, which you can enable the user to control in the configuration dialog.

The ReadSettings function is called by the screen saver framework at program startup time, to read various screen saver settings from the registry. DoConfig is called when the user wants to configure the screen saver settings. The program should respond to this by creating a dialog box with controls for the various screen saver settings. This dialog box should also have a button called Display Settings which, when pressed, should call DoScreenSettingsDialog. This common dialog box allows the user to configure what renderer and display mode should be used on each monitor. You should set the member variable m_strRegPath to a registry path that will hold the screen saver's settings. You can use this variable in your registry read/write functions. The screen saver framework will also use this variable to store information about the default display mode in some cases.

This sample uses common Microsoft DirectX?code that consists of programming elements such as helper functions. This code is shared with other samples in the DirectX SDK. You can find the sample framework headers and source code in (SDK root)\DXSDK\Samples\C++\Common\Include and (SDK root)\DXSDK\Samples\C++\Common\Src.

© 2002 Microsoft Corporation. All rights reserved.