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


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

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


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

示例1: tex

FTGlyph::FTGlyph(FileStream & stream, char * data,
                 int x_offset, int y_offset,
                 int tex_width, int tex_height)
: tex(0)
{
    charcode = stream.read_uint32();
    float x1, y1, x2, y2;
    x1 = stream.read_float();
    y1 = stream.read_float();
    x2 = stream.read_float();
    y2 = stream.read_float();
    bBox = FTBBox(x1, y1, x2, y2);
    float advance_x, advance_y;
    advance_x = stream.read_float();
    advance_y = stream.read_float();
    advance = FTPoint(advance_x, advance_y);
    float corner_x, corner_y;
    corner_x = stream.read_float();
    corner_y = stream.read_float();
    corner = FTPoint(corner_x, corner_y);
    width = stream.read_int32();
    height = stream.read_int32();

    char * glyph = new char[width*height];
    stream.read(glyph, width * height);

    if (width && height) {
        if (y_offset + height > tex_height) {
            // copy subimage
            height = tex_height - y_offset;
        }
        if (height >= 0) {
            for (int y = 0; y < height; ++y) {
                for (int x = 0; x < width; ++x) {
                    char c = glyph[y * width + x];
                    data[(y + y_offset) * tex_width + x + x_offset] = c;
                }
            }
        }
    }

#ifdef USE_OUTLINE
    uv[0].X(float(x_offset - 1) / float(tex_width));
    uv[0].Y(float(y_offset - 1) / float(tex_height));
    uv[1].X(float(x_offset + width + 1) / float(tex_width));
    uv[1].Y(float(y_offset + height + 1) / float(tex_height));
#else
    uv[0].X(float(x_offset) / float(tex_width));
    uv[0].Y(float(y_offset) / float(tex_height));
    uv[1].X(float(x_offset + width) / float(tex_width));
    uv[1].Y(float(y_offset + height) / float(tex_height));
#endif

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

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