I started teaching myself DirectX a short time ago and have come across a problem which I can't figure out by myself unfortunately. I'm trying to build my own font system, so I can draw strings in 2D screenspace. Until now Until now I have managed to create a function to which I just have to pass the string and the screenspace-positions., and it generates all vertices for / sets up the buffers etc (quads that i draw a certain portion of the font texture on). When I draw these vertices in 3D space, everything looks like it works like it should be. Text in 3D space

(Forgot to hide the cube) As soon as I try to switch to 2D, I just get a window filled with the blue backgroundcolor. To switch to 2D I do the following things:

graphics.context->ClearDepthStencilView(graphics.depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
context->OMSetDepthStencilState(depthDisabledStencilState, 1);

WVP = XMMatrixOrthographicLH((float)mWidth, (float)mHeight, 0.0f, 1.0f);
cbPerVert.WVP = XMMatrixTranspose(WVP);
cbPerVert.World = XMMatrixTranspose(World);

context->UpdateSubresource( cbPerVertexBuffer, 0, NULL, &cbPerVert, 0, 0 );
context->VSSetConstantBuffers( 0, 1, &cbPerVertexBuffer );  

My Question is now what I am doing wrong here. If the vertices are being genrated and drawn correctly, afaik all I have to do is project them into screenspace and disable the depth buffer, which I did here.. BTW: I randomly tried drawing the cube with my 2D settings and it was properly drawn.. Help is much appreciated :)

  • \$\begingroup\$ Your font vertices could be the problem probably, if your cube is drawn correctly. (rough guess: maybe your font vertices are on the XZ plane and your projection projects to the XY plane?) \$\endgroup\$ – János Turánszki Feb 12 '14 at 21:58
  • \$\begingroup\$ Thanks for the comment. The font vertices are in the XY-Plane, and for getting the cube drawn correctly in 2D I set the z-componenents of all cube-vertices to 0. \$\endgroup\$ – user42149 Feb 12 '14 at 22:11
  • \$\begingroup\$ I doubt anyone would get you anything but guesses with so little information, I suggest you debug your code yourself. (For example you could check your font vertices after the matrix multiplication, or check with a graphics debugger) \$\endgroup\$ – János Turánszki Feb 12 '14 at 22:41
  • \$\begingroup\$ wild guess 2: Maybe you are culling the wrong side of your quads? \$\endgroup\$ – János Turánszki Feb 12 '14 at 22:48
  • 1
    \$\begingroup\$ Thanks a whole lot! Today I learned what culling is thansk to you :D Looks like I filled the vertexbuffer in such a way that I was drawing backfaces. Fixed that. Thanks! \$\endgroup\$ – user42149 Feb 12 '14 at 23:18

So the problem was the culling, I recommend to debug your code while turning off the culling with D3D11_CULL_NONE flag in the rasterizer if your geometry does not get displayed, this is quite a common problem for beginners. And be sure to cull the backfaces in a release application wherever you can.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.