• Advertisement
Sign in to follow this  

How to place sprite in D3D window (DX10) for 2D rendering

This topic is 2159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to place sprite in a Direct3D window to display 2D image as a texture. The whole 3D scene should be in orthogonal projection. I have the following variables:

int m_nWindowWidth = 1600; // window client area width
int m_nWindowHeight = 1200; // window client area height
int m_nImageWidth = 1024; // image width
int m_nImageHeight = 1024; // image height
ID3D10Device* m_pDevice;
ID3DX10Sprite* m_pSprite;
D3DX10_SPRITE m_SpriteDefinition; // used in m_pSprite->DrawSpritesImmediate

The sprite should be placed with "best fit" in the client area, for given values sprite size should be 1200*1200, starting from (200, 0) point. I have the sample code which sets arbitrary values for the sprite placement, and need to calculate these values according to my requirements:

D3D10_VIEWPORT viewPort;

viewPort.Width = ??;
viewPort.Height = ??;
viewPort.MinDepth = ??;
viewPort.MaxDepth = ??;
viewPort.TopLeftX = ??;
viewPort.TopLeftY = ??;

m_pDevice->RSSetViewports(1, &viewPort);

D3DXMatrixOrthoOffCenterLH(&matProj, ??, ??, ??, ??, ??, ??);

D3DXMATRIX matTranslation;
D3DXMatrixTranslation(&matTranslation, ??, ??, ??);

D3DXMATRIX matScaling;
D3DXMatrixScaling(&matScaling, ??, ??, ??);
m_SpriteDefinition.matWorld = (matScaling * matTranslation);

Please help me to replace all ?? with correct values - general formula or just the values with small explanation, since I don't know the theory behind D3D matrices. Thank you.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement