using D3DXSPRITE in Lite-c

Posted By: Matt_Aufderheide

using D3DXSPRITE in Lite-c - 01/19/18 03:17

I don't think sprites are drawn using d3dxsprite in A8 commercial, so I want to to try to use it in my game.. but frankly I cant figure out how to use that interface in Lite-C ....its not in the d3d9 header.. any idea?
Posted By: Kartoffel

Re: using D3DXSPRITE in Lite-c - 01/22/18 09:27

what you can do in lite-c is get the d3d device pointer (using draw_begin(), I think) and then perform drawcalls using d3d interface functions like DrawPrimitive(), DrawIndexedPrimitive() or DrawPrimitiveUp() for example. note: the last one is more of a legacy thing from dx8 iirc. it's usually pretty bad for 3d geometry, since it always streams vertex data from the ram to your graphics card when drawing. still, I have used it successfully for 2d sprite drawing (since the vertex data is tiny in that case)
Alternatively, acknex has an engine function called draw_quad() which is basically the same but with some limitations. On the other hand, that way you don't have to fiddle around with d3d9 api stuff.

also, lite-c does not include d3dx9 helpers, afaik, and d3dxsprite sounds like another helper api that's built upon d3d9. (besides that, it most likely uses the same functions as mentioned above but provides a simpler interface for them). if you desperately want to use it you'd have to create a wrapper plugin dll for lite-c.

and lastly, if you're trying to draw sprites in you 3d level, I'm not entirely sure that's possible. acknex' limitations might be a problem here.

hope that helps laugh
Posted By: Matt_Aufderheide

Re: using D3DXSPRITE in Lite-c - 01/22/18 23:35

actually it is possible.. I got it working fine. Doesn't need a DLL, just have to declare the D3DXSPRITE interface as per the d3dx headers..

then I I just create an effect from file and and do the sprite drawing in that effect pass.. all of it I bind to a view /material event.. so I can control what layer its on...

if anyone want sot to see some code...

put the following in some header...

#define D3DXSPRITE_DONOTSAVESTATE (1 << 0)
#define D3DXSPRITE_DONOTMODIFY_RENDERSTATE (1 << 1)
#define D3DXSPRITE_OBJECTSPACE (1 << 2)
#define D3DXSPRITE_BILLBOARD (1 << 3)
#define D3DXSPRITE_ALPHABLEND (1 << 4)
#define D3DXSPRITE_SORT_TEXTURE (1 << 5)
#define D3DXSPRITE_SORT_DEPTH_FRONTTOBACK (1 << 6)
#define D3DXSPRITE_SORT_DEPTH_BACKTOFRONT (1 << 7)


#undef INTERFACE
#define INTERFACE ID3DXSprite

DECLARE_INTERFACE_(ID3DXSprite, IUnknown)

{
// IUnknown
STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
STDMETHOD_(ULONG, Release)(THIS) PURE;

// ID3DXSprite
STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;

STDMETHOD(GetTransform)(THIS_ D3DXMATRIX *pTransform) PURE;
STDMETHOD(SetTransform)(THIS_ CONST D3DXMATRIX *pTransform) PURE;

STDMETHOD(SetWorldViewRH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE;
STDMETHOD(SetWorldViewLH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE;

STDMETHOD(Begin)(THIS_ DWORD Flags) PURE;
STDMETHOD(Draw)(THIS_ LPDIRECT3DTEXTURE9 pTexture, CONST RECT *pSrcRect, CONST D3DXVECTOR3 *pCenter, CONST D3DXVECTOR3 *pPosition, D3DCOLOR Color) PURE;
STDMETHOD(Flush)(THIS) PURE;
STDMETHOD(End)(THIS) PURE;

STDMETHOD(OnLostDevice)(THIS) PURE;
STDMETHOD(OnResetDevice)(THIS) PURE;
};


MY_DECLARE_INTERFACE(ID3DXSprite)
typedef ID3DXSprite *LPD3DXSPRITE;

HRESULT WINAPI

D3DXCreateSprite(
LPDIRECT3DDEVICE9 pDevice,
LPD3DXSPRITE* ppSprite);
/////////////////////////////////////////////////////////////


simply create the sprite like this

pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();
if (!pd3dDev) return(0);

//create d3dxsprite object
hr=D3DXCreateSprite(
pd3ddev,
&SPRITE
);

everything else should be straightforward...
Posted By: Kartoffel

Re: using D3DXSPRITE in Lite-c - 01/23/18 10:56

good to know, I thought d3dx stuff needed additional libraries that you couldn't use in acknex directly.

thanks for sharing
© 2024 lite-C Forums