本文整理汇总了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;
}
示例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);
//.........这里部分代码省略.........