D3D10 Sprites are insane.
I'm trying to draw a single sprite to the screen. I have a window created (640,480) and the texture loaded in properly. The sprite drawing uses the code below in a Render() function. When run, the sprite does show up but is either tiny when scaling is not applied or skewed when scaling is applied. I know i'm messing up the scaling value, i'm just confused on what the formula should be for calculating it. Right now, i'm using example code from DXUT.cpp which says the scale should be (windowx/textureWidth) and (windowy/textureHeight). This gets the sprite close, but the result is skewed.
Could someone please take a look at the code below and see if you see any glaring issues? Thanks.
Render()
{
// clear the target buffer
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));if (gSpriteBatch != NULL)
{
D3D10_VIEWPORT VPs [D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
UINT cVPs = 1;
ID3D10Device* pd3dDevice = NULL;
gSpriteBatch->GetDevice( &pD3DDevice );
pD3DDevice->RSGetViewports(&cVPs, VPs);
D3DXMATRIXA16 matProjection;
D3DXMatrixOrthoOffCenterLH(&matProjection, (FLOAT)VPs[0].TopLeftX, (FLOAT)(VPs[0].TopLeftX + VPs[0].Width), (FLOAT)VPs[0].TopLeftY, (FLOAT)(VPs[0].TopLeftY + VPs[0].Height), 0.1f, 10);
HRESULT hr = gSpriteBatch->SetProjectionTransform(&matProjection);
gSpriteBatch->Begin(D3DX10_SPRITE_SORT_TEXTURE);
D3DXMATRIXA16 matTranslation;
D3DXMATRIXA16 matScaling;
float scaleX = 640/32;
float scaleY = 480/32;
D3DXMatrixScaling( &matScaling, scaleX, scaleY, 1.0f );
D3DXMatrixTranslation( &matTranslation, 32,480-32,0.1f);
D3DX10_SPRITE Sprite;
Sprite.matWorld = matScaling*matTranslation;
Sprite.pTexture = gSpriteTextureRV;
Sprite.TexCoord.x = (float)0.0f;
Sprite.TexCoord.y = (float)0.0f;
Sprite.TexSize.x = (float)1.0f;
Sprite.TexSize.y = (float)1.0f;
Sprite.TextureIndex = 0;
Sprite.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
gSpriteBatch->DrawSpritesBuffered(&Sprite, 1);
gSpriteBatch->Flush();
gSpriteBatch->End();
}
// display the next item in the swap chain
pSwapChain->Present(0, 0);
}

