Game Development Reference
In-Depth Information
// 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();
The D3DLOCKED_RECT structure is defined as:
typedef struct _D3DLOCKED_RECT {
INT Pitch; // the surface pitch
void *pBits; // pointer to the start of the surface memory
} D3DLOCKED_RECT;
Here are a few comments about the surface lock code. The 32-bit pixel
format assumption is important since we cast the bits to DWORD s, which
are 32-bits. This lets us treat every DWORD as representing a pixel.
Also, do not worry about understanding how 0xffff0000 represents
red, as colors are covered in Chapter 4.
1.3.2 Multisampling
Multisampling is a technique used to smooth out blocky-looking images
that can result when representing images as a matrix of pixels. One of
the common uses of multisampling a surface is for full-screen
antialiasing (see Figure 1.3).
Search WWH ::




Custom Search