sprite interface help

Started by
5 comments, last by MasterWorks 18 years, 9 months ago
I am trying to write a sprite in direct3d. I am having some problems regarding how I should go about this. First, I tried to use the ID3DXSprite interface, but goes all haywire when sprites aren't a power of 2. Then I tried textured quads. They were pretransformed coordinants, but I had to lock the vertex buffer in order to move them. I suspect that if I use nontransformed coordinants, my projection matrix will make it look all distorted. From the above attempts, I am exhausted of ideas. Please help, and thanks.
Advertisement
ID3DXSprite can use textures that are not in powers of 2. If you tried to load a non-power of 2 texture with any filter other than D3DX_FILTER_NONE than yes it probably would look weird. It all depends on which filter you use and how you calculate each frames region(source rect).

For textured quads locking the vertex buffer is too slow. You have to remove the RHW component from the FVF and create an orthogonal matrix(not projection), then use the D3DXMATRIX interface to move them around.
Quote:Original post by Scet
For textured quads locking the vertex buffer is too slow. You have to remove the RHW component from the FVF and create an orthogonal matrix(not projection), then use the D3DXMATRIX interface to move them around.


This is not necessarily true... locking and unlocking the vertex buffer once and filling it with all your sprite data isn't that slow, especially if you get the NOOVERWRITE flags and such correct. In fact it's the ideal way to batch your 2D sprites. Changing the matrix for each new sprite position requires a batch (DrawPrimitive...) for every sprite, which can be slow.

Quote:Original post by MasterWorks
This is not necessarily true... locking and unlocking the vertex buffer once and filling it with all your sprite data isn't that slow


I meant locking it each frame which was what he was doing. Of course the vertex buffer must be locked at least once to load to data into it, but that should be it.

I mean every frame. If you have dynamic data you should have a dynamic vertex buffer that is locked and filled every frame.
Thanks for all your help! I'm going to use the ID3DXSprite interface because it is easy and I want to get some stuff up and going quickly. Which is faster: ID3DXSprite or using my old technique with dynamic vertex buffers?
Quote:Original post by ProgrammingNerd
Thanks for all your help! I'm going to use the ID3DXSprite interface because it is easy and I want to get some stuff up and going quickly. Which is faster: ID3DXSprite or using my old technique with dynamic vertex buffers?


ID3DXSprite is 'highly optimized' is the typical response to your basic question, but you CAN achieve greater speed if you have some sort of special case that would allow a cheaper implementation... or, maybe you need more features...

This topic is closed to new replies.

Advertisement