Batching With Vertex Buffer

Started by
6 comments, last by Evil Steve 13 years, 6 months ago
I'm trying to figure out a way to batch sprites with a dynamic vertex buffer. But, the problem is that each sprite has a different texture. Is there a way to draw each sprite with the correct texture using 1 vertex buffer in Directx9 (C++)?
Advertisement
One vertex-buffer, yes, but not one draw-call. Each Draw or DrawIndexed call has a vertex-start index, which lets you decide which vertex in the buffer is the first to use. So you could store 2 triangles in the same vertex buffer of 6 vertices, and use 2 different Draw-calls where the first draws the first 3 vertices and the second the last 3 vertices.
If you want to use a single Draw-call, then you must use the same texture. You could build a texture-atlas where you put all your textures side by side into a larger texture for example.
So, how do I make a texture atlas?
Quote:Original post by justin12343
So, how do I make a texture atlas?


you could start by reading the publications of Hugues Hoppe, or save a few brain cells and use the D3D9 UV Atlas API.
Hmmm, this is rather for 3D meshes.

If all your textures have the same size, a uniform grid does the trick. If not, google for "rectangle packing". Either way you need a way to combine your images into one and calculate the corresponding (new) tex-coords. For the former you could abuse DX, but a image library or GDI+ is likely easier to use. Don't know but there are probably also tools for that (or GIMP/PhotoShop plugins).
Quote:Original post by unbird
Hmmm, this is rather for 3D meshes.


Oh yeah, i didn't see the "sprite" thing. Just saw "texture atlas" and first reaction was Hoppe and D3D UVAtlas :)
Hmmm, sounds complicated. I may just go with d3dxsprite or something if I can't figure this out.
Quote:Original post by justin12343
Hmmm, sounds complicated. I may just go with d3dxsprite or something if I can't figure this out.
Is there any reason you're not going with ID3DXSprite? It's about the fastest and easiest you're going to get...

This topic is closed to new replies.

Advertisement