2012-04-12 123 views
0

我想这个C++的Direct3D功能德尔福转换,但我有麻烦..转换Direct3D的C++函数德尔福

HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32) 
{ 
    if(FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL))) 
     return E_FAIL; 

    WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12) 
      |(WORD)(((colour32>>20)&0xF)<<8) 
      |(WORD)(((colour32>>12)&0xF)<<4) 
      |(WORD)(((colour32>>4)&0xF)<<0); 

    D3DLOCKED_RECT d3dlr; 
    (*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0); 
    WORD *pDst16 = (WORD*)d3dlr.pBits; 

    for(int xy=0; xy < 8*8; xy++) 
     *pDst16++ = colour16; 

    (*ppD3Dtex)->UnlockRect(0); 

    return S_OK; 
} 

这是我的德尔福转换函数错误:

function GenerateTexture(pD3Ddev: IDirect3DDevice9; ppD3Dtex: IDirect3DTexture9; colour32: dword):HRESULT; 
var 
colour16: word; 
d3dlr: D3DLOCKED_RECT; 
pDst16: pword; 
xy: integer; 
begin 
if failed(pD3Ddev.CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, nil)) then result := E_FAIL; 

colour16 := (word(((colour32 shr 28)and $F) shl 12) 
      or word((((colour32 shr 20)and $F) shl 8)) 
      or word((((colour32 shr 12)and $F) shl 4)) 
      or word((((colour32 shr 4)and $F) shl 0))); 

    ppD3Dtex.LockRect(0, d3dlr, 0, 0); 
    pDst16 := PWORD(d3dlr.pBits); 
    xy:=0; 
    while xy<(8*8) do begin 
    Inc(pDst16^); 
    pDst16^ := color16; //THIS IS THE LINE WITH ERROR: '('Expected but ';' found. 
    inc(xy); 
    end; 
    ppD3Dtex.UnlockRect(0); 

    Result := S_OK; 
end; 

我想我将一些错误,但我不知道是什么...

谁能帮助,我呢?谢谢

+4

colour16的拼写错误也许? – 2012-04-12 16:23:07

+0

LOL ...哈哈,谢谢..我没有注意..其余的都没问题?一切正确转换? – paulohr 2012-04-12 16:28:20

+0

我认为TheVedge在他的答案中得到了答案。 – 2012-04-12 16:30:32

回答

2

你的变量叫colour16,而不是color16。

您还有其他更高的错误。请记住,在C,返回立即退出功能,这是不是在德尔福的情况下,所以你会想是这样的,如果失败的呼叫:

if failed(pD3Ddev.CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, nil)) then 
begin 
    result := E_FAIL; 
    Exit; 
end; 
+0

谢谢! 其余的转换是否正确? – paulohr 2012-04-12 16:31:45

+0

据我可以告诉,但你确实有LockRect上的编译警告(第三个参数应该是一个指针,而不是一个int) – ESG 2012-04-12 16:36:30

1

只是一个很小的事情,我注意到:公司(pDst16 ^)应该低于赋值,因为C++版本使用后增值符号,而不是预增值。

0
function GenerateTexture(pD3Ddev: IDirect3DDevice9; ppD3Dtex: IDirect3DTexture9; colour32: dword):HRESULT; 
var 
    colour16: word; 
    d3dlr: D3DLOCKED_RECT; 
    pDst16: pword; 
    xy: integer; 
begin 
    if Failed(pD3Ddev.CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, nil)) then 
    begin 
     result := E_FAIL; 
     Exit; 
    end; 
    colour16 := (word(((colour32 shr 28)and $F) shl 12) 
     or word((((colour32 shr 20)and $F) shl 8)) 
     or word((((colour32 shr 12)and $F) shl 4)) 
     or word((((colour32 shr 4)and $F) shl 0))); 

    ppD3Dtex.LockRect(0, d3dlr, nil, 0); 
    pDst16 := PWORD(d3dlr.pBits); 
    xy:=0; 
    while xy<(8*8) do begin 
     Inc(pDst16^); 
     pDst16^ := colour16; 
     Inc(xy); 
    end; 
    ppD3Dtex.UnlockRect(0); 
    Result := S_OK; 
end;