Archived

This topic is now archived and is closed to further replies.

Hippokrates

Sprites

Recommended Posts

If I want to use sprites (billboards) in DX Graphics, would a vertexbuffer containing a quad be a good solution? Because if I want to animate the characters I will have to change the texture coordinates and thus refill the vertex buffer. Is this a price that can be paid or do I have to use ID3DXSprite instead? (I would love to use billboards in 3D space for my characters). Im Anfang war die Tat... Faust

Share this post


Link to post
Share on other sites
Why would you have to change the texture coordinates if you animate a character? You would just change the texture. The texture is still mapped the same way (hopefully). I''m assuming you''re talking about a 2D game btw.

ID3DXSprite is just a wrapper for a "sprite". I made my own for instance (CD3DSprite which derived from my very own ISprite interface), and it just draws a billboarded textured quad to the screen at a specified place with a specified size and texture. The price for theirs is probably the same as mine but I like to see whats going on in code, and I really don''t know what their code does.

A vertex buffer would be fine to answer your question though. ID3DXSprite uses one too.

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan

Share this post


Link to post
Share on other sites
Depending on how you need to animate the characters you might want to consider moving the texture matrix instead.


D3DXMATRIX matTrans;
D3DXMatrixIdentity(&matTrans);
matTrans._31 = spriteAnimData[frameID].uOffset;
matTrans._32 = spriteAnimData[frameID].vOffset;
IDirect3DDevice8_SetTransform(m_3DDevice, D3DTS_TEXTURE0, &matTrans );


The code above can be used to scroll textured without touching the vertex buffer. If you want a lot of polys or sprites to animate the same way you can move the texture matrix once per frame before you render the sprites it should affect.

However this is expensive to do on a per sprite basis. If you need to control UVs independently for each sprite, you are better off grouping them by texture and putting them in a big buffer. The biggest performance hit comes from locking and unlocking vb data. So, lock the buffer once per frame, update the new tu, tv coordinates for all the sprites, unlock it and render.


--
Slimy


[edited by - Slimy on July 27, 2002 8:24:48 PM]

Share this post


Link to post
Share on other sites
Check oout the Donuts3d sample with the sdk. It shows one way of using a texture containing animation then billboarding them in 3d space like what you wanted..

hth,

Share this post


Link to post
Share on other sites