| 121 | } |
| 122 | |
| 123 | void Font::Typeset(int32_t viewportWidth, int32_t viewportHeight, int32_t x, int32_t y, |
| 124 | Vector4<float> const& color, std::string const& message) const |
| 125 | { |
| 126 | // Get texel translation units, depends on viewport width and height. |
| 127 | float const vdx = 1.0f / static_cast<float>(viewportWidth); |
| 128 | float const vdy = 1.0f / static_cast<float>(viewportHeight); |
| 129 | |
| 130 | // Get texture information. |
| 131 | float tw = static_cast<float>(mTexture->GetWidth()); |
| 132 | float th = static_cast<float>(mTexture->GetHeight()); |
| 133 | |
| 134 | // Get vertex buffer information. |
| 135 | uint32_t vertexSize = mVertexBuffer->GetFormat().GetVertexSize(); |
| 136 | char* data = mVertexBuffer->GetData(); |
| 137 | |
| 138 | float x0 = 0.0f; |
| 139 | uint32_t const length = std::min( |
| 140 | static_cast<uint32_t>(message.length()), mMaxMessageLength); |
| 141 | for (uint32_t i = 0; i < length; ++i) |
| 142 | { |
| 143 | // Get character data. |
| 144 | int32_t c = static_cast<int32_t>(message[i]); |
| 145 | float const tx0 = mCharacterData[c]; |
| 146 | float const tx1 = mCharacterData[c + 1]; |
| 147 | float charWidthM1 = (tx1 - tx0)*tw - 1.0f; // in pixels |
| 148 | |
| 149 | // 0 -- 2 4 -- 6 ... |
| 150 | // | \ | | \ | |
| 151 | // | \ | | \ | |
| 152 | // 1 -- 3 5 -- 7 ... |
| 153 | size_t const fourI = 4 * static_cast<size_t>(i); |
| 154 | float* v0 = reinterpret_cast<float*>(data + (fourI + 0)*vertexSize); |
| 155 | float* v1 = reinterpret_cast<float*>(data + (fourI + 1)*vertexSize); |
| 156 | float* v2 = reinterpret_cast<float*>(data + (fourI + 2)*vertexSize); |
| 157 | float* v3 = reinterpret_cast<float*>(data + (fourI + 3)*vertexSize); |
| 158 | |
| 159 | // Set bottom left vertex y coordinate. |
| 160 | v1[1] = vdy * th; |
| 161 | |
| 162 | // Set x-coordinates. |
| 163 | float x1 = x0 + charWidthM1 *vdx; |
| 164 | v0[0] = x0; |
| 165 | v1[0] = x0; |
| 166 | v2[0] = x1; |
| 167 | v3[0] = x1; |
| 168 | |
| 169 | // Set bottom right-side y-coordinate. |
| 170 | v3[1] = vdy * th; |
| 171 | |
| 172 | // Set the four texture x-coordinates. The y-coordinates were set in |
| 173 | // the constructor. |
| 174 | v0[2] = tx0; |
| 175 | v1[2] = tx0; |
| 176 | v2[2] = tx1; |
| 177 | v3[2] = tx1; |
| 178 | |
| 179 | // Update left x coordinate for next quad |
| 180 | x0 = x1; |
no test coverage detected