   Trouble rendering a sprite in d3d10
  For some reason instead of rendering a sprite like its meant to I seem to get a white rectangle from the top left of the window to some point approximatly where the sprite should be, exacept that instead of moving smoothly it seems to make what look like 64px jumps, which intrestingly is the size of my sprite...I havnt implemented alpha blending in my shader yet, so I can understand not getting a white circle (the image I'm using for the sprite) because thats done through the images alpha channel, but it should still be a smoothly moving square..I know my logic code is sound, since when used with d3d9 it works fine, so it must be somewhere in the following d3d10 code...However ive spent all day going through this and havnt found the cause, ive got drawing a simple tringle in word space with a position/colour vertex buffer and shaders working, so I'm pretty sure its nothing fundamental like having an incorrect projection matrix or setting something ont he device wrong...Creating the Graphics objectHRESULT hr;ID3D10Blob *errorOut=0;DXGI_SWAP_CHAIN_DESC sd;ZeroMemory(&sd, sizeof(sd));sd.BufferCount = 2;//1 front buffer, 1 back buffersd.BufferDesc.Width  = size.w;//window client rectsd.BufferDesc.Height = size.h;sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;sd.BufferDesc.RefreshRate.Numerator   = 60;sd.BufferDesc.RefreshRate.Denominator = 1;sd.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;sd.OutputWindow = hwnd;//windowsd.SampleDesc.Count = 1;sd.SampleDesc.Quality = 0;sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;sd.Windowed = TRUE;unsigned deviceFlags = 0;#ifdef _DEBUGdeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;#endifhr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE,  NULL, deviceFlags,D3D10_SDK_VERSION, &sd, &swapChain, &device);if(FAILED(hr))throw WinError(L"Failed to create Direct3D 10 device and swap chain.",hr);//Create a render target view(from Backbuffer)ID3D10Texture2D *backBuffer = NULL;hr = swapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&backBuffer);if(FAILED(hr))throw WinError(L"Failed to get back buffer.",hr);hr = device->CreateRenderTargetView(backBuffer, NULL, &renderTargetView);backBuffer->Release();if(FAILED(hr))throw WinError(L"Failed to create view",hr);device->OMSetRenderTargets(1, &renderTargetView, NULL);//In D3D10 this must be done, because there is no default ViewportD3D10_VIEWPORT vp;vp.Width    = size.w;vp.Height   = size.h;vp.MinDepth = 0.0f;vp.MaxDepth = 1.0f;vp.TopLeftX = 0;vp.TopLeftY = 0;device->RSSetViewports(1, &vp);unsigned shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;#ifdef _DEBUGshaderFlags |= D3D10_SHADER_DEBUG;#endif//====PRIMITIVE====//...working primitive code...//====SPRITE====//hr = D3DX10CreateEffectFromResource(Module, MAKEINTRESOURCE(IDR_FX_SPRITE), L"sprite.fx",NULL, NULL, "fx_4_0", shaderFlags, 0, device, NULL, NULL, &spriteEffect, &errorOut, NULL);if(FAILED(hr))throw BlobError(errorOut, L"Failed to load effect: sprite.fx");SafeRelease(&errorOut);spriteTechnique = spriteEffect->GetTechniqueByName("Render");D3D10_INPUT_ELEMENT_DESC spriteInputLayoutDesc[] ={{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,D3D10_INPUT_PER_VERTEX_DATA, 0},{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0}};size_t spriteVertexNumElements = sizeof(spriteInputLayoutDesc)/sizeof(D3D10_INPUT_ELEMENT_DESC);// Create the input layoutD3D10_PASS_DESC spritePassDesc;spriteTechnique->GetPassByIndex(0)->GetDesc(&spritePassDesc);hr = device->CreateInputLayout(spriteInputLayoutDesc, spriteVertexNumElements,spritePassDesc.pIAInputSignature, spritePassDesc.IAInputSignatureSize,&spriteInputLayout);if(FAILED(hr))throw WinError(L"Failed to create vertex input layout",hr);//shader globalsspriteMatWorld = spriteEffect->GetVariableByName("World")->AsMatrix();spriteMatProjection = spriteEffect->GetVariableByName("Projection")->AsMatrix();spriteTexture  = spriteEffect->GetVariableByName("Texture")->AsShaderResource();//d3d10 vertex layout for trianglestrip// 2----4// | \  |// |  \ |// 1----3//in d3d9 I used a triangle fan// 1----2// | \  |// |  \ |// 4----3SpriteVertex spriteVertices[] ={{D3DXVECTOR3(-0.5, 0.5,0), D3DXVECTOR2(0,1)},{D3DXVECTOR3(-0.5,-0.5,0), D3DXVECTOR2(0,0)},{D3DXVECTOR3( 0.5, 0.5,0), D3DXVECTOR2(1,1)},{D3DXVECTOR3( 0.5,-0.5,0), D3DXVECTOR2(1,0)},};D3D10_BUFFER_DESC spriteBD;spriteBD.Usage = D3D10_USAGE_DEFAULT;spriteBD.ByteWidth = sizeof(SpriteVertex) * 4;spriteBD.BindFlags = D3D10_BIND_VERTEX_BUFFER;spriteBD.CPUAccessFlags = 0;spriteBD.MiscFlags = 0;D3D10_SUBRESOURCE_DATA spriteInitVertices;spriteInitVertices.pSysMem = spriteVertices;hr = device->CreateBuffer(&spriteBD, &spriteInitVertices, &spriteBuffer);if(FAILED(hr))throw WinError(L"Failed to create vertex buffer",hr);//all projections are same, so we set them all hereD3DXMATRIXA16 projMat;D3DXMatrixOrthoOffCenterLH(&projMat,0,(float)size.w,  (float)size.h, 0, 0, 1);spriteMatProjection->SetMatrix((float*)projMat);rendervoid Graphics::Render(boost::function<void(void)> call){device->ClearRenderTargetView(renderTargetView, backCol);//triangle test code, this triangle works perfectlyPrimitiveVertex *vertices;primBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&vertices);vertices[0].Col = D3DXVECTOR4(1.0, 0.0, 0.0, 1.0);vertices[1].Col = D3DXVECTOR4(0.0, 1.0, 0.0, 1.0);vertices[2].Col = D3DXVECTOR4(0.0, 0.0, 1.0, 1.0);vertices[0].Pos = D3DXVECTOR3(0,  0  , 0);vertices[1].Pos = D3DXVECTOR3(400,0  , 0);vertices[2].Pos = D3DXVECTOR3(400,400, 0);primBuffer->Unmap();device->IASetInputLayout(primInputLayout);UINT stride = sizeof(PrimitiveVertex);UINT offset = 0;device->IASetVertexBuffers(0, 1, &primBuffer, &stride, &offset);device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);// Render a triangleD3D10_TECHNIQUE_DESC techDesc;primTechnique->GetDesc( &techDesc );for( UINT p = 0; p < techDesc.Passes; ++p ){primTechnique->GetPassByIndex(p)->Apply(0);device->Draw(3, 0);}//calls my games render func, which is meant to draw the bouncing ball spritecall();swapChain->Present(options.VSync ? 1 : 0, 0);}textureTexture::Texture(Graphics *grf, const std::wstring &file):grf(grf), file(file){HRESULT hr;assert(grf);if(!fllib::FileExists(file))throw fllib::exception::FileNotFound(file);grf->AddRef();D3DX10_IMAGE_LOAD_INFO info;hr = D3DX10CreateShaderResourceViewFromFile(grf->GetDevice(), file.c_str(),&info, 0, &shaderResView, 0);if(FAILED(hr)){grf->Release();throw WinError(L"Failed to load texture: " + file, hr);}size.w = info.Width;size.h = info.Height;}//the sprite basicly holds a refrence to a texture, the centre (for scaling, roations) and some precalulated matrix stuff. As well as code for drawing it as a spriteSprite::Sprite(Graphics *grf, Texture *tex, fllib::Size2<unsigned> size):grf(grf), tex(tex), size(size), centre(size.w/2.0f, size.h/2.0f){assert(grf);assert(tex);grf->AddRef();tex->AddRef();D3DXMatrixScaling    (&matScale, (float)size.w, (float)size.h, 1.0f);D3DXMatrixTranslation(&matOffset, -centre.x, -centre.y, 0.0f);matSO = matScale * matOffset;}//there are several overloads for stuff like scaling, roation etc. But in this test I was only using this onevoid Sprite::Draw(fllib::Point2<float> pos){D3DXMATRIXA16 matPos;D3DXMatrixTranslation(&matPos, pos.x, pos.y, 0.0f);grf->DrawSprite(matSO * matPos, tex->GetShaderResView());}//this is here rather than in the Sprite class cause almost everything//is working with Graphics members anywayvoid Graphics::DrawSprite(D3DXMATRIX &transform, ID3D10ShaderResourceView *tex){device->IASetInputLayout(spriteInputLayout);UINT stride = sizeof(SpriteVertex);UINT offset = 0;device->IASetVertexBuffers(0, 1, &spriteBuffer, &stride, &offset);device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);spriteMatWorld->SetMatrix  ((float*)&transform);spriteTexture ->SetResource(tex);//RenderD3D10_TECHNIQUE_DESC techDesc;spriteTechnique->GetDesc(&techDesc);for(unsigned p=0; p<techDesc.Passes; ++p){spriteTechnique->GetPassByIndex(p)->Apply(0);device->Draw(4, 0);}}and the shader its selfmatrix Projection;matrix World;Texture2D Texture;SamplerState Sampler{    Filter = MIN_MAG_MIP_LINEAR;    AddressU    = Wrap;    AddressV    = Wrap;};struct VS_INPUT{    float4 Pos : POSITION;    float2 Tex : TEXCOORD;};struct PS_INPUT{    float4 Pos  : SV_POSITION;    float2 Tex  : TEXCOORD0;};PS_INPUT VS(VS_INPUT input){    PS_INPUT output = (PS_INPUT)0;    output.Tex = input.Tex;    output.Pos = mul(input .Pos, World);    output.Pos = mul(output.Pos, Projection);    return output;}float4 PS(PS_INPUT input):SV_Target{    return Texture.Sample(Sampler, input.Tex);}technique10 Render{    pass P0    {   SetVertexShader  (CompileShader(vs_4_0, VS()));   SetGeometryShader(NULL );   SetPixelShader   (CompileShader(ps_4_0, PS()));    }}//the shader for draing the triangle (which works)matrix Projection;struct VS_INPUT{    float4 Pos : POSITION;    float4 Col : COLOUR;};struct PS_INPUT{    float4 Pos : SV_POSITION;    float4 Col : COLOR;};PS_INPUT VS(VS_INPUT input){    PS_INPUT output = (PS_INPUT)0;    output.Col = input.Col;    output.Pos = input.Pos;    output.Pos = mul(input.Pos, Projection);    return output;}float4 PS(PS_INPUT input):SV_Target{    return input.Col;}technique10 Render{    pass P0    {   SetVertexShader  (CompileShader(vs_4_0, VS()));   SetGeometryShader(NULL );   SetPixelShader   (CompileShader(ps_4_0, PS()));    }}