【问题标题】:How to give data to Hardwarepixelbuffer correctly in Ogre3d?如何在 Ogre3d 中正确地将数据提供给 Hardwarepixelbuffer?
【发布时间】:2017-08-27 14:53:51
【问题描述】:

《OGRE 3D 1.7 Application Development Cookbook》中有这样一段代码:

m_VideoTexture->m_PixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
memcpy(m_VideoTexture->m_PixelBuffer->getCurrentLock().data, lpbi + lpbi->biSize + 25, lpbi->biSizeImage);
m_VideoTexture->m_PixelBuffer->unlock();

为什么lpbi加了lpbi的biSize又加了25?因为我想将代码转换为 C#,我几乎完成了,渲染的纹理是绿色的,而不是视频的原始颜色。 像这样:

这是我的 C# 代码:

System.Drawing.Bitmap bitmap = videotexMgr.Stream.GetBitmap(videotex.FrameNum);
        MemoryStream ms = new MemoryStream();
        bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        byte[] bitmapBuffer = new byte[ms.Length];
        ms.Seek(0, SeekOrigin.Begin);
        ms.Read(bitmapBuffer, 0, bitmapBuffer.Length);
        ms.Close();

        videotexMgr.PixelBuffer.Lock(HardwareBuffer.LockOptions.HBL_DISCARD);
        Marshal.Copy(bitmapBuffer, 0, videotex.PixelBuffer.CurrentLock.data, bitmapBuffer.Length);
        videotexMgr.PixelBuffer.Unlock();

PS:原视频是黑白的,我得到的位图是正确的

【问题讨论】:

  • 我不知道25 是干什么用的。但是,您可以尝试使用sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)。有关您的lpbi 的尺寸信息,请参阅this question
  • 我已将您的解决方案移至社区 wiki 答案。

标签: c# bitmap ogre3d videotexture


【解决方案1】:

OP 的解决方案。

正确的代码:

System.Drawing.Bitmap bitmap = videotex.Stream.GetBitmap(videotex.FrameNum);
bitmap.Save("./Media/materials/textures/xx.png");
Image image = new Image();
image.Load("xx.png", "General");
image.FlipAroundX();
videotexMgr.PixelBuffer.BlitFromMemory(image.GetPixelBox());
image.Dispose();

videotexMgr.FrameNum++;

【讨论】:

    猜你喜欢
    • 2019-03-26
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    相关资源
    最近更新 更多