Hi,
I am trying a little experiment to render a simple image using the Spritebatch with SharpDX
I get the BlueCornflower clear But no Image.. Debug says that the file has been successfully loaded so i'm guessing its to do with the Device setup which i am not very familiar with.
Thanks
using System;
using SharpDX;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Windows;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
using Texture2D = SharpDX.Direct3D11.Texture2D;
using SharpDX.Toolkit.Graphics;
namespace TestDriver
{
static class Program
{
[STAThread]
static void Main()
{
RenderForm form = new RenderForm("Demo");
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription=
new ModeDescription(512, 512,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
var context = device.ImmediateContext;
var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);
GraphicsDevice graphics = GraphicsDevice.New(device);
SpriteBatch spriteBatch = new SpriteBatch(graphics);
string path = "image.dds";
var image = Texture.Load(graphics, path,TextureFlags.ShaderResource, ResourceUsage.Immutable);
var rectangle = new Rectangle(100, 100, 980, 272);
RenderLoop.Run(form, () =>
{
context.ClearRenderTargetView(renderView, Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(image,rectangle,Color.White);
spriteBatch.End();
swapChain.Present(0, PresentFlags.None);
});
}
}
}