当前位置: 首页>>代码示例>>C++>>正文


C++ VertexRange::isEmpty方法代码示例

本文整理汇总了C++中VertexRange::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexRange::isEmpty方法的具体用法?C++ VertexRange::isEmpty怎么用?C++ VertexRange::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexRange的用法示例。


在下文中一共展示了VertexRange::isEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawText

void Font::drawText(vec2 pen, vec4 color, const char* text)
{
  uint vertexCount = 0;

  // Realize vertices for glyphs
  {
    const size_t length = std::strlen(text);
    m_vertices.resize(length * 6);

    for (const char* c = text;  *c != '\0'; )
    {
      const uint32 codepoint = utf8::next<const char*>(c, text + length);
      const Glyph* glyph = findGlyph(codepoint);
      if (!glyph)
      {
        glyph = findGlyph(0xfffd);
        if (!glyph)
          continue;
      }

      pen = round(pen);

      if (all(greaterThan(glyph->size, vec2(0.f))))
      {
        const Rect pa(pen + glyph->bearing - vec2(0.5f), glyph->size);
        const Rect ta(glyph->offset + vec2(0.5f), glyph->size);

        m_vertices[vertexCount + 0].texcoord = ta.position;
        m_vertices[vertexCount + 0].position = pa.position;
        m_vertices[vertexCount + 1].texcoord = ta.position + vec2(ta.size.x, 0.f);
        m_vertices[vertexCount + 1].position = pa.position + vec2(pa.size.x, 0.f);
        m_vertices[vertexCount + 2].texcoord = ta.position + ta.size;
        m_vertices[vertexCount + 2].position = pa.position + pa.size;

        m_vertices[vertexCount + 3] = m_vertices[vertexCount + 2];
        m_vertices[vertexCount + 4].texcoord = ta.position + vec2(0.f, ta.size.y);
        m_vertices[vertexCount + 4].position = pa.position + vec2(0.f, pa.size.y);
        m_vertices[vertexCount + 5] = m_vertices[vertexCount + 0];

        vertexCount += 6;
      }

      pen += vec2(glyph->advance, 0.f);
    }
  }

  if (!vertexCount)
    return;

  VertexRange range = m_context.allocateVertices(vertexCount,
                                                 Vertex2ft2fv::format);
  if (range.isEmpty())
  {
    logError("Failed to allocate vertices for text drawing");
    return;
  }

  range.copyFrom(m_vertices.data());

  m_pass.setUniformState(m_colorIndex, color);
  m_pass.apply();

  m_context.render(PrimitiveRange(TRIANGLE_LIST, range));
}
开发者ID:elmindreda,项目名称:Nori,代码行数:64,代码来源:Font.cpp


注:本文中的VertexRange::isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。