如何使用 Direct3D9 缩放 IDirect3DTexture9?

How to scale IDirect3DTexture9 using Direct3D9?

ChurchSkiz 在此网页 https://www.gamedev.net/forums/topic/577397-making-a-2d-menu-in-directx/ 上提出了我的问题。 一切都很简单,但我无法理解如何缩放该纹理。 我想像游戏主菜单的图像那样做。在我看来,这只是一种缩放任何纹理以显示用户分辨率(1024x768、1920x1080 等)的方法。

我还制作了一种非通用的缩放纹理的方法。这取决于中央纹理和显示器的分辨率

// The texture are 1024x768 and my display's resolution are 1440x900.
D3DXVECTOR3 center(-200,-50, 0);

sprite_handler->Draw(KidRightTexture, nullptr, &center, nullptr, D3DCOLOR_XRGB(255, 255, 255));

有什么想法吗?另外,有没有更好的方法来绘制我的纹理?例如,也许没有精灵?我对 DirectX 很陌生。 但是当我们的显示器是 1600x1050 时,一切都变了。

您可以使用ID3DXSprite::SetTransform method. You can use it by building transformation matrix调整精灵大小、旋转和世界位置。

::D3DXMATRIX scaling_matrix;
::D3DXMATRIX rotation_matrix;
::D3DXMATRIX move_matrix;
::D3DXMATRIX intermediate_matrix;
::D3DXMATRIX final_matrix;

::D3DXMatrixScaling(&scaling_matrix, scale_x, scale_y, 1.0f);
::D3DXMatrixRotationZ(&rotation_matrix, rotation);
::D3DXMatrixTranslation(&move_matrix, x, y, 1.0f);
::D3DXMatrixMultiply(&intermediate_matrix, &scaling_matrix, &rotation_matrix);
::D3DXMatrixMultiply(&final_matrix, &intermediate_matrix, &move_matrix);

sprite_handler->SetTransform(&final_matrix);

但我必须指出,您发布的文章已过时。 D3DXSPRITE 提供的 DirectX9 和精灵基本上已弃用。