void CPickup::Initalise(CVector3f p) { m_isActive = true; m_theta = 0.0f; m_position = p; CTexture texture; // Texture - https://www.textures.com/download/cliffs0174/56219?secure=login texture.Load("Resources\\Textures\\rock.jpg", false); m_textureID = texture.m_textureID; }
bool CSkybox::Create(const char *bmpDirectory, const float fSize) { // Load textures CTexture texture; //skybox texture "grave" from redsorceress.com texture.Load("Resources\\Textures\\grave_back.bmp", true); m_textureIDs[SKYBOX_BACK_ID] = texture.m_textureID; texture.Load("Resources\\Textures\\grave_front.bmp", true); m_textureIDs[SKYBOX_FRONT_ID] = texture.m_textureID; texture.Load("Resources\\Textures\\grave_top.bmp", true); m_textureIDs[SKYBOX_BOTTOM_ID] = texture.m_textureID; texture.Load("Resources\\Textures\\grave_top.bmp", true); m_textureIDs[SKYBOX_TOP_ID] = texture.m_textureID; texture.Load("Resources\\Textures\\grave_right.bmp", true); m_textureIDs[SKYBOX_LEFT_ID] = texture.m_textureID; texture.Load("Resources\\Textures\\grave_left.bmp", true); m_textureIDs[SKYBOX_RIGHT_ID] = texture.m_textureID; return true; }
CMaterial::CMaterial(CXMLTreeNode &TreeNode) : CNamed(TreeNode) { std::string l_EffectTechnique = TreeNode.GetPszProperty("effect_technique"); m_EffectTechnique = CEngine::GetSingletonPtr()->GetEffectManager()->GetResource(l_EffectTechnique); if (l_EffectTechnique == "diffuse_technique") { for (int i = 0; i < TreeNode.GetNumChildren(); ++i) { CXMLTreeNode l_Texture = TreeNode(i); CTexture * Texture = new CTexture(); Texture->Load(l_Texture.GetPszProperty("filename")); m_Textures.push_back(Texture); } } }
bool CStaticMesh::ExtractTexture(FILE* modelFile, std::vector<CTexture*>& textVector) { assert(modelFile); uint16 length = 0; char* path; std::string sPath = ""; //Read Length of the texture path fread(&length, sizeof(uint16), 1, modelFile); path = new char[length]; memset(path, 0, length); //Read Path fread(path, 1, length, modelFile); sPath = std::string(path); CHECKED_DELETE(path); std::string texName = m_MeshName + "_" + sPath; CTexture* texture = CORE->GetTextureManager()->GetResource(texName); if(texture == NULL) { texture = new CTexture(); texture->SetName(texName); if(!texture->Load(sPath)) { CHECKED_DELETE(texture); texture = CORE->GetTextureManager()->GetNoTexture(); std::string err = "CStaticMesh::ExtractTexture->No se ha podido crear la textura: " + sPath; LOGGER->AddNewLog(ELL_WARNING, err.c_str() ); } } textVector.push_back(texture); return true; }
//-------------------------------------------------------------------------------------------------------------- CTexture* CResourceManager::_CreateTexture (LPCSTR _Name) { // DBG_VerifyTextures (); if (0==xr_strcmp(_Name,"null")) return 0; R_ASSERT (_Name && _Name[0]); string_path Name; strcpy_s (Name,_Name); //. andy if (strext(Name)) *strext(Name)=0; fix_texture_name (Name); // ***** first pass - search already loaded texture LPSTR N = LPSTR(Name); map_TextureIt I = m_textures.find (N); if (I!=m_textures.end()) return I->second; else { CTexture * T = xr_new<CTexture>(); T->dwFlags |= xr_resource_flagged::RF_REGISTERED; m_textures.insert (mk_pair(T->set_name(Name),T)); T->Preload (); if (Device.b_is_Ready && !bDeferredLoad) T->Load(); return T; } }
CTexture* CTextureResources::Load( const char* filePath, bool isCubeMap ) { int hash = CUtil::MakeHash(filePath); auto it = textureMap.find(hash); CTexture* tex = nullptr; if (it == textureMap.end()) { //�V�K tex = new CTexture; if (tex->Load(filePath, isCubeMap) ){ textureMap.insert(std::pair<int, CTexture*>(hash, tex)); } else { delete tex; return nullptr; } } else { tex = it->second; } return tex; }
CPass* CMaterialLoader::ParsePass(Json::Value& json, Json::Value& root) { const char* szVertexProgram = json["vertex_program"].asCString(); const char* szFragmentProgram = json["fragment_program"].asCString(); Json::Value& diffuseJson = json["diffuse"]; Json::Value& ambientJson = json["ambient"]; Json::Value& specularJson = json["specular"]; Json::Value& emissiveJson = json["emissive"]; Json::Value& textureUnitJson = json["texture_unit"]; // 创建颜色 CColorF diffuse = CColorF(diffuseJson[0].asFloat(), diffuseJson[1].asFloat(), diffuseJson[2].asFloat(), diffuseJson[3].asFloat()); CColorF ambient = CColorF(ambientJson[0].asFloat(), ambientJson[1].asFloat(), ambientJson[2].asFloat(), ambientJson[3].asFloat()); CColorF specular = CColorF(specularJson[0].asFloat(), specularJson[1].asFloat(), specularJson[2].asFloat(), specularJson[3].asFloat()); CColorF emissive = CColorF(emissiveJson[0].asFloat(), emissiveJson[1].asFloat(), emissiveJson[2].asFloat(), emissiveJson[3].asFloat()); // 创建纹理 CTexture* pTexture = NULL; if (!textureUnitJson.isNull()) { const char* texture = textureUnitJson["texture"].asCString(); std::string filter_mode = textureUnitJson["filter_mode"].asString(); std::string address_mode = textureUnitJson["address_mode"].asString(); pTexture = XENEW(CTexture); if (!pTexture) { return NULL; } if (filter_mode == "nearest") { pTexture->SetFilter(ITexture::E_Nearest); } else if (filter_mode == "linear") { pTexture->SetFilter(ITexture::E_Linear); } if (address_mode == "repeat") { pTexture->SetAddress(ITexture::E_Repeat); } else if (address_mode == "clamp") { pTexture->SetAddress(ITexture::E_Clamp); } if (!pTexture->Load(texture)) { XELOG("material parse pass load texture error: %s", texture); XEDELETE(pTexture); return NULL; } } // 创建program CCgProgram* pProgram = XENEW(CCgProgram); if (!pProgram) { XEDELETE(pTexture); return NULL; } // 创建vertex CCg* pVertex = ParseVertex(szVertexProgram, root); if (!pVertex) { XELOG("material parse pass load vertex error: %s", szVertexProgram); XEDELETE(pTexture); XEDELETE(pProgram); return NULL; } pProgram->AddCg(pVertex); // 创建fragment CCg* pFragment = ParseFragment(szFragmentProgram, root); if (!pFragment) { XELOG("material parse pass load fragment error: %s", szFragmentProgram); XEDELETE(pTexture); XEDELETE(pProgram); XEDELETE(pVertex); return NULL; } pProgram->AddCg(pFragment); pProgram->Compile(); // 创建pass CPass* pPass = XENEW(CPass); if (!pPass) { XEDELETE(pTexture); XEDELETE(pProgram); XEDELETE(pVertex); XEDELETE(pFragment); return NULL; } pPass->Init(pTexture, diffuse, ambient, specular, emissive, pProgram); return pPass; }