本文主要是介绍DirectX9 表面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
The most important methods of IDirect3DSurface9 are:
LockRect—This method allows us to obtain a pointer to the surface memory. Then, with some pointer arithmetic, we can read and write to each pixel in the surface.
UnlockRect—After you have calledLockRectand are done accessing the surface’s memory, you must unlock the surface by calling this method.
GetDesc—This method retrieves a description of the surface by filling out aD3DSURFACE_DESCstructure.
we have provided the following code block that locks a surface and colors each pixel red:
// Assume _surface is a pointer to an IDirect3DSurface9 interface.
// Assumes a 32-bit pixel format for each pixel.
// Get the surface description.
D3DSURFACE_DESC surfaceDesc;
_surface->GetDesc(&surfaceDesc);
// Get a pointer to the surface pixel data.
D3DLOCKED_RECT lockedRect;
_surface->LockRect(
&lockedRect,// pointer to receive locked data
0, // lock entire surface
0); // no lock flags specified
// Iterate through each pixel in the surface and set it to red.
DWORD* imageData = (DWORD*)lockedRect.pBits;
for(inti=0;i<surfaceDesc.Height; i++)
{
for(intj=0;j<surfaceDesc.Width; j++)
{
// index into texture, note we use the pitch and divide by
// four since the pitch is given in bytes and there are
// 4 bytes per DWORD.
int index=i*lockedRect.Pitch/4+j;
imageData[index] = 0xffff0000; // red
}
}
_surface->UnlockRect();
TheD3DLOCKED_RECTstructure is defined as:
typedef struct _D3DLOCKED_RECT {
INT Pitch; // the surface pitch
void *pBits; // pointer to the start of the surface memory
} D3DLOCKED_RECT;
这篇关于DirectX9 表面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!