I've made some progress getting D3DXMatrixOrthoLH to work (finally) and I've managed to successfully blit a full screen 2D image. However, when blitting smaller images and sprite sheets, things don't work properly anymore. I've put quite a bit of work into getting this working so far, here's my code:
void bltSprite( LPDIRECT3DTEXTURE9 tex, RECT* src, D3DXVECTOR3* dst )
{
D3DXMATRIX mtxProj, mtxWorld, mtxView;
struct BLTVERTEX v[4];
float w = src->top - src->right;
float h = src->left - src->bottom;
float fx, fy;
ZeroMemory( v, sizeof( struct BLTVERTEX ) * 4 );
fx = src->right - (ScreenX/2.0f);
fy = src->bottom - ((ScreenY/2.0f)-h);
v[0].v.x = dst->x - 0.5f;
v[0].v.y = -dst->y - 0.5f;
v[1].v.x = dst->x+w - 0.5f;
v[1].v.y = -dst->y - 0.5f;
v[2].v.x = dst->x+w - 0.5f;
v[2].v.y = -dst->y+h - 0.5f;
v[3].v.x = dst->x - 0.5f;
v[3].v.y = -dst->y+h - 0.5f;
v[0].t.x = src->top / w;
v[0].t.y = 1.0f - src->left / h;
v[1].t.x = src->right / w;
v[1].t.y = 1.0f - src->left / h;
v[2].t.x = src->right / w;
v[2].t.y = 1.0f - src->bottom / h;
v[3].t.x = src->top / w;
v[3].t.y = 1.0f - src->bottom / h;
D3DXMatrixTranslation( &mtxWorld, fx, -fy, 0.0f );
D3DXMatrixIdentity( &mtxView );
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_WORLD, &mtxWorld );
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_VIEW, &mtxView );
IDirect3DDevice9_SetFVF( lpD3DDevice, D3DFVF_XYZ | D3DFVF_TEX1 );
IDirect3DDevice9_SetTexture( lpD3DDevice, 0, (IDirect3DBaseTexture9*) tex );
IDirect3DDevice9_DrawPrimitiveUP( lpD3DDevice, D3DPT_TRIANGLEFAN, 2, v, sizeof( struct BLTVERTEX ) );
}
I apologize for the usage of C (for the C haters), but the project was originally written in C. I can't quite figure out what's going on here.
Examples of what works and what doesn't:
This works:
RECT src = { 0, 0, 640, 480 };
D3DXVECTOR3 dst = { 0, 0, 0 };
bltSprite( lpSplash, &src, &dst );
This doesn't:
RECT src = { 50, 50, 600, 440 };
D3DXVECTOR3 dst = { 0, 0, 0 };
bltSprite( lpSplash, &src, &dst );
Moving the sprites about doesn't seem to work either in some instances. Not sure what's going on here. This sucks, so any help is appreciated. Thanks.
Shogun