Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class BitmapFont
  2. {
  3. public:
  4. enum Align {Left, Center, Right};
  5. BitmapCharacterSet m_charSet;
  6. std::map<int, FontQuad> m_quads;
  7. StringBlock* m_strings;
  8. char* m_fntFile;
  9. char* m_textureFile;
  10. ID3D11ShaderResourceView *m_texture;
  11. ID3D11Buffer *m_vb;
  12. int MaxVertices = 4096;
  13. int m_nextChar;
  14. int stringCount = 1;
  15. int indexCount;
  16. DWORD* tempIndices;
  17.  
  18. void Render(ID3D11DeviceContext* devcontext, ID3D11Buffer* iBuffer)
  19. {
  20. if (m_quads.size() == 0)
  21. return;
  22. UINT stride = sizeof(TL_VERTEX);
  23. UINT offset = 0;
  24. int size = (m_quads.size()) * 6;
  25. int numVertices = 0;
  26. D3D11_MAPPED_SUBRESOURCE ms;
  27. devcontext->Map(m_vb, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
  28. for (int i = 0; i < m_quads.size(); i++)
  29. {
  30. memcpy(&ms.pData + (i - 1 * sizeof(m_quads[i].m_vertices)), &m_quads[i].m_vertices, sizeof(m_quads[i].m_vertices));
  31. numVertices = numVertices + (sizeof(TL_VERTEX) * 6);
  32. }
  33. //std::cout << sizeof(ms.pData) << std::endl;
  34. devcontext->Unmap(m_vb, NULL);
  35. devcontext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset);
  36. devcontext->PSSetShaderResources(0, 1, &m_texture);
  37. if (indexCount < size)
  38. {
  39. indexCount = size;
  40. std::cout << "IndexCount is smaller! " << indexCount << " | " << size << std::endl;
  41. tempIndices = new DWORD[indexCount];
  42. for (int i = 0; i < indexCount; i = i + 6)
  43. {
  44. //std::cout << i << std::endl;
  45. tempIndices[i] = i;
  46. tempIndices[i + 1] = i + 1;
  47. tempIndices[i + 2] = i + 2;
  48. tempIndices[i + 3] = i + 3;
  49. tempIndices[i + 4] = i + 4;
  50. tempIndices[i + 5] = i + 5;
  51. }
  52. }
  53.  
  54. D3D11_MAPPED_SUBRESOURCE is;
  55. devcontext->Map(iBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &is);
  56. memcpy(is.pData, &tempIndices, sizeof(tempIndices));
  57. devcontext->Unmap(iBuffer, NULL);
  58. devcontext->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0);
  59. //std::cout << sizeof(m_quads) << std::endl;
  60. //devcontext->DrawIndexed(6, 0, 0);
  61. devcontext->DrawIndexed(numVertices, 0, 0);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement