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


C++ FileStream::read_uint16方法代码示例

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


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

示例1: textureWidth

FTTextureFont::FTTextureFont(FileStream & stream)
: textureWidth(0), textureHeight(0), xOffset(0), yOffset(0), padding(3)
{
    glyphList = new FTGlyphContainer(this);

    size = stream.read_uint16();
    flags = stream.read_uint16();
    width = stream.read_float();
    height = stream.read_float();
    ascender = stream.read_float();
    descender = stream.read_float();
    numGlyphs = stream.read_int32();

    glyphHeight = std::max(1, int(height + 0.5f));
    glyphWidth = std::max(1, int(width + 0.5f));

    int tex_size = 1024;

    // Texture width required for numGlyphs glyphs. Will probably not be
    // large enough, but we try to fit as many glyphs in one line as possible
    textureWidth = ClampSize(glyphWidth * numGlyphs + padding * 2,
                             tex_size);

    // Number of lines required for that many glyphs in a line
    int tmp = (textureWidth - (padding * 2)) / glyphWidth;
    tmp = tmp > 0 ? tmp : 1;
    tmp = (numGlyphs + (tmp - 1)) / tmp; // round division up

    // Texture height required for tmp lines of glyphs
    textureHeight = ClampSize(glyphHeight * tmp + padding * 2,
                              tex_size);

    char * data = new char[textureWidth*textureHeight]();

    xOffset = yOffset = padding;

    for (int i = 0; i < numGlyphs; i++) {
        FTGlyph * glyph = new FTGlyph(stream, data, xOffset, yOffset,
                                      textureWidth, textureHeight);
        glyphList->Add(glyph, glyph->charcode);

        if (xOffset > (textureWidth - glyphWidth)) {
            xOffset = padding;
            yOffset += glyphHeight;

            if (yOffset > (textureHeight - glyphHeight)) {
                std::cout << "Cannot fit glyphs in texture!" << std::endl;
                break;
            }
        }

        xOffset += int(glyph->BBox().Upper().X() -
                       glyph->BBox().Lower().X() + padding + 0.5);
    }

    tex = Render::create_tex(data, Render::L, textureWidth, textureHeight);
    Render::set_filter(tex, true);

    GlyphVector::iterator it;
    for (it = glyphList->glyphs.begin(); it != glyphList->glyphs.end(); ++it) {
        FTGlyph * glyph = *it;
        if (glyph == NULL)
            continue;
        glyph->tex = tex;
    }

    delete[] data;
}
开发者ID:joaormatos,项目名称:anaconda,代码行数:68,代码来源:font.cpp


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