Device->BeginScene(); // assume _surface is a pointer to an idirect3dsurface9 interface. // assumes a 32-bit pixel format for each pixel. // get the surface description.Describe the surface D3DSURFACE_DESC surfacedesc; Device->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&_surface); _surface->GetDesc(&surfacedesc);//Note that it has been assumed that _surface is a pointer to the port of idirect3dsurface9// / get a pointer to the surface pixel data. Get the pointer to the memory area D3DLOCKED_RECT lockedrect; _surface->LockRect( &lockedrect, // pointer to receive locked data points to the applied memory area 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(int i = 0; iUnlockRect(); Device->EndScene();
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; // d3dpp is the key of the D3DPRESENT_PARAMETERS structure variable.
The above is the main code. Implemented using directx 9.0. At that time, I explored for a long time, and it took a long time. .
Thanks to these two friends for their blogs
IDirect3DSurface9::LockRect failed
< p>Directx IDirect3DSurface9:LockRect call returns a negative number with a very large absolute value
Welcome to communicate.