Game Development Reference
In-Depth Information
Since most of the necessary grunt work is done in the effect file, such
as setting lights, materials, and textures, the application code is simply
a matter of creating the effect and enabling it. The sample has the fol-
lowing relevant global variables:
ID3DXEffect* LightTexEffect = 0;
D3DXHANDLE WorldMatrixHandle = 0;
D3DXHANDLE ViewMatrixHandle
= 0;
D3DXHANDLE ProjMatrixHandle
= 0;
D3DXHANDLE TexHandle
= 0;
D3DXHANDLE LightTexTechHandle = 0;
This is nothing interesting—just an ID3DXEffect pointer and some
handles. The LightTexTechHandle is a handle to a technique, hence
the substring “Tech” in its name.
The Setup function performs three primary steps: creates the
effect, obtains handles to effect parameters and to the technique we are
going to use, and initializes some of the effect parameters. Its abridged
implementation is as follows:
bool Setup()
{
HRESULT hr = 0;
//
// ...[Load XFile Snipped]
//
//
// Create effect.
//
ID3DXBuffer* errorBuffer = 0;
hr = D3DXCreateEffectFromFile(
Device, // associated device
"light_tex.txt", // effect filename
0, // no preprocessor definitions
0, // no ID3DXInclude interface
D3DXSHADER_DEBUG, // compile flags
0, // don't share parameters
&LightTexEffect, // return effect interface pointer
&errorBuffer);
// return error messages
// output any error messages
if( errorBuffer )
{
::MessageBox(0, (char*)errorBuffer->GetBufferPointer(), 0, 0);
d3d::Release<ID3DXBuffer*>(errorBuffer);
}
if(FAILED(hr))
{
Search WWH ::




Custom Search