I have read a couple of articles that describe the necessity to move the texture one half unit of the vertex positions in order to get the correct mapping between texels and pixels. Though I think I understand the theory behind it, when I try to implement the the solution (moving half a unit up to the left), all I get are black lines on the opposite sides of the rendered image.
I get the impression that I either do not adjust the correct x and y parameters or that this does not apply to my particular scenario. I use direct3d 9 with linear filtering and render an image that covers the entire screen. I have tried with both the actual size of the texture and with -1 to +1 (i.e. according to the different solution in the two linked articles). Both approaches give the same effect.
My questions are, when is this correction necessary and is there a correct way to do this that I am missing?
According to DirectX documentation, offsetting by half a pixel is only necessary "when rendering 2D output using pre-transformed vertices". Pre-transformed vertices are those with
D3DFVF_XYZRHW
flag specified inIDirect3DDevice9::SetFVF
call. In order to draw a transformed vertex correctly, you have to set its position to(posx - 0.5, posy - 0.5, 0, 1)
where(posx, posy)
are screen-space coordinates of the vertex (in pixels).Here's a code for rendering a full-screen textured quad:
Of course, you need to call this function between
BeginScene()
andEndScene()
. You have also to set up the texture and sampler states properly (or shader constants).