Skip to content

layouts

Alex Miyamoto edited this page Apr 23, 2018 · 2 revisions

The layouts library is almost entirely empty. The layout library was viteis 2D rendering code for menus and HUDs, unfortunately they were previously created using a proprietary tool and as such have been removed.

The code was restructured to use msdfgen to generate distance field fonts, however as there is no concept of a layout system anymore setup for rendering is quite verbose.

The class for rendering text on screen is Text.

All text needs a font resource, obtained from the resource manager. Fonts are generated from yaml defintions, in Data/Fonts, e.g.

Data\Fonts*FontName*.yml

FontName: "arial"
SourceFont: "Data/Fonts/JKG-M_3.ttf"
Size: 64
Spacing: 0.05
Bold: false 
Underscore: false
LetterList: "家族 1234567890-_+=[]{};:',./?|#@~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

A ttf file is required as a source. Letters not present in the letter list can not be rendered.

The fonts are created using msdfgen, a distance field font library. These scale up well but don't scale down so impressively, you may wish to create different font definitions for smaller text specifying a smaller size.

// Create the constant buffer describing the 2D window
m_2DConstants.Init(pDevice, usg::g_global2DCBDecl);
m_2DDescriptor.Init(pDevice, pDevice->GetDescriptorSetLayout(usg::g_sGlobalDescriptors2D));
m_2DDescriptor.SetConstantSet(0, &m_2DConstants);

// Set the 2D projection matrix to be 1280*720, with near of 0 and far of 10
usg::Global2DConstants* pConstants = m_2DConstants.Lock<usg::Global2DConstants>();
pConstants->mProjMat.Orthographic(0.0f, 1280.0f, 0.0f, 720.0f, 0.0f, 10.0f);
m_2DConstants.Unlock();
// Update the GPU side data
m_2DConstants.UpdateData(pDevice);
m_2DDescriptor.UpdateDescriptors(pDevice);

m_text.Init(pDevice, usg::RenderPassHndl());  // Init the text
m_text.SetPosition(0.0f, 0.0f); // Set to the bottom right corner
m_text.SetScale(usg::Vector2f(128.f, 128.f)); // Set the scale
const usg::Keystring* string = usg::StringTable::Inst()->Find("Test"); // Optional - grab the region specific text from the string table
m_text.SetText(string->text); // Set the text to display
m_text.SetFont(usg::ResourceMgr::Inst()->GetFont(pDevice, "FontDef")); // Get the font from the resource manager and bind to our text
// Set the colours
m_text.SetGradationEndColor(usg::Color(0.8f, 0.8f, 0.8f, 1.0f));
m_text.SetGradationStartColor(usg::Color(0.3f, 0.3f, 0.3f, 1.0f));
m_text.SetBackgroundColor(usg::Color(1.0f, 1.0f, 1.0f, 0.0f));
// Update the GPU buffers for the text box so that it can be rendered.
m_text.UpdateBuffers(pDevice);

As you can see the concept for keystrings still exists, these are defined as yaml files in Data\VPB:

KeystringTable:
  keyStrings:
  - key: "Test"
    text: "家族A Test String"
    style:
      charHeight: 12
      charSpacing: 0.05
      lineSpacing: 0.3
      displayLines: 1
      fontName: arialbd
      color: { m_fR: 1.0, m_fG: 1.0, m_fB: 1.0, m_fA: 1.0 }
      backgroundColor: { m_fR: 1.0, m_fG: 1.0, m_fB: 1.0, m_fA: 1.0 }
      tabWidth: 2.0

Unfortunately the code to apply these settings was in the now removed layout code. The text class should be modified to accept keystrings and apply all of the relevant settings automatically.

Fortunately rendering is much less verbose

pImmContext->SetDescriptorSet(&m_2DDescriptor, 0);
m_text.Draw(pImmContext);