I'm running into trouble trying to figure out the best way to draw textures to the screen using Directx 11.1 (for Metro apps).

In XNA, I used SpriteBatch. Is there something partially comperable?

In the Win8 SDK examples, they used WIC and Bitmap, although it suggests that that is not the best way to draw 2D graphics with the best performance.

  • \$\begingroup\$ I really recomend you look at Allen Pestaluky's answer. An author of the XNA library ported sprite batch to D3D11 which would prably help you immensly. \$\endgroup\$ Jul 8 '13 at 20:14

In XNA, I used SpriteBatch. Is there something partially comperable?

No. Direct3D is a low-level rendering system. It's job is not to make your life easier (like XNA); it's job is to provide a bare-bones interface to graphics hardware.

You do not "draw textures" in D3D. You draw triangles, which have textures mapped onto them with shaders. Two triangles form a rectangle or "quad" (short for quadrilateral), which is how you draw textures.

To do this in D3D, you need to fill a vertex buffer with the vertex positions and texture coordinates for the triangles you want to render. You will also need a (very simple) pair of shaders, vertex and pixel, which pass your positions and texture coordinates. Your pixel shader needs to use the texture coordinate it gets from the vertex shader to fetch from the texture. And that texture's color becomes the pixel shader output.

You use all of these, the two shaders, the texture, and the vertex buffer, to render.

Low-level isn't easy, and it's not meant to be.

  • \$\begingroup\$ Thanks Nicol, could you possibly direct me to a resource to learn how to do this? \$\endgroup\$
    – kanno41
    Jan 26 '12 at 3:42
  • \$\begingroup\$ Just stop looking for D3D 11.1 information specifically. D3D 11.1 is not that different from D3D 11, which is not that different from D3D 10 with regard to how to do this. And even D3D 10 is not that different from how you do it in D3D 9 (you might use functions with slightly different names, but the principle is the same). Pretty much any resource on sprite rendering with D3D will help. \$\endgroup\$ Jan 26 '12 at 3:53

In XNA, I used SpriteBatch. Is there something partially comperable?

Now there is, yes. :) It's called the DirectX Tool Kit. Not as full-featured and mature as XNA, but it seems to get the job done and has been created by members of the orignal XNA team. Worth checking out.


Just make a bitmap and draw it:

D2D1_SIZE_U             size;
D2D1_BITMAP_PROPERTIES1 bitmapProperties;

size.width = m_width;
size.height = m_height;

bitmapProperties.bitmapOptions = D2D1_BITMAP_OPTIONS::D2D1_BITMAP_OPTIONS_NONE;
bitmapProperties.colorContext = nullptr;
bitmapProperties.dpiX = 96;
bitmapProperties.dpiY = 96;
bitmapProperties.pixelFormat.format = DXGI_FORMAT_R8G8B8A8_UNORM;
bitmapProperties.pixelFormat.alphaMode = D2D1_ALPHA_MODE::D2D1_ALPHA_MODE_PREMULTIPLIED;

m_videoDevice->GetD2DDeviceContext()->CreateBitmap(size, m_data, m_pitch, &bitmapProperties, &m_bitmap)


D2D1_RECT_F r;

r.left = 10;
r.bottom = 400;
r.right = 200;
r.top = 10;

m_videoDevice->GetD2DDeviceContext()->DrawBitmap(m_imageManager->GetImage("./Assets/starryAlpha.tga")->m_bitmap.Get(), &r);

// Ignore D2DERR_RECREATE_TARGET here. This error indicates that the device
// is lost. It will be handled during the next call to Present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.