本文整理汇总了C++中CCTextureAtlas::initWithTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTextureAtlas::initWithTexture方法的具体用法?C++ CCTextureAtlas::initWithTexture怎么用?C++ CCTextureAtlas::initWithTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTextureAtlas
的用法示例。
在下文中一共展示了CCTextureAtlas::initWithTexture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initWithImageInfo
bool CCMeshImage::initWithImageInfo(CCMeshImageInfo* info)
{
bool error_found = false;
for (std::vector<CCMeshSliceInfo>::iterator slice = info->slices.begin();
slice != info->slices.end(); slice++)
{
CCTextureAtlas* atlas = NULL;
CCTextureAtlasMap::iterator atlas_it = m_atlas_map.find(slice->texture_id);
if (atlas_it == m_atlas_map.end())
{
std::string tex_filename = info->id2tex[slice->texture_id];
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(tex_filename.c_str());
if (!texture)
{
error_found = true;
break;
}
texture->setAliasTexParameters();
atlas = new CCTextureAtlas();
atlas->initWithTexture(texture, 15);
m_atlas_map[slice->texture_id] = atlas;
}
else
{
atlas = atlas_it->second;
}
if (atlas->getTotalQuads() == atlas->getCapacity())
{
atlas->resizeCapacity(atlas->getCapacity() * 1.5f + 1);
}
CCSize tex_size = atlas->getTexture()->getContentSize();
float left = slice->texture_pos.x / tex_size.width;
float right = left + slice->size.width / tex_size.width;
float top = slice->texture_pos.y / tex_size.height;
float bottom = top + slice->size.height / tex_size.height;
float ele_pos_left = slice->image_pos.x / info->scale_ratio;
float ele_pos_top = (slice->image_pos.y + slice->size.height) / info->scale_ratio;
float ele_width = slice->size.width / info->scale_ratio;
float ele_height = slice->size.height / info->scale_ratio;
ccV3F_C4B_T2F_Quad quad;
if (slice->rotated)
{
quad.bl.texCoords.u = left;
quad.bl.texCoords.v = top;
quad.br.texCoords.u = left;
quad.br.texCoords.v = bottom;
quad.tl.texCoords.u = right;
quad.tl.texCoords.v = top;
quad.tr.texCoords.u = right;
quad.tr.texCoords.v = bottom;
}
else
{
quad.bl.texCoords.u = left;
quad.bl.texCoords.v = bottom;
quad.br.texCoords.u = right;
quad.br.texCoords.v = bottom;
quad.tl.texCoords.u = left;
quad.tl.texCoords.v = top;
quad.tr.texCoords.u = right;
quad.tr.texCoords.v = top;
}
quad.bl.vertices.x = (float) (ele_pos_left);
quad.bl.vertices.y = ele_pos_top - ele_height;
quad.bl.vertices.z = 0.0f;
quad.br.vertices.x = (float)(ele_pos_left + ele_width);
quad.br.vertices.y = ele_pos_top - ele_height;
quad.br.vertices.z = 0.0f;
quad.tl.vertices.x = (float)(ele_pos_left);
quad.tl.vertices.y = ele_pos_top;
quad.tl.vertices.z = 0.0f;
quad.tr.vertices.x = (float)(ele_pos_left + ele_width);
quad.tr.vertices.y = ele_pos_top;
quad.tr.vertices.z = 0.0f;
atlas->updateQuad(&quad, atlas->getTotalQuads());
}
if (!error_found)
{
m_name = new CCString(info->name);
setAnchorPoint(ccp(0, 0));
setContentSize(CCSize(info->size.width / info->scale_ratio, info->size.height / info->scale_ratio));
// shader stuff
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
//m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
}
return !error_found;
}