Sign in to follow this  
XDarkAngelX

ID3DXSprite isn't drawing in the expected postion

Recommended Posts

I am trying to draw Textures to the screen using ID3DXSprite and everything is going great except that it seems not draw in the right position(both in relation to the window client 0 point and the 0 point of the window itself)
also I have noticed what I think is the problem the ID3DXSprite seems to scale my texture as the texture should be 256x256 and it appears on screen something like 200x190
I have used to GetCursorPos to measure the texutre that was drawn on the screen
I also using ID3DXFont to draw a line of text to the screen

so my question is if any one knows what could be causing this sort of werid behavior ?

the render function
[code]void render(void)
{
std::string st;
std::stringstream out,out2;
RECT rc;
POINT cursorPos;
GetCursorPos(&cursorPos);
ScreenToClient( wndHandle, &cursorPos );

out << cursorPos.x;
out2 << cursorPos.y;
st = out.str() + " " + out2.str();

WINDOWINFO winInfo;
winInfo.cbSize = sizeof(winInfo);
GetWindowInfo(wndHandle,&winInfo);

// Check to make sure you have a valid Direct3D device
if( NULL == pd3dDevice )
return;// Clear the back buffer to a blue color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0,100,255 ), 1.0f, 0 );
if(SUCCEEDED(pd3dDevice->BeginScene()))
{
//HRESULT result=g_Pen->DrawTexture(g_Texture);
D3DXMATRIX Mat;
D3DXMatrixTransformation2D(&Mat, NULL, 0, NULL, &g_Texture->GetRotationCenter(), g_Texture->GetRotation(), &g_Texture->GetTranslation());
g_Sprite->Begin(0);
g_Sprite->SetTransform(&Mat);
D3DXVECTOR3 vec;
vec.x=0;
vec.y=0;
vec.z=0;
HRESULT Result = g_Sprite->Draw(g_Texture->GetTexture(), NULL, NULL ,NULL, 0xFFFFFFFF);
g_Sprite->End();


SetRect( &rc, 0, 0, 30, 30 );
g_fpsFont->DrawText( NULL, st.c_str(), -1, &rc, DT_NOCLIP, D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
// End the scene
pd3dDevice->EndScene();
}
// Present the back buffer contents to the display
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}[/code]

initliaztion of ID3DXSprite and the texture
[code]
D3DXVECTOR2 Translation;
D3DXVECTOR2 Scale;
//Create a blank surface
g_Texture = new CXTexture(pd3dDevice);

g_Texture->LoadFromFile("white.jpg");

Translation.x = 50;
Translation.y = 50;
g_Texture->SetTranslation(Translation);

Scale.x = 1;
Scale.y = 1;
g_Texture->SetScaling(Scale);

D3DXCreateSprite(pd3dDevice, &g_Sprite);[/code]

hope you can help with this problem

Share this post


Link to post
Share on other sites
ok I have found what I was doing wrong
I have set the size of the backBuffer to 800x600 while my window size was 640x480 which caused the weird scaling problem after adjusting the client area of the window to 800x600 it seems that both the scaling problem and the position problem were gone

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this