CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, unsigned int capacity) { CCTextureAtlas * pTextureAtlas = new CCTextureAtlas(); if(pTextureAtlas && pTextureAtlas->initWithFile(file, capacity)) { pTextureAtlas->autorelease(); return pTextureAtlas; } CC_SAFE_DELETE(pTextureAtlas); return NULL; }
CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *texture, unsigned int capacity) { CCTextureAtlas * pTextureAtlas = new CCTextureAtlas(); if (pTextureAtlas && pTextureAtlas->initWithTexture(texture, capacity)) { pTextureAtlas->autorelease(); return pTextureAtlas; } CC_SAFE_DELETE(pTextureAtlas); return NULL; }
void _AtlasPage_createTexture (AtlasPage* self, const char* path) { CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(path); CCTextureAtlas* textureAtlas = CCTextureAtlas::createWithTexture(texture, 4); textureAtlas->retain(); self->rendererObject = textureAtlas; // Using getContentSize to make it supports the strategy of loading resources in cocos2d-x. // self->width = texture->getPixelsWide(); // self->height = texture->getPixelsHigh(); self->width = texture->getContentSize().width; self->height = texture->getContentSize().height; }
CCTextureAtlas* CCTextureAtlas::createWithTexture ( CCTexture2D* pTexture, KDuint uCapacity ) { CCTextureAtlas* pRet = new CCTextureAtlas ( ); if ( pRet && pRet->initWithTexture ( pTexture, uCapacity ) ) { pRet->autorelease ( ); } else { CC_SAFE_DELETE ( pRet ); } return pRet; }
CCTextureAtlas* CCTextureAtlas::create ( const KDchar* szFilePath, KDuint uCapacity ) { CCTextureAtlas* pRet = new CCTextureAtlas ( ); if ( pRet && pRet->initWithFile ( szFilePath, uCapacity ) ) { pRet->autorelease ( ); } else { CC_SAFE_DELETE ( pRet ); } return pRet; }
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); } } }
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; }