You can use a DirectDraw surface as a texture map by calling the IDirectDrawSurface::QueryInterface method to retrieve an IDirect3DTexture2 interface. You can use the IDirect3DTexture2 interface to load textures, retrieve handles, and track changes to palettes.
IDirect3D2 and its DirectX 3 counterpart, IDirect3DTexture, can be associated with a 3-D device. A texture handle identifies this coupling of a texture map with a device. A texture can be associated with more than one device. When you call the IDirect3DTexture2::GetHandle method to associate a texture with a device, it is validated to ensure that the device can support the specified type of texture format and dimensions. The GetHandle method returns the texture handle if this validation succeeds. Texture handles can then be used as render states and in materials (for ramp mode) in either IDirect3DDevice2 or IDirect3DDevice. Because a handle obtained by associating a texture object with a device object does not depend on which interfaces were used to obtain it, handles obtained using IDirect3DTexture or IDirect3DTexture2 for a given device object can be used interchangeably.
The IDirect3DTexture2 interface eliminates some unimplemented methods from the IDirect3DTexture interface.
The following example demonstrates how to create an IDirect3DTexture2 interface and then how to load the texture by calling the IDirect3DTexture2::GetHandle and IDirect3DTexture2::Load methods. Note that the DirectDraw surface you query must have the DDSCAPS_TEXTURE capability to support a Direct3D texture.
lpDDS->QueryInterface(IID_IDirect3DTexture2,
lpD3DTexture2); // Address of a DIRECT3DTEXTURE object
lpD3DTexture2->GetHandle(
lpD3DDevice, // Address of a DIRECT3DDEVICE object
lphTexture); // Address of a D3DTEXTUREHANDLE
lpD3DTexture2->Load(
lpD3DTexture); // Address of a DIRECT3DTEXTURE object
To use a texture handle in an execute buffer, use the D3DRENDERSTATE_TEXTUREHANDLE render state (part of the D3DRENDERSTATETYPE enumerated type).