Exemplo n.º 1
0
void OpenGLFontLoader::PostInitialize(ISystem *ySys, IPluginObjectInstance *pInstance) {
    Font *font;
    font = FontManager::GetInstance(ySys)->GetFont(std::string(fontName->v->string), fontSize->v->int_val);
    //textureFont = FontManager::GetInstance(ySys)->LoadBitmapFont(std::string("fontmap.fnt"));
    //new Font(std::string(font->v->string), fontSize->v->int_val, face);
    font->Build();
    outputFontObject->v->userdata = font;


}
Exemplo n.º 2
0
Font *FontManager::LoadBitmapFont(std::string filename) {
    Font *font = GetFromCache(filename, 0);	// bitmap font's have no size
    if (font != NULL) return font;

    psys->GetLogger("FontManager")->Debug("Loading bitmap font '%s'", filename.c_str());

    font = new BitmapFont(filename);
    font->Build();
    fonts.push_back(font);

    return font;
}
Exemplo n.º 3
0
Font *FontManager::LoadTrueTypeFont(std::string family, int size) {
    Font *font = GetFromCache(family, size);

    if (font != NULL) return font;

    psys->GetLogger("FontManager")->Debug("Building font '%s' with size %d (not cached), building",family.c_str(), size);
    // not cached, create new and cache
    FT_Face face;
    if(FT_New_Face(ft, family.c_str(), 0, &face)) {
        psys->GetLogger("FontManager")->Error("OpenGLDrawText, Could not open font");
        exit(1);
    }
    FT_Set_Pixel_Sizes(face, 0, size);

    font = new Font(family, size, face);
    font->Build();
    fonts.push_back(font);

    return font;
}
Exemplo n.º 4
0
    //----------------------------------------------------------------------------
    //----------------------------------------------------------------------------
    void FontProvider::LoadFont(StorageLocation in_location, const std::string& in_filePath, const ResourceProvider::AsyncLoadDelegate& in_delegate, const ResourceSPtr& out_resource)
    {
        std::string fileName, fileExtension;
        StringUtils::SplitBaseFilename(in_filePath, fileName, fileExtension);
        
        const std::string textureFilePath(fileName + "." + k_textureFileExtension);
        
        if(in_delegate == nullptr)
        {
            Font::Descriptor desc;
            desc.m_texture = Application::Get()->GetResourcePool()->LoadResource<Texture>(in_location, textureFilePath);
            if(desc.m_texture == nullptr)
            {
                out_resource->SetLoadState(Resource::LoadState::k_failed);
                return;
            }
            
            if (LoadCSFont(in_location, in_filePath, desc) == false)
            {
                out_resource->SetLoadState(Resource::LoadState::k_failed);
                return;
            }
            
            Font* font = (Font*)(out_resource.get());
            font->Build(desc);
            out_resource->SetLoadState(Resource::LoadState::k_loaded);
        }
        else
        {
            Application::Get()->GetResourcePool()->LoadResourceAsync<Texture>(in_location, textureFilePath, [=](const TextureCSPtr& in_texture)
            {
                if(in_texture != nullptr)
                {
                    Application::Get()->GetTaskScheduler()->ScheduleTask(TaskType::k_file, [=](const TaskContext&) noexcept
                    {
                        Font::Descriptor desc;
                        desc.m_texture = in_texture;
                        
                        if (LoadCSFont(in_location, in_filePath, desc) == true)
                        {
                            Font* font = (Font*)(out_resource.get());
                            font->Build(desc);
                            out_resource->SetLoadState(Resource::LoadState::k_loaded);
                        }
                        else
                        {
                            out_resource->SetLoadState(Resource::LoadState::k_failed);
                        }

                        Application::Get()->GetTaskScheduler()->ScheduleTask(TaskType::k_mainThread, [=](const TaskContext&) noexcept
                        {
                            in_delegate(out_resource);
                        });
                    });
                }
                else
                {
                    //Already on main thread
                    out_resource->SetLoadState(Resource::LoadState::k_failed);
                    in_delegate(out_resource);
                }
            });
        }
    }