简体   繁体   中英

How to give data to Hardwarepixelbuffer correctly in Ogre3d?

There is a code in "OGRE 3D 1.7 Application Development Cookbook" like this:

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();

Why did the lpbi plus the biSize of lpbi and also plus 25? Because i want to convert the code into the C#, i almost finished, the texture rendered is green not the original color that the video has. like this:

Here is my c# code:

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: The original video is black and white and the bitmap i get is correct

Solution by OP.

The right code:

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++;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM