I want to show one of my WPF applications in VR and ran into a little problem when rendering the overlay texture directly from a datastream. The texture isn´t displaye correctly.
First of all I render my WPF Application into a Bitmap and save it to a stream:
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(visual);
BitmapFrame frame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(frame);
m_vrStream.Position = 0;
encoder.Save(m_vrStream);
I don´t want to use Unity for the VR part so I switched to SharpDX and created a new Texture2D.
var description2D = new Texture2DDescription()
{
Width = 1920,
Height = 1080,
ArraySize = 1,
MipLevels = 1,
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
};
m_texture = new Texture2D(m_device, description2D, new[] { new SharpDX.DataBox(m_dataStream.DataPointer,description2D.Width
* (int)FormatHelper.SizeOfInBytes(description2D.Format),0)});
This always brings a System.AccessViolationException. If I lower the width and height in Texture2DDescription, the texture is displayed but not correctly (random colored pixel). If I first save the datastream into a .png file and load it with
m_texture = TextureLoader.CreateTexture2DFromBitmap(m_device, TextureLoader.LoadBitmap(new SharpDX.WIC.ImagingFactory2(), "test.png"));
everything looks fine.
I´m new to graphics programming and believe that I have a miss understanding in the Texture2DDescription part. The width and height are hard coded for testing purposes and fitting the size of the image I´m generating
Hope someone can give me some hints with that.
Thanks and regards