Drawing 2d Images(sprites I guess)

Started by
2 comments, last by Nik02 12 years ago
I am a little confused on the proper way to go about drawing sprites. Using ID3DXSprite, it seems to use the fixed function pipeline. How well does this work in a purely programmable pipeline? Will d3dxsprite draw with transparency ontop of the back buffer image that was put together using shaders? Would it be better to create my own image format?

My rendering pipeline is a deferred one, but after I compile my final scene, can I just sprite->Draw() on top of it, and transparency will magically work? What file format is good to use?????

A little guidance is all I am looking for.

I am programming in c++ and directx9. Thanks!

WE REQUIRE ADDITIONAL QUESTION MARKS!
Advertisement
Fixed pipeline is emulated in modern hardware anyway.

It is perfectly acceptable to mix fixed function and shader processing in D3D9 during same frame. Mixing the two can cause problems if you try to match depth precision and such between them, but this shouldn't be an issue here. Think of the fixed pipeline as a pre-compiled, simple shader combination (because it basically is just that).

Niko Suni

Ok, that is reassuring, but what if I were using something like Dx11? Are ID3DXSprite's still used in Dx11(and there ffpp), or is there a different more preferred method? I ask because I would like to stay current, and be able to someday upgrade(or add) Dx11, without having to redo my entire image system. I am creating a UI system right now, and part of that would be sprites(as well as 3D objects).
In D3D11, you don't even have a fixed function pipeline smile.png

Sprite functionality is relatively easy to do:

On initialize:

  • allocate a vertex buffer large enough to hold estimated amount of triangles to hold your sprite quads; also, create index buffer to ease sorting of geometry
  • allocate a quad list that holds structs of texture pointer + triangle indices for quads (two triangles per sprite)

On Begin:

  • clear the internal lists of your sprite

On Draw (given quad, transformation and texture pointer):

  • Push the quad geometry to your vertex buffer after transforming it; also, push it to your quad list so you can implement sorting by texture
  • Optional: sort quad list now

On End/Flush:

  • (if you didn't sort at Draw,) Sort your quad list by texture pointer (to avoid swapping texture for each quad)
  • Push the newly sorted quad indices to the index buffer; this avoids shuffling the vertex data itself
  • Submit your vertex and index buffer to the device
  • Issue state set and draw calls to the device as needed

On End:

  • (optionally) Restore device state you captured during Begin

These are the basics; in particular, the last step of the Flush/End should be implemented according to your specific needs.

Niko Suni

This topic is closed to new replies.

Advertisement