设置 DirectX9 表面像素

发布于 2024-11-03 05:00:17 字数 629 浏览 2 评论 0原文

我试图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2024-11-10 05:00:17

D3DLOCKED_RECT 是每行开头之间的字节数,而不是 DWORD 数。您使用 DWORD 指针对缓冲区进行索引,因此您实际上使用了四倍大的间距。

尝试这样的事情......

DWORD * row = (DWORD *)((char *)lrt.pBits + pitch * Y);
for(int z=0;xmsg.iNum;z++)
{
   if( xmsg.iDataBlock[z]>0 )
      row[X+z] = 0xFFFFFF00;
   else
      row[X+z] = 0xFF000000;
   }
}

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...

DWORD * row = (DWORD *)((char *)lrt.pBits + pitch * Y);
for(int z=0;xmsg.iNum;z++)
{
   if( xmsg.iDataBlock[z]>0 )
      row[X+z] = 0xFFFFFF00;
   else
      row[X+z] = 0xFF000000;
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文