Jump to content
  • Advertisement
Sign in to follow this  
XDarkAngelX

ID3DXSprite isn't drawing in the expected postion

This topic is 2593 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 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

Share this post


Link to post
Share on other sites
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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!