开发者

Set Individual Pixels on Back Buffer

开发者 https://www.devze.com 2023-01-14 11:35 出处:网络
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:

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 locke开发者_StackOverflow社区d?

Just found out that locked.pBits is a null pointer. Why did LockRect fail, then?


In order to lock the back buffer, you need to specify a flag at device creation:

D3DPRESENT_PARAMETERS d3dpp;
(...)
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

However, as specified in Direct3D specifications, this could seriously hurt the performances. You should rather draw textured triangles.

0

精彩评论

暂无评论...
验证码 换一张
取 消