开发者

Drawing sprites on D3D device

开发者 https://www.devze.com 2023-01-13 03:25 出处:网络
I have a hooked DirectX used in C++ code that draws text and sprite. I tested it and it drew well onto 2D application. However, when I tried it with 3D application (some complex game actually), only t

I have a hooked DirectX used in C++ code that draws text and sprite. I tested it and it drew well onto 2D application. However, when I tried it with 3D application (some complex game actually), only text was visible. From that I deduced the sprite is not being overdrawn by something else, hence the text would be too. I set flags

    SetVertexShader(0);
    SetPixelShader(0);
    SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);

    //SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); 
    SetRenderState(D3DRS_ZENABLE, false);
    SetRenderState(D3DRS_LIGHTING, FALSE);
    SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
    SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

For some reason, ALPHABLEND caused the sprite not to be visible at all in any application, so I didn't enable it and it's commented out.

Does any fail-proof way to draw sprites over D3D exist? Otherwise, should I use different flags/values for them?

Also, which z-index should I set for the sprite in case it's really "under" some other sprites/objects?

(I'm not author of anything drawn to the device, I only have the hooked开发者_如何学JAVA DirectX API and don't even know the code of application I draw over).


Firstly, the easiest way to render sprites to a D3D device is ID3DXSprite.

Secondly, i think there's a typo and you meant to set COLOROP to MODULATE, not ALPHAOP.

However, i think in both cases you would only end up with an invisible output if your alpha was 0. Could it be that the texture you're using is fully transparent?

Also, don't forget to restore all render states you changed (directly or indirectly) after you're done with your injected render code. A simple way to do this is to capture a state block and apply it after you're done with your own rendering.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号