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


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

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


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

示例1: draw

void CCSkeleton::draw () {
	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc(blendFunc.src, blendFunc.dst);
	ccColor3B color = getColor();
	skeleton->r = color.r / (float)255;
	skeleton->g = color.g / (float)255;
	skeleton->b = color.b / (float)255;
	skeleton->a = getOpacity() / (float)255;

	CCTextureAtlas* textureAtlas = 0;
	ccV3F_C4B_T2F_Quad quad;
	quad.tl.vertices.z = 0;
	quad.tr.vertices.z = 0;
	quad.bl.vertices.z = 0;
	quad.br.vertices.z = 0;
	for (int i = 0, n = skeleton->slotCount; i < n; i++) {
		Slot* slot = skeleton->slots[i];
		if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
		CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
		if (regionTextureAtlas != textureAtlas) {
			if (textureAtlas) {
				textureAtlas->drawQuads();
				textureAtlas->removeAllQuads();
			}
		}
		textureAtlas = regionTextureAtlas;
		if (textureAtlas->getCapacity() == textureAtlas->getTotalQuads() &&
			!textureAtlas->resizeCapacity(textureAtlas->getCapacity() * 2)) return;
		RegionAttachment_updateQuad(attachment, slot, &quad);
		textureAtlas->updateQuad(&quad, textureAtlas->getTotalQuads());
	}
	if (textureAtlas) {
		textureAtlas->drawQuads();
		textureAtlas->removeAllQuads();
	}

	if (debugSlots) {
		// Slots.
		ccDrawColor4B(0, 0, 255, 255);
		glLineWidth(1);
		CCPoint points[4];
		ccV3F_C4B_T2F_Quad quad;
		for (int i = 0, n = skeleton->slotCount; i < n; i++) {
			Slot* slot = skeleton->slots[i];
			if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
			RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
			RegionAttachment_updateQuad(attachment, slot, &quad);
			points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y);
			points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y);
			points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y);
			points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y);
			ccDrawPoly(points, 4, true);
		}
	}
	if (debugBones) {
		// Bone lengths.
		glLineWidth(2);
		ccDrawColor4B(255, 0, 0, 255);
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			float x = bone->data->length * bone->m00 + bone->worldX;
			float y = bone->data->length * bone->m10 + bone->worldY;
			ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
		}
		// Bone origins.
		ccPointSize(4);
		ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			ccDrawPoint(ccp(bone->worldX, bone->worldY));
			if (i == 0) ccDrawColor4B(0, 255, 0, 255);
		}
	}
}
开发者ID:stnguyen,项目名称:spine-runtimes,代码行数:76,代码来源:CCSkeleton.cpp

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