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


C++ CCTextureAtlas::getTexture方法代码示例

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


在下文中一共展示了CCTextureAtlas::getTexture方法的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;
}
开发者ID:guozanhua,项目名称:ImageCropper,代码行数:99,代码来源:CCMeshImage.cpp


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