在directx9中使用RECT选取图形的问题

leafank 2009-07-26 02:08:13
我自己做了个纹理,每frame的大小是40*40,但是在代码中,要正确绘制每个frame,left与right,top与bottom的差都必须设为64,这是什么原因?我使用40就得不到完整的那个frame,导致动画错误
...全文
96 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
taxi 2009-07-26
  • 打赏
  • 举报
回复
你的显卡不支持non power of two纹量。
tkminigame 2009-07-26
  • 打赏
  • 举报
回复
你可以把图片做成64*64,然后在设置顶点uv的时候设置到40的位置,不是1.0.
leafank 2009-07-26
  • 打赏
  • 举报
回复
原来如此,谢谢了
IONPhantom 2009-07-26
  • 打赏
  • 举报
回复
power of two 就是 2的幂,比如说 2的2次方 8次方 10次方,以前的硬件在纹理上有限制,纹理的大小必须是 Power of two , 比方说 64 就是 2的6次方, 40就不是 2 的幂, 所以出问题
leafank 2009-07-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 taxi 的回复:]
你的显卡不支持non power of two纹量。
[/Quote]
不太明白,我用demo里的64*64的tga纹理就是正常的,但是自己的做的40*40的就不可以。是不是只能用64*64或者128*128这样的?
leafank 2009-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tkminigame 的回复:]
你可以把图片做成64*64,然后在设置顶点uv的时候设置到40的位置,不是1.0.
[/Quote]
不是太懂,这个1.0是在哪里设的?下面是我的代码
void Render()
{
// Clear the back buffer
HRESULT hr=gD3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,255,0),1.0f,0);
if (FAILED(hr))
return;

// Begin the scene
hr=gD3dDevice->BeginScene();
if (SUCCEEDED(hr))
{
// Draw with alpha blending - needed for our transparent sprites
gSprite->Begin(D3DXSPRITE_ALPHABLEND);

if(count == 5)count=0;

// Now draw all the cavemen, fill a rect to select the area of the texture to draw
for (int i=0;i<kNumCavemen;i++)
{
RECT drawRect;

drawRect.left = 1*64;
drawRect.right = 1*64+64;

drawRect.top= 0;

drawRect.bottom=drawRect.top+64;

D3DXVECTOR3 pos;
if(count != 0)
posX += 16;
if(posX > 800)
posX -= 800;
pos.x = posX;
if(count ==0||count == 4)
{
pos.y = 100 ;
}
else if(count == 1|| count == 3)
{
pos.y = 100 - 8;
}
else if(count == 2)
{
pos.y = 100 - 12;
}
pos.z = 0;

// This is the other method of using the sprite interface. We do not set a matrix
// transformation but just use the parameters to pass in the position. This is fine
// when we do not need to rotate or scale the graphic
gSprite->Draw(gTexture,&drawRect,NULL,&pos,0xffffffff);
}

// Finished drawing. By reusing the same sprite object D3D can maximise batching of the draws
gSprite->End();

// Finished rendering
gD3dDevice->EndScene();
gD3dDevice->Present(NULL,NULL,NULL,NULL);
count++;
}
}

/**************************************************************************************************
Desc: To initialise DirectX we must create the Direct3D object and then a device
**************************************************************************************************/
bool InitialiseDirectX(HWND hWnd)
{
// Create the D3D object
gD3dObject=Direct3DCreate9(D3D_SDK_VERSION);
if (gD3dObject==NULL)
return FALSE;

// Fill out some presentation parameters for running in a window
D3DPRESENT_PARAMETERS presParams;
ZeroMemory(&presParams,sizeof(presParams));

presParams.Windowed=TRUE;
presParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat=D3DFMT_UNKNOWN;
presParams.BackBufferCount=1;

// Create the D3D device
HRESULT hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
{
// Some cards may not do hardware vertex processing so fall back to software:
hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
return FALSE;
}

return TRUE;
}

/**************************************************************************************************
Desc: Our application is finishing so we must clean up by deallocating any DirectX objects
Evey DirectX object has a release function to call
**************************************************************************************************/
void CleanupDirectX()
{
if (gTexture)
gTexture->Release();

if (gSprite)
gSprite->Release();

if (gD3dObject)
gD3dObject->Release();

if (gD3dDevice)
gD3dDevice->Release();
}

/**************************************************************************************************
Desc: Create our sprite object. Return FALSE if an error occured.
Note: We only use one sprite object as this is the most efficient way of doing it. The sprite object
is purely a mechanism for drawing 2D graphics. By using just one and doing all our drawing between
begin and end Direct3D can batch the rendering of the textures most efficiently
**************************************************************************************************/
bool CreateSprite()
{
HRESULT hr=D3DXCreateSprite(gD3dDevice,&gSprite);
if (FAILED(hr))
return FALSE;

// Load a cavemen texture
D3DXCreateTextureFromFile(gD3dDevice,"d:\\slime.tga",>exture);


return TRUE;
}


void UpdateWorld(HWND hWnd)
{
DWORD timeNow=timeGetTime();


if (timeNow-lastUpdate>kTimeBetweenUpdated)
{
act = TRUE;
lastUpdate=timeNow;
}
}

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧