Jump to content

  • Log In with Google      Sign In   
  • Create Account


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

        	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;

            	out device,
            	out swapChain);

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

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


            	swapChain.Present(0, PresentFlags.None);



Spore's creature editor, aka 10 dollar demo and content generator

16 April 2008 - 02:21 PM

While I'm not one of the slavering fanboys when it comes to spore (I'll actually read reviews before running out to get it), I have been looking forward to it. So like many, I thought it was neat when EA announced it was going to release the creature editor component of the game as a demo. It's certainly a good idea. It'll whet many people's appetites, it'll promote the product more, and what's more, it connects to the online sporepedia and uploads the content you generate. That way when spore is released in september, we won't all start in empty or identical worlds. But here's the kicker: it's just been announced that the editor will be released in june... and that they're charging 10 bucks for it. There's also a free version, but it only has 25% of the body parts available. So EA gets their product promoted, and gets tons of free content, AND they're charging for it. What's more, they're charging for a product that'll become obsolete three months later. We all know EA loves to milk their franchises, even after the cow is dead, but wow. Now to be completely honest, I'm probably going to get it. After all, I regularly spend more than that on lunch. But it definately leaves a bad taste in my mouth. Thoughts?

[.net] Automatic properties: why require both get and set?

08 April 2008 - 09:42 AM

My private variables are never exposed publicly, they're always behind properties. So I was initially excited about automatic properties. Note however that unlike some, I don't just place everything behind simple getters and setters. I don't often make properties anything other than just get. Allowing the user to alter too many internals is just dangerous. So why do you suppose they require that automatic properties be BOTH get and set? I find myself rarely using them for this reason.

[.net] Retrieving data from an SQL database with LINQ

05 April 2008 - 09:37 AM

Given the following:
        public CharacterSummary GetCharacterSummary(string name)
            CharacterSummary summary = new CharacterSummary();

            var Query = from a in mData.CharacterDataSets
                        where a.Name == name
                        select a;

            if (Query.Count<CharacterDataSet>() == 0)
                return null;
                CharacterDataSet c = Query.First<CharacterDataSet>();
                summary.Name = c.Name;
                summary.Bounty = c.Bounty;
                summary.Rank = c.Rank;
                return summary;

Is all the data retrieved when I do the query, or when I call individual properties (summary.Name for example). I'm concerned about potential performance issues in the future. Suppose the Character table gets quite large. If I just need to retrieve a summary that's a smaller subset of data, I would like to pull just the relevant information from the database, not the entire set of data for that character. If it is the case that all the data is pulled at the time the query is made, does anyone have suggestions as to how to improve that? I'm fairly new at working with SQL. Surely there's a way to pull a specific subset of data from an entry in a table.

Stencil shadow volumes rendering incorrectly

19 December 2007 - 07:46 AM

I've been trying to implement shadow volumes for the first time. I'm working in c#, with an engine of my own making. OpenGL, Managed Direct3D9, and Xna are abstracted away. At this time, the stenciling methods are only implemented for MDX. I've double checked that the correct states are being sent to MDX (ie, my ComparisonFunction enum is properly converted to MDX's Compare enum, etc). At this point, this is what I'm seeing, which is obviously incorrect: Incorrect Shadows The upside is that the stencil buffer is definately in action. The shadow volumes are not getting rendered to the color or depth buffers, only the stencil buffer. The black areas are the unlit pass rendered after the shadow volumes are rendered to the stencil buffer. I confirmed this by changing the color of the unlit pass. I'm not finding silouette edges when creating my shadow volumes. I'm simply extruding all edges in a vertex shader. At this point only the boxes are extruding volumes, not the spheres. I render in three passes: 1) The lit pass: Lights are turned on. Objects are rendered to color and depth buffers. 2) The shadow pass: shadow volumes are rendered to the stencil buffer, but not the color or depth buffers. 3) The unlit pass: Lighting is still enabled to allow for ambient lighting, but all light sources are turned off. Objects are rendered to color and depth buffers, as permitted by the stencil buffer. Here's the relevant code. I've removed some of the engine code for clarity. I used codesampler.com's shadow volume example as a guide. Hopefully someone more experienced with shadow volumes and stenciling can tell whats wrong either from the code or the image.
                // Lit pass
                mGraphicsProvider.States.StencilBufferEnabled = false;
                mGraphicsProvider.States.LightingEnabled = true;

                // Lit pass is rendered here

                // Shadow pass
                mGraphicsProvider.States.ReferenceStencil = 0x1;
                    mGraphicsProvider.States.StencilMask = (int)0xffffffff;
                    mGraphicsProvider.States.StencilWriteMask = (int)0xffffffff;
                // Ensure nothing is rendered to color buffer
                mGraphicsProvider.States.AlphaBlendEnabled = true;
                mGraphicsProvider.States.SetAlphaBlendFunction(BlendFunction.Zero, BlendFunction.One);
                // Ensure nothing is written to the depth buffer
                mGraphicsProvider.States.DepthBufferWriteEnabled = false;
                mGraphicsProvider.States.StencilBufferEnabled = true;
                mGraphicsProvider.States.TwoSidedStencil = true;
                    StencilOperation.Keep, // fail
                    StencilOperation.Keep, // zfail
                    StencilOperation.Increment); // pass

                // Shadow volumes rendered here

                mGraphicsProvider.States.StencilBufferEnabled = false;
                mGraphicsProvider.States.AlphaBlendEnabled = false;
                mGraphicsProvider.States.TwoSidedStencil = false;
                mGraphicsProvider.States.DepthBufferWriteEnabled = true;

                // unlit pass
                mGraphicsProvider.States.LightingEnabled = true;
                mGraphicsProvider.States.LightStates[0].Enabled = false;
                mGraphicsProvider.States.StencilBufferEnabled = true;

                // Unlit pass is rendered here

                mGraphicsProvider.States.StencilBufferEnabled = false;