I'd like to plot a pixel on screen with directx 9. I know about the GetBackBuffer() function, but when I try to write to the backbuffer surface pointer I get a memory error.
// Set device parameters.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferCount = 1;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dpp.Windowed = true;
d3dpp.EnableAutoDepthStencil = false;
// Create device.
m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &m_pDevice);
m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_pBackBuffer);
m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 0, 0);
m_pDevice->BeginScene();
m_pBackBuffer->LockRect(&m_bbRect, NULL, D3DLOCK_DONOTWAIT);
D3DCOLOR *pPixelData = (D3DCOLOR*)m_bbRect.pBits;
pPixelData[x + (y * m_bbRect.Pitch)] = D3DCOLOR_XRGB(255, 255, 255); // Crashes...
m_pBackBuffer->UnlockRect();
m_pDevice->EndScene();
m_pDevice->Present(NULL, NULL, 0, NULL);