Search code examples
c++directxresolutiondirectx-11pixel

DirectX stretched pixels


I am just starting off with directX and have run into a problem with stretched pixels. When I create the window and all the directX goodies I use two variables, width and height. For most testing I have them set to 800x600. When I draw a square on the screen it looks stretched. Res of 800x600

However when I set the resoltion to 600x600 Res of 600x600

it looks normal and square. This led me to conclude that it was some sort of pixel stretching. In directX how do I fix this, and make the pixels square.


Solution

  • float aspectRatio = bufferWidth / bufferHeight;
    

    That is completely normal. Once you project into normalized screen space, coordinates go from -1.0 to 1.0 (left to right) and -1.0 to 1.0 (bottom to top). You can see that both directions on the screen have the same range of values. This means that if you draw a square on the screen with equal height and width, it will be aspectRatio times greater in width than height. This explains the good behaviour at 600x600 but a problem at 800x600.(aspectRatio of 1.33)

    If you really want a square, what you can do is simply divide the width by your aspect ratio which in your case is 800/600 (1.33) to get a polygon of equal width and height.