So I'm looking into doing some 2D graphics with Direct3D 11. I am having a problem getting a simple orthographic projection to work right, and I am hoping that somebody can tell me what I may be doing wrong, or ideas of how to figure it out.

My vertex layout is a simple position/color layout, and the vertices are these:

{0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},

{1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},

{-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f}

This is my vertex shader:

cbuffer cbChangesPerFrame : register( b0 ) { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; struct VS_Input { float4 pos : POSITION; float4 color : COLOR; }; struct VS_Output { float4 pos : SV_POSITION; float4 color : COLOR; }; VS_Output main( VS_Input vertex ) { VS_Output vsOut = (VS_Output)0; vsOut.pos = mul(vertex.pos, worldMatrix); vsOut.pos = mul(vsOut.pos, viewMatrix); vsOut.pos = mul(vsOut.pos, projectionMatrix); vsOut.color = vertex.color; return vsOut; }

And this is my code to setup the constant buffer:

XMMATRIX all[3]; all[0] = XMMatrixIdentity(); all[1] = XMMatrixIdentity(); all[2] = XMMatrixOrthographicOffCenterLH( 0.0f, 600.0f, 0.0f, 400.0f, 0.1f, 100.0f ); ctx->UpdateSubresource( _constants, 0, 0, all, sizeof(XMMATRIX) * 3, 0 ); ctx->VSSetConstantBuffers( 0, 1, &_constants );

This results in a red single-pixel line being drawn from the top center of the screen, to about the center of the screen.

If I change my matrices to the following:

XMMATRIX all[3]; all[0] = XMMatrixIdentity(); all[1] = XMMatrixIdentity(); all[2] = XMMatrixIdentity();

Then the triangle renders as I expect; with one point at the top center, and the other 2 points at the bottom corners, with a red-green-blue gradient. So it would appear that the vertices are being correctly pushed to the shaders.

I have tried explicitly setting the .w position value to 1 in the vertex shader, I have tried using 4-element position values in the code, I have tried using a single matrix in the shader and multiplying them in code, and I have tried using a single matrix in the shader and just setting it to the projection matrix, all of which I figure should be the same since I'm using identity for the other 2 matrices anyway, and of course the result is the same in all cases.

What could I be missing here?

Thanks!