本文整理汇总了C++中ogre::MaterialPtr::compile方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialPtr::compile方法的具体用法?C++ MaterialPtr::compile怎么用?C++ MaterialPtr::compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MaterialPtr
的用法示例。
在下文中一共展示了MaterialPtr::compile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static void
SubEntity_tintColour(
SubEntity* self,
const String& groupName,
const String& materialName,
const Ogre::ColourValue& colour
) {
Ogre::MaterialPtr baseMaterial = Ogre::MaterialManager::getSingleton().getByName(materialName);
Ogre::MaterialPtr materialPtr = baseMaterial->clone(groupName);
materialPtr->compile();
Ogre::TextureUnitState* ptus = materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
ptus->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, colour);
self->setMaterial(materialPtr);
}
示例2: createMaterial
Ogre::MaterialPtr OgrePlanarReflectionMaterial::createMaterial(const Ogre::TexturePtr& texture, const Ogre::Camera& projectionCamera)
{
using namespace::Ogre;
Ogre::MaterialPtr matPtr = MaterialManager::getSingleton().create(this->getName(),"General");
Ogre::TextureUnitState* t;
if(! textureFilename.getValue().empty() )
{
t = matPtr->getTechnique(0)->getPass(0)->createTextureUnitState(textureFilename.getValue());
}
t = matPtr->getTechnique(0)->getPass(0)->createTextureUnitState(texture->getName() );
t->setColourOperationEx(Ogre::LBX_BLEND_MANUAL, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT,
Ogre::ColourValue::White, Ogre::ColourValue::White,
blendingFactor.getValue());
t->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
t->setProjectiveTexturing(true,&projectionCamera);
matPtr->compile();
return matPtr;
}
示例3: ReloadMaterial
void ReloadMaterial(const std::string& materialName, const std::string& groupName, const std::string& filename, bool parseMaterialScript)
{
if (materialName.empty())
{
Ogre::LogManager::getSingleton().logMessage("Material name is empty.");
return;
}
if (groupName.empty())
{
Ogre::LogManager::getSingleton().logMessage("Group name is empty.");
return;
}
if (filename.empty())
{
Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
return;
}
UnloadMaterials(filename);
UnloadVertexPrograms(filename);
UnloadFragmentPrograms(filename);
if (parseMaterialScript)
{
Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename);
if(!stream.isNull())
{
try
{
Ogre::MaterialManager::getSingleton().parseScript(stream, groupName);
Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialName);
if (!materialPtr.isNull())
{
materialPtr->compile();
materialPtr->load();
}
}
catch (Ogre::Exception &e)
{
StringUtil::StrStreamType msg;
msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
Ogre::LogManager::getSingleton().logMessage(msg.str());
}
}
stream->close();
///
/// RELOAD MATERIAL SCRIPT CONTENTS
///
stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename);
if(!stream.isNull())
{
try
{
///
/// RELOAD ALL MATERIAL CONTENTS IN FILE
///
while(!stream->eof())
{
std::string line = stream->getLine();
StringUtil::trim(line);
///
/// RELOAD MATERIALS
///
if (StringUtil::startsWith(line, "material"))
{
Ogre::vector<Ogre::String>::type vec = StringUtil::split(line," \t:");
bool skipFirst = true;
for (Ogre::vector<Ogre::String>::type::iterator it = vec.begin(); it < vec.end(); ++it)
{
if (skipFirst)
{
skipFirst = false;
continue;
}
std::string match = (*it);
StringUtil::trim(match);
if (!match.empty())
{
LoadResource(Ogre::MaterialManager::getSingletonPtr(), match, groupName);
break;
}
}
}
///
/// RELOAD VERTEX PROGRAMS
///
if (StringUtil::startsWith(line, "vertex_program") && !StringUtil::startsWith(line, "vertex_program_ref"))
{
Ogre::vector<Ogre::String>::type vec = StringUtil::split(line," \t");
bool skipFirst = true;
for (Ogre::vector<Ogre::String>::type::iterator it = vec.begin(); it < vec.end(); ++it)
{
if (skipFirst)
{
skipFirst = false;
continue;
}
//.........这里部分代码省略.........
示例4: frameStarted
//.........这里部分代码省略.........
if ( crowdMember.mbReversing )
{
crowdMember.mFrameIdx--;
if ( crowdMember.mFrameIdx < 0 )
{
crowdMember.mFrameIdx = 1;
crowdMember.mbReversing = false;
}
}
else
{
crowdMember.mFrameIdx++;
if ( crowdMember.mFrameIdx >= NUM_FRAMES_TO_RECORD )
{
crowdMember.mFrameIdx = NUM_FRAMES_TO_RECORD-1;
crowdMember.mbReversing = true;
}
}
}
// Check to see if we can stop recording
if ( mbRecording )
{
mRecordingFrameIdx++;
if ( mRecordingFrameIdx >= NUM_FRAMES_TO_RECORD )
{
// Create a new crowd member
Ogre::Image image;
image.loadDynamicImage(
mpImageData, SMALL_FRAME_WIDTH, NUM_FRAMES_TO_RECORD*SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );
std::stringstream ss;
ss << "RecordedSequenceTex_" << numCrowdMembers;
Ogre::String texName = ss.str();
Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr();
Ogre::TexturePtr pTexture = pTextureMgr->loadImage( texName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image );
ss.clear();
ss << "RecordedSequenceMat_" << numCrowdMembers;
Ogre::String matName = ss.str();
Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr();
Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
Ogre::MaterialPtr pMat = pSrcMat->clone( matName ); // (Ogre::MaterialPtr)pMatMgr->create( matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState( texName, 0 );
pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );
/*Ogre::Technique* pTech = pMat->getTechnique( 0 );
pTech->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
Ogre::Pass *pPass = pTech->createPass();
pPass->setLightingEnabled( false );
pPass->setAmbient( 1.0, 1.0, 1.0 );
pPass->setDiffuse( 1.0, 1.0, 1.0, 1.0 );
pPass->setSpecular( 0.0, 0.0, 0.0, 0.0 );
Ogre::ColourValue val(0.0f, 0.0f, 0.0f, 1.0f);
pPass->setSelfIllumination(val);
//pPass->setE ( 0.0, 0.0, 0.0, 0.0 );
pPass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
pPass->setDepthWriteEnabled( false );
Ogre::TextureUnitState* pTex = pPass->createTextureUnitState( texName, 0 );
pPass->addTextureUnitState( pTex );
pTex->setColourOperation( Ogre::LBO_MODULATE );*/
pMat->setCullingMode( Ogre::CULL_NONE );
pMat->compile();
CrowdMember crowdMember;
crowdMember.mMaterialName = matName;
crowdMember.mFrameIdx = 0;
crowdMember.mColourIdx = rand()%NUM_COLOURS;
crowdMember.mbReversing = false;
int32_t rowIdx = rand()%NUM_ROWS;
float angle = MIN_CROWD_ANGLE + ((float)rand()/(float)RAND_MAX)*(MAX_CROWD_ANGLE-MIN_CROWD_ANGLE);
float x = ROW_DEPTHS[ rowIdx ]*sin( angle );
float z = ROW_DEPTHS[ rowIdx ]*cos( angle );
crowdMember.mPos = Ogre::Vector3( x, ROW_HEIGHTS[ rowIdx ], z );
mCrowdMembers.push_back( crowdMember );
mbRecording = false;
mRecordingGapTimer.reset(); // Reset time so that there's a gap between recording
printf( "Got frame\n" );
}
}
return true;
}
示例5: OnLoadTexture
//-----------------------------------------------------------------------
void MaterialTab::OnLoadTexture(wxCommandEvent& event)
{
// Add a new directory and parse all resources in that directory
wxFileDialog loadDialog(this,
_("Load a texture"),
wxT(""),
wxT(""),
_("Textures (*.*)|*.*"),
wxFD_OPEN,
wxDefaultPosition,
wxDefaultSize, _("Load"));
if (loadDialog.ShowModal() == wxID_OK)
{
SetCursor(*wxHOURGLASS_CURSOR);
Ogre::TextureUnitState* tut = 0;
// User has pressed ok, so load the texture
Ogre::String fileName = wx2ogre(loadDialog.GetFilename());
Ogre::String path = wx2ogre(loadDialog.GetPath());
Ogre::String baseName; // should be the same as fileName
Ogre::String extension;
Ogre::String dir;
Ogre::StringUtil::splitFullFilename(path, baseName, extension, dir);
// Validate the extension
Ogre::String types = "bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2,pfm,pct,pict,pic,bay,bmq,cr2,crw,cs1,dc2,dcr,dng,erf,fff,hdr,k25,kdc,mdc,mos,mrw,nef,orf,pef,pxn,raf,raw,rdc,sr2,srf,arw,3fr,cine,ia,kc2,mef,nrw,qtk,rw2,sti,drf,dsc,ptx,cap,iiq,rwz,dds";
Ogre::StringUtil::toLowerCase(extension);
if (types.find(extension) == Ogre::String::npos)
return; // Unsupported format
// Load the resource
Ogre::ResourceGroupManager::getSingletonPtr()->removeResourceLocation(dir, TEMP_TEXTURE_GROUP);
Ogre::ResourceGroupManager::getSingletonPtr()->addResourceLocation(dir, "FileSystem", TEMP_TEXTURE_GROUP);
Ogre::ResourceGroupManager::getSingletonPtr()->clearResourceGroup(TEMP_TEXTURE_GROUP);
Ogre::ResourceGroupManager::getSingletonPtr()->initialiseResourceGroup(TEMP_TEXTURE_GROUP);
Ogre::TextureManager::getSingleton().prepare(fileName, TEMP_TEXTURE_GROUP);
Ogre::TextureManager::getSingleton().load(fileName, TEMP_TEXTURE_GROUP);
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(fileName, TEMP_TEXTURE_GROUP);
if (!texture.isNull())
{
// Set the texture name
tut = forceCreateFirstTexture(fileName); // Return texture unit state
if (tut)
{
tut->setName(fileName);
mTxtTextureLoad->SetValue(loadDialog.GetFilename());
}
// Compile the material
wxString materialName = mMaterialListBox->GetStringSelection();
Ogre::String name = wx2ogre(materialName);
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
if (!material.isNull())
{
material->compile();
}
mResourceLocationTexture = ogre2wx(dir);
}
// Display image
viewTexture(tut); // Clear the old texture if no TextureUnitState
SetCursor(wxNullCursor);
}
}
示例6: createNewCrowdMember
void OgreCPP::createNewCrowdMember( float animationTime )
{
char buffer[ 512 ];
uint32_t numCrowdMembers = mCrowdMembers.size();
// Create a new crowd member
Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr();
Ogre::String frameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
Ogre::String lowResFrameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
{
Ogre::Image image;
image.loadDynamicImage( mpImageData + frameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT,
SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );
sprintf( buffer, "RecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
frameTexNames[ frameIdx ] = buffer;
Ogre::TexturePtr pTexture = pTextureMgr->loadImage( frameTexNames[ frameIdx ],
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image );
sprintf( buffer, "LowResRecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
lowResFrameTexNames[ frameIdx ] = buffer;
Ogre::Image lowResImage;
lowResImage.loadDynamicImage( mpLowResImageData + frameIdx*LOW_RES_SMALL_FRAME_WIDTH*LOW_RES_SMALL_FRAME_HEIGHT,
LOW_RES_SMALL_FRAME_WIDTH, LOW_RES_SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );
pTextureMgr->loadImage( lowResFrameTexNames[ frameIdx ],
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, lowResImage );
}
for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
{
frameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = frameTexNames[ frameIdx ];
lowResFrameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = lowResFrameTexNames[ frameIdx ];
}
// Create materials for the crowd member
sprintf( buffer, "RecordedSequenceMat_%i", numCrowdMembers );
Ogre::String matName = buffer;
Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr();
Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
Ogre::MaterialPtr pMat = pSrcMat->clone( matName );
pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );
pTex->setAnimatedTextureName( frameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );
pMat->setCullingMode( Ogre::CULL_NONE );
pMat->compile();
sprintf( buffer, "LowResRecordedSequenceMat_%i", numCrowdMembers );
Ogre::String lowResMatName = buffer;
pMat = pSrcMat->clone( lowResMatName );
pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );
pTex->setAnimatedTextureName( lowResFrameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );
pMat->setCullingMode( Ogre::CULL_NONE );
pMat->compile();
CrowdMember newCrowdMember;
newCrowdMember.mMaterialName = matName;
newCrowdMember.mLowResMaterialName = lowResMatName;
newCrowdMember.mFrameIdx = 0;
newCrowdMember.mColourIdx = rand()%NUM_COLOURS;
newCrowdMember.mbReversing = false;
num = mCrowdMembers.size()%11;
/** POSITION CROWD MEMBER HERE **/
float x = (num*(5.0/11.0))-2.25;
float y = 1.5;
/* centre is 0,0, extremes are -3,+3 */
newCrowdMember.mPos = Ogre::Vector3( x, y, 5.0 );
newCrowdMember.mRow = 0;
newCrowdMember.mpBillboard = OGRE_NEW PersonBillboard();
newCrowdMember.mpBillboard->setMaterial( newCrowdMember.mMaterialName );
newCrowdMember.mpBillboard->setCorners(
Ogre::Vector3( -0.5f, -0.375f, 0.0f ),
Ogre::Vector3( 0.5f, -0.375f, 0.0f ),
Ogre::Vector3( -0.5f, 0.375f, 0.0f ),
Ogre::Vector3( 0.5f, 0.375f, 0.0f )
);
// Make sure that the front row is drawn in front of everything else
newCrowdMember.mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE );
//.........这里部分代码省略.........
示例7: createActions
//.........这里部分代码省略.........
mNodeEditor->addNode(mMaterialNode);
}
}
//****************************************************************************/
void EditorDockWidget::doTechniqueHToolbarAction(void)
{
// Add a technique node
Magus::QtNodeTechnique* techniqueNode = new Magus::QtNodeTechnique(NODE_TITLE_TECHNIQUE);
mNodeEditor->addNode(techniqueNode);
}
//****************************************************************************/
void EditorDockWidget::doPassHToolbarAction(void)
{
// Add a pass node
Magus::QtNodePass* passNode = new Magus::QtNodePass(NODE_TITLE_PASS);
mNodeEditor->addNode(passNode);
}
//****************************************************************************/
void EditorDockWidget::doTextureHToolbarAction(void)
{
// Add a texture unit node
Magus::QtNodeTextureUnit* textureUnitNode = new Magus::QtNodeTextureUnit(NODE_TITLE_TEXTURE_UNIT);
mNodeEditor->addNode(textureUnitNode);
}
//****************************************************************************/
void EditorDockWidget::doCogHToolbarAction(void)
{
if (!mMaterialNode)
return;
if (mMaterialNode->getMaterialName().isEmpty())
return;
// ---------------------------------------- Create a material ----------------------------------------
Ogre::LogManager* logManager = Ogre::LogManager::getSingletonPtr();
Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
Ogre::String materialName = mMaterialNode->getMaterialName().toStdString(); // Convert to std format
logManager->logMessage("SME: create Ogre material: " + materialName);
Ogre::MaterialPtr material = materialManager->create(materialName, "General");
// Remark: Sceneblending is done for each pass individually, although it is defined on material level
// ---------------------------------------- Add the technique ----------------------------------------
Magus::QtNode* node = mMaterialNode->getNodeConnectedToPort(PORT_TECHNIQUE_OUT);
if (!node)
{
logManager->logMessage("SME: No technique node available");
return;
}
Magus::QtNodeTechnique* techniqueNode = static_cast<Magus::QtNodeTechnique*>(node);
material->removeAllTechniques();
Ogre::Technique* technique = material->createTechnique();
technique->removeAllPasses();
logManager->logMessage("SME: Technique created" + Ogre::StringConverter::toString(material->getNumTechniques()));
// ---------------------------------------- Add the passes ----------------------------------------
Magus::QtNodePass* passNode;
Magus::QtNodeTextureUnit* textureUnitNode;
Ogre::Pass* pass;
Ogre::TextureUnitState* textureUnit;
for (unsigned int i = 1; i < 5; ++i)
{
node = techniqueNode->getNodeConnectedToPort(PORT_PASS_OUT, i); // node with the same name
if (node)
{
passNode = static_cast<Magus::QtNodePass*>(node);
pass = technique->createPass();
pass->removeAllTextureUnitStates();
logManager->logMessage("SME: Pass on port nr. " + Ogre::StringConverter::toString(i) + " created");
propagatePassNodeData(passNode, pass);
// ---------------------------------------- Add the texture units ----------------------------------------
for (unsigned int j = 1; j < 9; ++j)
{
node = passNode->getNodeConnectedToPort(PORT_TEXTURE_OUT, j);
if (node)
{
logManager->logMessage("SME: Texture unit on port nr. " +
Ogre::StringConverter::toString(j) +
" of Pass port nr. " +
Ogre::StringConverter::toString(i) +
" created");
textureUnitNode = static_cast<Magus::QtNodeTextureUnit*>(node);
textureUnit = pass->createTextureUnitState();
propagateTextureUnitNodeData(textureUnitNode, textureUnit);
}
}
}
}
// Assign the material to the ogrehead
material->compile();
material->load();
mParent->getOgreManager()->getOgreWidget(1)->mEntity->setMaterial(material);
}