Exemple #1
0
	LUMIX_RENDERER_API IPlugin* createPlugin(Engine& engine)
	{
		RendererImpl* r = LUMIX_NEW(engine.getAllocator(), RendererImpl)(engine);
		if (r->create())
		{
			return r;
		}
		LUMIX_DELETE(engine.getAllocator(), r);
		return nullptr;
	}
Exemple #2
0
	LUMIX_RENDERER_API IPlugin* createPlugin(Engine& engine)
	{
		RendererImpl* r = engine.getAllocator().newObject<RendererImpl>(engine);
		if (r->create())
		{
			return r;
		}
		engine.getAllocator().deleteObject(r);
		return nullptr;
	}
Exemple #3
0
ImagePtr generateAtlas(RendererImpl& rendererImpl, const std::string& filePath,
    uint32_t letterSize, Letters& letters) {

    static const auto kBorderWidth = 1u, kBorderSize = kBorderWidth * 2;
    static const auto kSpaceFactor = 0.7f;

    Context context;
    if (!context.loadFont(filePath, letterSize))
        return ImagePtr();

    auto width = 0, height = 0, heightOffset = 0;
    auto x = (double)kBorderWidth, y = 0.0;

    for (auto c : getAlphabet()) {
        auto glyph = context.getGlyph(c);
        if (!glyph)
            continue;
        if (c != kSpaceSymbol) {
            height = std::max<int32_t>(height, glyph->bounds.y2 - glyph->bounds.y1);
            heightOffset = std::min(heightOffset, glyph->bounds.y1);
        }
        x += (c == kSpaceSymbol ? kSpaceFactor : 1.0f) * glyph->advance_x + kBorderSize;
    }
    width = (int32_t)ceil(x);
    height += -heightOffset + kBorderSize;
    x = kBorderWidth;
    y = -heightOffset + kBorderWidth;

    letters.clear();
    Renderer renderer((uint32_t)width, (uint32_t)height);

    for (auto c : getAlphabet()) {
        auto glyph = context.getGlyph(c);
        if (!glyph)
            continue;
        if (c != kSpaceSymbol)
            context.renderGlyph(renderer, glyph, x, y);
        auto w = (c == kSpaceSymbol ? kSpaceFactor : 1.0f) *
             std::max(glyph->advance_x, (double)(glyph->bounds.x2 - glyph->bounds.x1));
        letters[c] = Rect((int32_t)x, 0, (int32_t)(x + w), height);
        x += w + kBorderSize;
    }
    auto atlas = rendererImpl.makeImage(
        {(uint32_t)width, (uint32_t)height}, Image::Format::A, true);
    atlas->upload(Image::Bytes(renderer.data(), renderer.size()));
    return atlas;
}