Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

gharen2

Member Since 12 Feb 2007
Offline Last Active Apr 16 2012 01:30 PM
-----

Topics I've Started

SlimDX, DirectX 10 sprite woes.

04 July 2011 - 02:41 AM

I'm fairly familiar with graphics programming, but am trying out directx 10 for the first time and can't figure this one out. I just can't get a sprite to be visible. I've compared my code to countless tutorials and snippets. I've fiddled with the projection and world matrices to no end.

Using the debug runtimes gives the warning "[1032] D3D10: WARNING: ID3D10Buffer::SetPrivateData: Existing private data of same name with different size found! [ STATE_SETTING WARNING #55: SETPRIVATEDATA_CHANGINGPARAMS ]" when the sprite object is created, but from what google has shown me this warning seems to be pretty common when the sprite is created and rendering still works.

I have the feeling I'm missing something really obvious. If anyone can spot what I'm missing I'd greatly appreciate it.

PS: Yes I understand the evil that is Application.DoEvents.

using System;

using System.Drawing;
using System.Windows.Forms;

using SlimDX;
using SlimDX.Direct3D10;
using SlimDX.DXGI;
using Device = SlimDX.Direct3D10.Device;

namespace SpriteTest
{
	class Program
	{
    	static void Main(string[] args)
    	{
        	var form = new Form();
        	form.ClientSize = new Size(800, 600);
        	form.Show();

        	var swapChainDescription = new SwapChainDescription()
        	{
            	BufferCount = 1,
            	ModeDescription = new ModeDescription(800, 600, new Rational(60, 1), Format.R8G8B8A8_UNorm),
            	IsWindowed = true,
            	OutputHandle = form.Handle,
            	SampleDescription = new SampleDescription(1, 0),
            	SwapEffect = SwapEffect.Discard,
            	Usage = Usage.RenderTargetOutput
        	};

        	Device device;
        	SwapChain swapChain;

        	Device.CreateWithSwapChain(null,
            	DriverType.Hardware,
            	DeviceCreationFlags.None,
            	swapChainDescription,
            	out device,
            	out swapChain);

        	var backBuffer = SlimDX.Direct3D10.Texture2D.FromSwapChain<SlimDX.Direct3D10.Texture2D>(swapChain, 0);
        	var renderTarget = new RenderTargetView(device, backBuffer);
        	backBuffer.Dispose();

        	device.OutputMerger.SetTargets(renderTarget);
        	
        	device.Rasterizer.SetViewports(new Viewport(0, 0, 800, 600, 0, 1));

        	var textureView = ShaderResourceView.FromFile(device, "testtexture.jpg");

        	var sprite = new Sprite(device, 100);
        	sprite.ProjectionTransform = Matrix.OrthoOffCenterLH(0, 800, 600, 0, 0, 100);

        	var spriteInstance = new SpriteInstance(textureView, Vector2.Zero, new Vector2(1, 1));
        	spriteInstance.TextureIndex = 0;
        	spriteInstance.Color = new Color4(1, 1, 1, 1);
        	spriteInstance.Transform = (Matrix.Scaling(100, 100, 1) * Matrix.Translation(100, 100, 10));

        	var spriteInstances = new SpriteInstance[1];
        	spriteInstances[0] = spriteInstance;

        	while (form.Created)
        	{
            	device.ClearRenderTargetView(renderTarget, Color.Red);

            	sprite.Begin(SpriteFlags.GroupByTexture);
            	sprite.DrawBuffered(spriteInstances);
            	sprite.Flush();
            	sprite.End();

            	swapChain.Present(0, PresentFlags.None);

            	Application.DoEvents();
        	}

        	sprite.Dispose();
        	textureView.Dispose();
        	renderTarget.Dispose();
        	swapChain.Dispose();
        	device.Dispose();
    	}
	}
}


PARTNERS