ID3DXSprite isn't drawing in the expected postion

Started by
0 comments, last by XDarkAngelX 12 years, 11 months ago
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
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 );
}


initliaztion of ID3DXSprite and the texture

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);


hope you can help with this problem
Advertisement
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

This topic is closed to new replies.

Advertisement