I think I must be using the wrong wording for what I want, because I seached and just kept finding pixel shader questions. But this seems like something that anyone making a 2D game would want.

Basically I have my quad, my loaded texture in a ID3D11ShaderResourceView and I can draw it to the screen using coordinates of -1.0 to 1.0.

But what I want to accomplish is drawing based on pixels.


I would want to draw a 20x20 pixel image to coordinates 100,100 on a 800x600 screen. But, I want to do this by manipulating the quad to the correct size and position to mimic this (which is, I assume, a common way to do 2D in DirectX11).

As I said, I am able to draw a texture to screen space at the moment but I am lost as to what calculations or methods would be required to convert this to pixel-based drawing.

Thank you :)

  • \$\begingroup\$ multiple 0.0->1.0 with the width of your texture. in other words. 1 / 800 = some where between 0->1 wich corresponds to one pixel of 800 pixels. from there you can multiply and add what ever you need to your uv cordinates. \$\endgroup\$
    – Tordin
    May 5, 2014 at 12:32

1 Answer 1


The normal way to do this would be to create a matrix representing the transformation from game world coordinates to screen coordinates. Note that I never mention resolution here because it does not come in to play directly. For such a projection the only thing important is the aspect ration.

In your vertex shader you would just multiply the input position with the matrix and output the new position to your pixel shader. Alternatively if you are not using shaders (or well, if they are hidden from you) you could apply the matrix manually to each vertex before you send it to the graphics device.

How to create such a matrix requires just a few calculations on paper. For example: if your game world coordinates are from 0~100 and your screen coordinates are -1~1 you would need to scale by 0.02 and translate by -1.0 (in that order). Remember that you can combine multiple successive matrix operations by pre-multiplying the matrices.

  • \$\begingroup\$ Ok, I am now using the XMMatrixTranslation, Scaling and RotationAxis along with the texture width/height and screen width/height to draw to the screen and that seems to be working fine. One problem that remains is that as my resolution gets larger, the texture gets fuzzier even though the size of the quad is scaled down. Right now my quad starts as a full -1.0 to 1.0 quad and the scaled size is sent to the shader. \$\endgroup\$
    – Nexian
    May 5, 2014 at 15:03
  • \$\begingroup\$ Just to clarify. I think the texture thinks it will be drawing to the full -1 to 1 coordinates (the full screen) and then the quad gets scaled down after. So the larger the screen size, the blurrier the texture. But the vertex shader outputs the correct, smaller scale. \$\endgroup\$
    – Nexian
    May 5, 2014 at 15:31
  • \$\begingroup\$ Ok. This is apparently to do with my base resolution 800x600 while allowing the screen to be re-sized. So I suppose my question here would be, what is the best way to update your screen resolution for directx 11? I mean, I know the depth stencil and swapchain both hold width and height of my screen. Is there a method that updates all this resolution data or do I need to update each aspect manually? \$\endgroup\$
    – Nexian
    May 5, 2014 at 16:08
  • \$\begingroup\$ I think you need to update each aspect manually as they all have their separate buffers. Also what texture sampling setting are you using? \$\endgroup\$
    – Roy T.
    May 5, 2014 at 20:33
  • \$\begingroup\$ tbh I don't think I am doing it in the best way as I have to transform by scale first. i.e. my quad is a -1 to 1 quad (covers the whole screen), I scale it to match the texture width and height in pixels and then transform it using the screen resolution and the object's position. I then set the world space as Scale * Transformation * Rotation (as I have to scale it as an initial action). Sampler values (low on characters) are: D3D11_FILTER_MIN_MAG_MIP_LINEAR; D3D11_TEXTURE_ADDRESS_WRAP; D3D11_TEXTURE_ADDRESS_WRAP; D3D11_TEXTURE_ADDRESS_WRAP; D3D11_COMPARISON_NEVER; D3D11_FLOAT32_MAX; \$\endgroup\$
    – Nexian
    May 7, 2014 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .