Theories for 2D engine with D3D

Started by
7 comments, last by GameDev.net 19 years, 4 months ago
I'm designing a new 2D graphics engine using DirectGraphics, and I need a little advice as to which approach may give the best results. I actually have two issues I'm addressing right now, so I'll list them separately. 1. Textures I have been thinking of alternatives to using a single texture for each image and the best I could come up with is this: Each image is stored in a D3DSurface. A single, large (512x512) texture could be used as a mechanism for rendering the individual surfaces. i.e. The texture would be set as dynamic, and each surface would be copied to it, as needed, before rendering. My biggest issue with this is: How widely supported are dynamic textures? And would the cost of obtaining the surface-interface of the texture outweigh the alternative method's constant calls to SetTexture()? 2. FVF structures vs. Vertex Buffers Since I need to do a lot of batch rendering to reduce the number of calls to DrawPrimitive(), I'll be using dynamic buffers. My question is, which is a faster way of transforming the vertex data before storing it in the batch-buffer? Should I use VertexBuffers for all objects and call ProcessVertices(), or should I use the defined FVF structures and perform the transformations myself. Thanks in advance.
Advertisement
I would say stick to ID3DXSprite, it is very fast and optimized as of DX9, is directly supported by DX, offers all the functionality of the card that you can think of wanting. And it will always be compatible with any card you might think of.

I would say, if you don't intend to make a killer-fast engine, which doesn't seem to be the case I would say, stick to ID3DXSprite, it offers everything you are likely to need.

...And btw, why would you want to store all textures in 512x512-textures? Why not allocate multiple textures for each image, and just combine the smaller into a larger one.

And for using SetTexture(), but, don't you still have to get the surface before you can set the rendertarget (which SetTexture would operate from). Because you don't want to use the backbuffer as an intermediate surface?


You misunderstood my intent with the textures issue, but it's a moot point anyway. I did some testing and found the method too slow.

I looked into D3DXSprite and was very impressed. It seems it has greatly improved since DirectX8 and I may think of using it now. Thanks.

However, many parts of my engine cannot utilize D3DXSprite for various reasons. So my second question still stands, awaiting any answers or advice.
I'm not sure I understand your question. If you are in 2D then there are no transformations so why use ProcessVertices()?
Also why do you want to create a surface each time you render? Surely the same set of sprites will be used each frame (more or less).
As I said, issue no. 1 is resolved, it was just a theory and it failed.

YES, there ARE transformations, whether it's 3D, 2D or even 1D. That is what it is called when you move a point from one spot to another. My question is: Should I keep the vertex data in FVF structures and do the transformations using the D3DX libraries, or should I keep the vertex data in VertexBuffers and use ProcessVertices(). Keep in mind, I will probably want to support non-T&L hardware.

EDIT: Wait, your right =) I'm thinking of TRANSFORMATIONS. Doh! Ah well. I would still use ProcessVertices() because I'm using 3D cordinates(for a 2D game, heh) and thus projecting the images.

VertexBuffer
typedef class _OBJECT{LPDIRECT3DVERTEXBUFFER9 Verts;}OBJECT;



or FVF?
typedef class _OBJECT{CustomVert[NUM_VERTS] Verts;}OBJECT;

Where "CustomVert" is an FVF structure.

[Edited by - lack o comments on December 2, 2004 10:45:50 AM]
I'm curious about your second question - particularly, I don't understand why you need to batch a lot and reduce the calls to DrawPrimitive(). If you could elaborate a bit on why this is the case (animation? lots of little objects? what?) it'd be helpful.

-Mezz
I'm curious as to why you're using 3D coordinates for a 2D game?
Just out of interest, what is the intended application of your 2D engine?
I think you are being unclear about FVF structures & Vertex Buffers, they are generally the same thing, - or at least both are used.

Are you trying to say something about keeping vertices in a vertex array like;
MyCustomVert[] = {
{x,y,z,color}
{x,y,z,color}
{x,y,z,color}
}

and changing those x,y & z values directly each time,
or do you mean after createvertexbuffer(..) (where you use memcpy)..
and then using SetMatrix() to move etc?
if so try D3DXVec2TransformCoord or D3DXVec2TransformCoordArray for the matrices.






This topic is closed to new replies.

Advertisement