I need to draw a tilemap for a 2d game. For that I created vertices with their relative positions already hard baked. The coordinates start top-left with (0f, 0f) and z is always 0.
I rendered them to the rendertarget
with the following view matrix (world and projection are both Identity
):
Matrix view = Matrix.CreateOrthographic(this.miniMapRenderTarget.Width, this.miniMapRenderTarget.Height, 0, 1)
* Matrix.CreateScale((float)(this.miniMapRenderTarget.Width / (this.map.Size.X * this.map.TileSize.X * 2)))
* Matrix.CreateTranslation(-0.5f, -0.5f, 0);
I noticed that all stuff was just rendered to the top-right quadrant of the texture so I added a translation of -0.5 for x and y. This works find, so far.
The only bug still is that Y seem to be displayed inverted, so top is bottom. I tried to fix this by multiplying Matrix.CreateScale(1, -1, 1)
to the matrix but then I do not see anything rendered to the texture. I guess I am doing something fundamentally wrong here and the matrix has to be constructed in a different way?