I want to be able to set the individual pixels of the back buffer in my program in an efficient way. This is what I call in my rendering function:
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
d3ddev->BeginScene();
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
D3DLOCKED_RECT locked;
surface->LockRect(&locked, NULL, 0);
*(BYTE*)locked.pBits=42;
surface->UnlockRect();
surface->Release();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
However it always crashes. If I comment out the part where I assign the first byte to 42, it doesn't crash. So what am I doing wrong, shouldn't I be able to assign values to the buffer pointed by bPits since the surface is locked?
Just found out that locked.pBits is a null pointer. Why did LockRect fail, then?