After some learning I am able to answer my own question.
As Zdd and Roger mentioned in comments, issue was caused by back-side culling, or rather incorrect order of vertices making triangles viable for culling. Back-Side Culling is testing triangle for visibility in quite simple way: vertices of triangle must be positioned clockwise around center of figure in order for it to be deemed visible.
There are two possible solutions.
- Change Culling mode to accept incorrect order of vertices, but it results in reduced performance.
- Change order of vertices to appropriate one, which require preparations before drawing
To check if vertices are in clockwise order it is enough to do a bit of math, and if result is False simply flip around A and C. Result depends on Z axis direction.
bool TestTriangle(VertexPositionColor A, VertexPositionColor B, VertexPositionColor C)
{
float crossz = (B.position.x - A.position.x) * (C.position.y - B.position.y) - (B.position.y - A.position.y) * (C.position.x - B.position.x);
// for Left Hand z axis
return !(crossz > 0.0f);
// for Right Hand z axis
return (crossz > 0.0f);
}
For axis-aligned rectangles vertices can be created in correct order from start
void DrawRect(int x, int y, int h, int w, XMFLOAT4 brush)
{
VertexPositionColor A, B, C, D;
// set color
D.color = C.color = B.color = A.color = brush;
//Z index manipulation can be used to position figure above/below other drawings
D.position.z = C.position.z = B.position.z = A.position.z = 0;
// clockwise aligned vertices
A.position.x = x; B.position.x = x + w;
D.position.x = x; C.position.x = x + w;
// DirectX Y axis starts from bottom left corner (as in cartesian coordinates system and in opposite to WinApi Top/Left coord system)
A.position.y = y + h; B.position.y = y + h;
D.position.y = y; C.position.y = y;
//m_batch is PrimitveBatch from Directx Toolkit
m_batch->DrawQuad(A, B, C, D);
}