I am trying to render to a texture in DirectX 11 (C++ API) using an orthographic projection matrix. In the horizontal dimension, I am taking advantage of the "projection" that occurs, but in the vertical dimension, I am wanting my vertices to map directly to a specific texel row.
I have created a texture that is 128x128. I set it as my render target and set up a viewport as follows:
D3D11_VIEWPORT textureViewport;
textureViewport.TopLeftX = 0.0f;
textureViewport.TopLeftY = 0.0f;
textureViewport.Height = 128.0f;
textureViewport.Width = 128.0f;
textureViewport.MinDepth = 0.0f;
textureViewport.MaxDepth = 1.0f;
I provide a projection matrix created like this:
XMMATRIX projection = XMMatrixOrthographicOffCenterLH(50.0f, 250.0f, 128.0f, 0.0f, 256.0f, 0.0f);
Notice my left and right values do not match my texture width, but the bottom to top values do match the height. With this I would expect that if my vertex shader transforms a coordinate with a Y-value of 0.0f using the above projection matrix for SV_Position, it would be drawn to the top row of the texture. A coordinate with a Y-value of 127.0f would be drawn to the bottom row of the texture.
However, after giving it data that I would expect to fill the entire texture (I'm drawing many vertices as a point list), the bottom row of my texture is blank. And I notice the top row of my texture doesn't appear to contain the vertices I expect it to. It seems like everything is shifted up a row (or a partial row).
I have read the page on the DirectX 10 Coordinate System, but I must not be fully understanding this. I thought this was telling me that I don't have to offset anything by 0.5 like you would have to in DirectX 9. But maybe I have that backwards?
What's the proper way to control what texel row my vertices get drawn to?
I don't know if this is any consequence, but I will note that I am not ever rendering this texture to the screen. I am saving the texture to an image file.