设置 DirectX9 表面像素
我试图在 D3DSURFACE9 中设置各个像素,但它们到处都是。 我想我以前也这样做过,但这次似乎做不好。
3DLOCKED_RECT lrt;
if(D3D_OK == lpThis->sfRenderingCanvas->LockRect(&lrt,NULL,0))
{
UINT pitch = lrt.Pitch;
VOID *data;
data = lrt.pBits;
UINT Y = (UINT)xmsg.Y;
UINT X = (UINT)xmsg.X;
for(int z=0;xmsg.iNum;z++)
{
if( xmsg.iDataBlock[z]>0 )
((DWORD*)data)[X+Y*pitch+z] = 0xFFFFFF00;
else
((DWORD*)data)[X+Y*pitch+z] = 0xFF000000;
}
}
}
Y 介于 0 和创建曲面时使用的高度之间
X 介于 0 和表面的节距之间
有人能告诉我我做错了什么吗? 而且,它的高度似乎是我的窗户的两倍。 (^如果我尝试绘制超过 1/4 的行,它会覆盖其中的 1/2。)
I'm trying to set the individual pixels in a D3DSURFACE9 but they're going all over the place.
I think I've done this before but can't seem to get it right this time.
3DLOCKED_RECT lrt;
if(D3D_OK == lpThis->sfRenderingCanvas->LockRect(&lrt,NULL,0))
{
UINT pitch = lrt.Pitch;
VOID *data;
data = lrt.pBits;
UINT Y = (UINT)xmsg.Y;
UINT X = (UINT)xmsg.X;
for(int z=0;xmsg.iNum;z++)
{
if( xmsg.iDataBlock[z]>0 )
((DWORD*)data)[X+Y*pitch+z] = 0xFFFFFF00;
else
((DWORD*)data)[X+Y*pitch+z] = 0xFF000000;
}
}
}
Y is between 0 and the height used when creating the surface
X is between 0 and the pitch of the surface
Can anybody tell what I'm doing wrong?
Also, it seems to go about twice as far down as my window.
(^If I try to draw over 1/4 the rows, it covers 1/2 of them.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
D3DLOCKED_RECT 是每行开头之间的字节数,而不是 DWORD 数。您使用 DWORD 指针对缓冲区进行索引,因此您实际上使用了四倍大的间距。
尝试这样的事情......
The pitch value that comes back in the D3DLOCKED_RECT is the number of bytes between the start of each row, not the number of DWORDs. You're indexing into the buffer using a DWORD pointer, so you are effectively using a pitch four times too large.
Try something like this...