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


C++ CTexture::load方法代码示例

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


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

示例1:

IResource* createObjFromName<CTexture>(const std::string& name) {
	CTexture* texture = new CTexture;
	//TODO: find locale texture
	//auto p = name.find_last_of(".");
	//if (p == std::string::npos) {
	//	return nullptr;
	//}
	//std::string name_locale = name + GameController->GetLanguage();
	//if (!texture->load(name_locale.c_str())) {
	if (!texture->load(name.c_str())) {
		dbg("Can't load texture %s. Will try placeholder...\n", name.c_str());
		delete texture;
		// try to load a placeholder...
		texture = new CTexture;
		if (!texture->load("textures/missing.dds")) {
			fatal("Can't load texture %s\n", name.c_str());
			delete texture;
			texture = nullptr;
		}
	}
	//}
	if (texture) texture->setName(name.c_str());
	return texture;
}
开发者ID:DopaminaInTheVein,项目名称:ItLightens,代码行数:24,代码来源:texture.cpp

示例2: pageSize

CFont::CFont(CXMLTreeNode& fontNode, CGUI* gui)
    : CNamed(fontNode)
    , m_glyphs( MAX_GLYPHS_BATCH )
    , m_gui(gui)
    , m_textAlign(Rectf::Alignment::TOP_LEFT)
{
    auto mm = CEngine::GetSingleton().getMaterialManager();
    auto tm = CEngine::GetSingleton().getTextureManager();

    std::string fontFile = fontNode.GetPszProperty("path", "", false);
    std::string fontName = fontNode.GetPszProperty("name", "", false);
    DEBUG_ASSERT(fontFile.size() != 0 && fontName.size() != 0);
    if (fontFile.size() == 0 || fontName.size() == 0)
    {
        return;
    }

    for (int i = 0; i < fontNode.GetNumChildren(); ++i)
    {
        auto matNode = fontNode(i);
        if (matNode.GetName() == std::string("material"))
        {
            std::string matName = "font-material-" + fontName;
            CMaterial *mat = new CMaterial(matNode);
            mat->setName(matName);
            mm->add(matName, mat);
            m_material = mat;
            break;
        }
    }

    std::string fontPath;
    size_t pathEnd = fontFile.find_last_of('\\');
    if (pathEnd == fontFile.npos)
    {
        pathEnd = fontFile.find_last_of('/');
    }

    if (pathEnd != fontFile.npos)
    {
        fontPath = fontFile.substr(0, pathEnd+1);
    }

    CXMLTreeNode ff;
    if (!ff.LoadFile(fontFile.c_str()))
    {
        DEBUG_ASSERT(false);
        return;
    }

    CXMLTreeNode font = ff["font"];

    CXMLTreeNode common = font["common"];

    CXMLTreeNode info = font["info"];

    Vect2f pageSize(common.GetFloatProperty("scaleW", 0, false), common.GetFloatProperty("scaleH", 0, false));

    m_fontSize = info.GetFloatProperty( "size", 0, false );

    DEBUG_ASSERT( m_fontSize != 0);

    m_lineHeight = common.GetFloatProperty( "lineHeight", m_fontSize, false );

    m_base = common.GetFloatProperty( "base", m_fontSize, false );

    CXMLTreeNode pages = font["pages"];

    for (int i = 0; i < pages.GetNumChildren(); ++i)
    {
        auto page = pages(i);
        if (page.GetName() == std::string("page"))
        {
            std::string texFile = page.GetPszProperty("file", "", false);
            DEBUG_ASSERT(texFile.size() > 0);
            texFile = fontPath + texFile;
            CTexture *tex = new CTexture();
            tex->load(texFile, false);
            tm->add(tex->getName(), tex);
            m_pages.push_back(tex);
        }
    }

    auto chars = font["chars"];

    for (int i = 0; i < chars.GetNumChildren(); ++i)
    {
        auto ch = chars(i);
        if (ch.GetName() != std::string("char"))
        {
            continue;
        }
        uchar chId = ch.GetIntProperty("id");

        CharDesc_t cdesc;
        cdesc.offset = Vect2f(ch.GetFloatProperty("xoffset", 0, false), ch.GetFloatProperty("yoffset", 0, false));
        cdesc.page = ch.GetIntProperty("page");
        cdesc.size = Vect2f(ch.GetFloatProperty("width", 0, false), ch.GetFloatProperty("height", 0, false));
        cdesc.xAdvance = ch.GetFloatProperty("xadvance", 0, false);

//.........这里部分代码省略.........
开发者ID:rcrmn,项目名称:mastervj-basic-engine,代码行数:101,代码来源:Font.cpp


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