From af653e7bcff55e77b1aad8868f55a148cd53d6af Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sun, 13 Mar 2016 16:19:03 +0100 Subject: [PATCH] Code cleanup --- distancefieldfonts/distancefieldfonts.cpp | 44 +++-------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/distancefieldfonts/distancefieldfonts.cpp b/distancefieldfonts/distancefieldfonts.cpp index b7d2889f..b2a759ff 100644 --- a/distancefieldfonts/distancefieldfonts.cpp +++ b/distancefieldfonts/distancefieldfonts.cpp @@ -65,9 +65,6 @@ void parsebmFont() std::ifstream fstream(filename); assert(fstream.good()); - // todo : from texture - const uint32_t texdim = 512; - while (!fstream.eof()) { std::string line; @@ -304,26 +301,13 @@ public: // todo : function fill buffer with quads from font - void generateQuad() + // Creates a vertex buffer containing quads for the passed text + void generateText(std:: string text) { - // Setup vertices for a single uv-mapped quad - /* -#define dim 1.0f - std::vector vertexBuffer = - { - { { dim, dim, 0.0f },{ 1.0f, 1.0f } }, - { { -dim, dim, 0.0f },{ 0.0f, 1.0f } }, - { { -dim, -dim, 0.0f },{ 0.0f, 0.0f } }, - { { dim, -dim, 0.0f },{ 1.0f, 0.0f } } - }; -#undef dim -*/ std::vector vertexBuffer; std::vector indexBuffer; uint32_t indexOffset = 0; - std::string text = "Vulkan"; - float w = textures.fontSDF.width; float posx = 0.0f; @@ -365,6 +349,7 @@ public: float advance = ((float)(charInfo->xadvance) / 36.0f); posx += advance; } + indices.count = indexBuffer.size(); // Center for (auto& v : vertexBuffer) @@ -373,23 +358,6 @@ public: v.pos[1] -= 0.5f; } - /* -#define dim 1.0f - int charId = 'V'; - float w = textures.fontSDF.width; - float sstart = fontChars[charId].x / w; - float send = (fontChars[charId].x + fontChars[charId].width) / w; - float tstart = fontChars[charId].y / w; - float tend = (fontChars[charId].y + fontChars[charId].height) / w; - std::vector vertexBuffer = - { - { { dim, dim, 0.0f },{ send, tend } }, - { { -dim, dim, 0.0f },{ sstart, tend } }, - { { -dim, -dim, 0.0f },{ sstart, tstart } }, - { { dim, -dim, 0.0f },{ send, tstart } } - }; -#undef dim -*/ createBuffer( VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, vertexBuffer.size() * sizeof(Vertex), @@ -397,10 +365,6 @@ public: &vertices.buf, &vertices.mem); - // Setup indices - // std::vector indexBuffer = { 0,1,2, 2,3,0 }; - indices.count = indexBuffer.size(); - createBuffer( VK_BUFFER_USAGE_INDEX_BUFFER_BIT, indexBuffer.size() * sizeof(uint32_t), @@ -720,7 +684,7 @@ public: VulkanExampleBase::prepare(); parsebmFont(); loadTextures(); - generateQuad(); + generateText("Vulkan"); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout();