我正在尝试使用Oculus Rift DK2和.Net来显示实时视频流
我可以使用Emgu或ffmpeg对视频(rtmp)进行采样,然后在屏幕上使用SharpDX进行显示。
但我正在努力制造眼睛裂缝来展示它。现在我正在使用SharpOVR包装器。
任何建议都将受到高度赞赏
这是一些代码:
的Program.cs:
using (var program = new RiftGame())
program.Run();
RiftGame.cs
using SharpOVR;
using SharpDX;
...
Queue<System.Drawing.Bitmap> _images;
void _tmr_Tick(object sender, EventArgs e)
{
if (_capture == null)
{
_capture = new Capture(Emgu.CV.CvEnum.CaptureType.Any);
}
System.Drawing.Bitmap image = _capture.QueryFrame().Bitmap;
_images.Enqueue(image);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_graphicsDeviceManager.PreferredBackBufferWidth = 480;
_graphicsDeviceManager.PreferredBackBufferHeight = 800;
var image = _images.Dequeue();
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
tex = Texture2D.Load(GraphicsDevice, ms);
}
Vector2 planePosition = new Vector2(
(this.GraphicsDevice.BackBuffer.Width / 2.0f) - (tex.Width / 2.0f),
(this.GraphicsDevice.BackBuffer.Height / 2.0f) - (tex.Height / 2.0f));
_spriteBatch.Begin();
_spriteBatch.Draw(tex, planePosition, Color.White);
_spriteBatch.End();
_spriteBatch.Begin(SpriteSortMode.Deferred, GraphicsDevice.BlendStates.NonPremultiplied);
_spriteBatch.End();
base.Draw(gameTime);
}