سؤال

I have an application that, to this point, is mostly DirectX 10 3D graphics. Now we are wanting to generate some real-time 2D images to display on a portion of the screen. The 2D graphics will be generated by using raw data coming in from an external piece of hardware - each value will be translated into a pixel color and position.

I have looked at Direct2D integration options, but I don't see a straightforward way to draw to a surface pixel-by-pixel, but rather just common lines and shapes.

I believe it would also be possible to do this with just Direct3D (no use of Direct2D), and just have a simple vertex for each pixel and draw it in orthogonal view.

Does using Direct2D improve efficiency at all when generating real-time 2D graphics? I am not wanting to use the shape tools so that is not really a selling point for me. Are there any other common practices for generating 2D graphics within a Direct3D application that would work better?

Any pointers would be greatly appreciated. Thank you.

هل كانت مفيدة؟

المحلول

The normal approach for drawing 2D graphics (UI etc.) in a D3D application is to store any bitmap image data you need in textures and draw textured 2D quads to display it. This gives you hardware acceleration of scaling, rotation, filtering, etc. for free.

If you want pixel accurate reproduction of your source images you'll need to ensure you take the screen resolution into account and draw your quads with the correct vertex positions. This is easier in Direct3D 10 than it was in Direct3D 9.

نصائح أخرى

The answer to your question is Textured 2D quads

Simply create a vertex shader with the following vertices:

(0.0f, 0.0f, 0.0f, 0.0f, 1.0f),
(0.0f, 1.0f, 0.0f, 0.0f, 0.0f),
(1.0f, 1.0f, 0.0f, 1.0f, 0.0f),
(1.0f, 0.0f, 0.0f, 1.0f, 1.0f)

Vertex layout (Position x, Position y, Position z, Texture Coord x, Texture Coord y).

And the appropriate index buffer.

Then simply bind the appropriate texture as a shader resource and a matrix to translate/rotate/scale the quad as you want. In the vertex shader transform the vertices position using the matrix and in the pixel shader sample the shader resource congaing the texture.

If you want to update the texture simply Map() it, update whatever pixels you want, Unmap() it and bind it again to the pixel shader.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top