1.1 Surfaces Package CXSurface [http://blog.9cbs.net/mythma]
1. What is Surfaces?
Popular Surfaces is a two-dimensional rectangular plane. In DX9, the COM interface corresponding to it is IDirect3dsurface9, lpdirect3dsurface9.
2, Surfaces' role:
As a rectangular plane, Surfaces is used to display a plan image on the screen, ie, read image data from the file to the user.
3, the usual process of iDirect3dsurface9:
Disclaimer: LPDIRECT3DSURFACE9
Create: createoffscreenplainsurface (...)
Get image information: d3dxgetimageInfofromfile (...)
Loaded into Surfaces: D3DXLOADSURFAMFILE (...)
Get Back Buffer Address: getBackBuffer (...)
Display: updatesurface (...)
Release memory Release ()
The code segment is as follows:
LPDIRECT3DSURFACE9 g_surface = NULL;
D3DXIMAGE_INFO INFO;
D3DxGetImageInfofromFile ("D: /Image.jpg", & info);
g_pd3ddevice-> createoffscreenPlainsurface (Info.width, Info.Height,
Info.format, & g_surface, null;
D3DXLOADSURFAMFROMFROMFILE (g_surface, null, null, "d: /image.jpg", null,
D3DX_FILTER_NONE, 0xFF000000, NULL;
/ / -------------------------------------------------------------------------------------------- --------------------------------------------------
LPDIRECT3DSURFACE9 BackBuffer = NULL;
g_pd3ddevice-> getBackBuffer (0, 0, D3DBACKBuffer_Type_Mono, & Backbuffer);
g_pd3ddevice-> UpdateSurface (g_surface, null, backbuffer, null);
IF (BackBuffer! = NULL)
Backbuffer-> Release ();
/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- -
IF (g_surface! = NULL)
g_surface -> Release ();
As can be seen from the above process, Idirect3DSurface9 is not very complicated, but it is a bit inconvenient - the total amount of creation and release is always paired, and the LPDirect3DDevice9 interface is also inserted during use. These uses a class package, which is more convenient to use.
4, how to package:
Create it to display images according to the function of Surfaces. Therefore, there is an interface to read the image and display the image of the image. It is also to be associated with the LPDirect3DDevice9 device interface, so you need an interface to set the device. As shown below: 1, statement and release
Disclaimer: LPDIRECT3DSURFACE9
Release memory Release ()
2, related image: LoadFromFile
Get image information: d3dxgetimageInfofromfile (...)
Create: createoffscreenplainsurface (...)
Loaded into Surfaces: D3DXLOADSURFAMFILE (...)
3, display image render
Get a cache address: getBackBuffer (...)
Display: updatesurface (...)
4, related device interface setDevice
So the CXSurface is defined as follows:
Class cxsurface
{
protected:
LPDIRECT3DSURFACE9 M_SURFACE;
LPDIRECT3DSURFACE9 M_BACKBUFFER; // Back Buffer
LPDIRECT3DDEVICE9 M_PDEVICE; / / DIRECT3D device pointer
PUBLIC:
Cxsurface (LPDirect3DDevice9 PDEvice);
~ Cxsurface ();
HRESULT LOADFROMFILE (LPCSTR PATH);
Void Render (Void);
}