MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / RenderText

Method RenderText

SampleFramework11/v1.02/Graphics/SpriteRenderer.cpp:388–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388void SpriteRenderer::RenderText(const SpriteFont& font,
389 const wchar* text,
390 const Float4x4& transform,
391 const Float4& color)
392{
393 D3DPERF_BeginEvent(0xFFFFFFFF, L"SpriteRenderer RenderText");
394
395 size_t length = wcslen(text);
396
397 Float4x4 textTransform;
398
399 uint64 numCharsToDraw = std::min(length, MaxBatchSize);
400 uint64 currentDraw = 0;
401 for(uint64 i = 0; i < numCharsToDraw; ++i)
402 {
403 wchar character = text[i];
404 if(character == ' ')
405 textTransform._41 += font.SpaceWidth();
406 else if(character == '\n')
407 {
408 textTransform._42 += font.CharHeight();
409 textTransform._41 = 0;
410 }
411 else
412 {
413 SpriteFont::CharDesc desc = font.GetCharDescriptor(character);
414
415 textDrawData[currentDraw].Transform = textTransform * transform;
416 textDrawData[currentDraw].Color = color;
417 textDrawData[currentDraw].DrawRect.x = desc.X;
418 textDrawData[currentDraw].DrawRect.y = desc.Y;
419 textDrawData[currentDraw].DrawRect.z = desc.Width;
420 textDrawData[currentDraw].DrawRect.w = desc.Height;
421 currentDraw++;
422
423 textTransform._41 += desc.Width + 1;
424 }
425 }
426
427 // Submit a batch
428 RenderBatch(font.SRView(), textDrawData, currentDraw);
429
430 D3DPERF_EndEvent();
431
432 if(length > numCharsToDraw)
433 RenderText(font, text + numCharsToDraw, textTransform, color);
434}
435
436void SpriteRenderer::End()
437{

Callers 1

EndFrameMethod · 0.45

Calls 3

SpaceWidthMethod · 0.80
CharHeightMethod · 0.80
SRViewMethod · 0.80

Tested by

no test coverage detected