本文整理汇总了C++中ogre::TexturePtr::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ TexturePtr::isNull方法的具体用法?C++ TexturePtr::isNull怎么用?C++ TexturePtr::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::TexturePtr
的用法示例。
在下文中一共展示了TexturePtr::isNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resizeTexture
void UiManager::resizeTexture(const QSize &aSize, const Ogre::MaterialPtr &aMaterial, const Ogre::TexturePtr &aTexture)
{
assert(!aMaterial.isNull());
assert(!aTexture.isNull());
// get the smallest power of two dimension that is at least as large as the new UI size
Ogre::uint newTexWidth = nextHigherPowerOfTwo(aSize.width());
Ogre::uint newTexHeight = nextHigherPowerOfTwo(aSize.height());
if (!aTexture.isNull())
{
std::string txtrName = aTexture->getName();
// remove the old texture
aTexture->unload();
aMaterial->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
Ogre::TextureManager::getSingleton().remove(aTexture->getHandle());
Ogre::TexturePtr newTxtr = Ogre::TextureManager::getSingleton().createManual(
txtrName, "General", Ogre::TEX_TYPE_2D, newTexWidth, newTexHeight, 0, Ogre::PF_A8R8G8B8,
Ogre::TU_DYNAMIC_WRITE_ONLY);
// add the new texture
Ogre::TextureUnitState* txtrUstate = aMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(txtrName);
// adjust it to stay aligned and scaled to the window
Ogre::Real txtrUScale = (Ogre::Real)newTexWidth / aSize.width();
Ogre::Real txtrVScale = (Ogre::Real)newTexHeight / aSize.height();
txtrUstate->setTextureScale(txtrUScale, txtrVScale);
txtrUstate->setTextureScroll((1 / txtrUScale) / 2 - 0.5, (1 / txtrVScale) / 2 - 0.5);
}
}
示例2: getIcon
Icon* IconManager::getIcon(int, EmberEntity* entity)
{
std::string key = "entity_" + entity->getId();
if (mIconStore.hasIcon(key)) {
return mIconStore.getIcon(key);
} else {
IconActionCreator actionCreator(*entity);
std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView()));
std::string modelName;
if (modelMapping.get()) {
modelMapping->initialize();
modelName = actionCreator.getModelName();
}
//if there's no model defined for this use the placeholder model
if (modelName == "") {
modelName = "placeholder";
}
Ogre::ResourcePtr modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName);
if (!modelDefPtr.isNull()) {
Model::ModelDefinition* modelDef = static_cast<Model::ModelDefinition*> (modelDefPtr.get());
const std::string& iconPath(modelDef->getIconPath());
if (iconPath != "") {
Ogre::TexturePtr texPtr;
try {
if (Ogre::TextureManager::getSingleton().resourceExists(iconPath)) {
texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath));
//try to load it to make sure that's it a working image
texPtr->load();
}
if (texPtr.isNull()) {
texPtr = Ogre::TextureManager::getSingleton().load(iconPath, "Gui");
}
} catch (...) {
S_LOG_WARNING("Error when trying to load the icon " << iconPath <<". The icon will be rendered dynamically.");
texPtr.setNull();
}
if (!texPtr.isNull()) {
Icon* icon = mIconStore.createIcon(key, texPtr);
return icon;
}
}
}
Icon* icon = mIconStore.createIcon(key);
if (icon) {
//update the model preview window
// Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName);
render(*icon, modelName);
// mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model);
}
return icon;
}
return 0;
}
示例3: createMaterial
bool PersonShape::createMaterial( const std::string& image_name,
const std::string& resource_group)
{
if (image_name == "default")
{
material_ = Ogre::MaterialManager::getSingleton().create( "default",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
material_->setCullingMode(Ogre::CULL_NONE);
return true;
}
material_ = Ogre::MaterialManager::getSingleton().load( image_name, resource_group );
material_->setCullingMode(Ogre::CULL_NONE);
if( material_.isNull() )
return false;
Ogre::Pass* first_pass = material_->getTechnique(0)->getPass(0);
if( first_pass->getNumTextureUnitStates() == 0 )
{
Ogre::TextureUnitState* texture_unit = first_pass->createTextureUnitState();
Ogre::TexturePtr texture
= Ogre::TextureManager::getSingleton().load( image_name, resource_group );
if( texture.isNull() )
return false;
#if (OGRE_VERSION_MINOR >=8)
texture_unit->setTexture( texture ); // or setTextureName if Ogre 1.8?
#else
texture_unit->setTextureName( texture->getName());
#endif
}
return true;
}
示例4: updateShadowTexture
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow, std::set<std::string>& managedTextures) const
{
auto shadowTextureName = getShadowTextureName(material);
Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName));
if (texture.isNull()) {
texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY);
managedTextures.insert(texture->getName());
}
Ogre::Image ogreImage;
terrainPageShadow->loadIntoImage(ogreImage);
texture->loadImage(ogreImage);
//blit the whole image to the hardware buffer
Ogre::PixelBox sourceBox(ogreImage.getPixelBox());
//blit for each mipmap
for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) {
Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i));
hardwareBuffer->blitFromMemory(sourceBox);
}
return texture;
}
示例5: updateShadowTexture
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow)
{
//we need an unique name for our alpha texture
std::stringstream shadowTextureNameSS;
shadowTextureNameSS << material->getName() << "_shadow";
const Ogre::String shadowTextureName(shadowTextureNameSS.str());
Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr> (Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName));
if (texture.isNull()) {
texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getAlphaTextureSize(), mPage.getAlphaTextureSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY);
}
Ogre::Image ogreImage;
terrainPageShadow->loadIntoImage(ogreImage);
texture->loadImage(ogreImage);
//blit the whole image to the hardware buffer
Ogre::PixelBox sourceBox(ogreImage.getPixelBox());
//blit for each mipmap
for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) {
Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i));
hardwareBuffer->blitFromMemory(sourceBox);
}
return texture;
}
示例6: processOutputImage
//!
//! Processes the node's input data to generate the node's output image.
//!
void BadPrintingNode::processOutputImage ()
{
// obtain input image
Ogre::TexturePtr inputTexture = getTextureValue("Input Map");
if (inputTexture.isNull()) {
//disable compositor (now that the input texture name was set)
if (m_compositor)
m_compositor->setEnabled(false);
//render and set output
m_renderTexture->getBuffer()->getRenderTarget()->update();
setValue("Image", m_defaultTexture);
Log::warning("No input image connected.", "BadPrintingNode::processOutputImage");
}
else if (!m_renderTexture.isNull()) {
//resize render texture
size_t width = inputTexture->getWidth();
size_t height = inputTexture->getHeight();
resizeRenderTexture(width, height);
//enable compositor (now that the input texture name was set)
if (m_compositor)
m_compositor->setEnabled(true);
m_renderTexture->getBuffer()->getRenderTarget()->update();
setValue("Image", m_renderTexture);
}
}
示例7: video_display
void video_display(VideoState *is)
{
VideoPicture *vp;
vp = &is->pictq[is->pictq_rindex];
if (is->video_st->codec->width != 0 && is->video_st->codec->height != 0)
{
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton ().getByName("VideoTexture");
if (texture.isNull () || texture->getWidth() != is->video_st->codec->width || texture->getHeight() != is->video_st->codec->height)
{
Ogre::TextureManager::getSingleton ().remove ("VideoTexture");
texture = Ogre::TextureManager::getSingleton().createManual(
"VideoTexture",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,
is->video_st->codec->width, is->video_st->codec->height,
0,
Ogre::PF_BYTE_RGBA,
Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
}
Ogre::PixelBox pb(is->video_st->codec->width, is->video_st->codec->height, 1, Ogre::PF_BYTE_RGBA, vp->data);
Ogre::HardwarePixelBufferSharedPtr buffer = texture->getBuffer();
buffer->blitFromMemory(pb);
}
free(vp->data);
}
示例8: Refresh
void EC_ChatBubble::Refresh()
{
if (renderer_.expired() || !billboardSet_ || !billboard_)
return;
// If no messages in the log, hide the chat bubble.
if (messages_.isEmpty())
{
billboardSet_->setVisible(false);
return;
}
else
billboardSet_->setVisible(true);
// Get image buffer and texture
QImage buffer = GetChatBubblePixmap().toImage();
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
if (buffer.isNull() || texture.isNull())
return;
// Check texture size
if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
{
texture->freeInternalResources();
texture->setWidth(buffer.width());
texture->setHeight(buffer.height());
texture->createInternalResources();
}
// Update texture buffer
Ogre::Box update_box(0,0, buffer.width(), buffer.height());
Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)buffer.bits());
if (!texture->getBuffer().isNull())
texture->getBuffer()->blitFromMemory(pixel_box, update_box);
}
示例9: onCursorChange
void BaseApp::onCursorChange(const std::string &name)
{
if (!mCursorManager->cursorChanged(name))
return; // the cursor manager doesn't want any more info about this cursor
// See if we can get the information we need out of the cursor resource
ResourceImageSetPointerFix* imgSetPtr = dynamic_cast<ResourceImageSetPointerFix*>(MyGUI::PointerManager::getInstance().getByName(name));
if (imgSetPtr != NULL)
{
MyGUI::ResourceImageSet* imgSet = imgSetPtr->getImageSet();
std::string tex_name = imgSet->getIndexInfo(0,0).texture;
Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(tex_name);
// everything looks good, send it to the cursor manager
if (!tex.isNull())
{
Uint8 size_x = imgSetPtr->getSize().width;
Uint8 size_y = imgSetPtr->getSize().height;
Uint8 left = imgSetPtr->getTexturePosition().left;
Uint8 top = imgSetPtr->getTexturePosition().top;
Uint8 hotspot_x = imgSetPtr->getHotSpot().left;
Uint8 hotspot_y = imgSetPtr->getHotSpot().top;
mCursorManager->receiveCursorInfo(name, tex, left, top, size_x, size_y, hotspot_x, hotspot_y);
}
}
}
示例10: showTexture
TexturePair AssetsManager::showTexture(const std::string textureName)
{
// if (!mOgreCEGUITexture) {
// S_LOG_WARNING("You must first create a valid OgreCEGUITexture instance.");
// return;
// }
if (Ogre::TextureManager::getSingleton().resourceExists(textureName)) {
Ogre::TexturePtr texturePtr = static_cast<Ogre::TexturePtr>(Ogre::TextureManager::getSingleton().getByName(textureName));
if (!texturePtr.isNull()) {
if (!texturePtr->isLoaded()) {
try {
texturePtr->load();
} catch (...) {
S_LOG_WARNING("Error when loading " << textureName << ". This texture will not be shown.");
return TexturePair();
}
}
std::string textureName(texturePtr->getName());
std::string imageSetName(textureName + "_AssetsManager");
return createTextureImage(texturePtr, imageSetName);
// mOgreCEGUITexture->setOgreTexture(texturePtr);
}
}
return TexturePair();
}
示例11: UpdateLegacyMaterials
void UpdateLegacyMaterials(const std::string& texture_name)
{
Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
Ogre::TexturePtr tex = tm.getByName(texture_name);
bool has_alpha = false;
if (!tex.isNull())
if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
has_alpha = true;
for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
{
std::string material_name = texture_name + MaterialSuffix[i];
Ogre::MaterialPtr material = mm.getByName(material_name);
if (!material.get())
continue;
Ogre::MaterialPtr base_material;
if (!has_alpha)
base_material = mm.getByName(BaseMaterials[i]);
else
base_material = mm.getByName(AlphaBaseMaterials[i]);
if (!base_material.get())
{
OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
continue;
}
base_material->copyDetailsTo(material);
SetTextureUnitOnMaterial(material, texture_name, 0);
}
}
示例12: createImage
void SimpleRenderContext::createImage(const std::string& prefix)
{
if (mWidth == 0 || mHeight == 0) {
throw Exception("Height and width of the image can't be 0.");
}
Ogre::Real aspectRatio = static_cast<float>(mWidth) / static_cast<float>(mHeight);
S_LOG_VERBOSE("Setting aspect ratio of camera to " << aspectRatio);
mCamera->setAspectRatio(aspectRatio);
//the width and height needs to be multipes of 2
mWidth = Ogre::Bitwise::firstPO2From(mWidth);
mHeight = Ogre::Bitwise::firstPO2From(mHeight);
//first, create a RenderTexture to which the Ogre renderer should render the image
S_LOG_VERBOSE("Creating new rendertexture " << (prefix + "_SimpleRenderContextRenderTexture") << " with w:" << mWidth << " h:" << mHeight);
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(prefix + "_SimpleRenderContextRenderTexture", "Gui", Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, &mResourceLoader);
if (texture.isNull()) {
S_LOG_WARNING("Could not create a texture.");
return;
}
setTexture(texture);
}
示例13: setViewSize
void UiManager::setViewSize(const Ogre::TexturePtr &aTexture)
{
// make sure that the view size matches the texture size
if (!aTexture.isNull() && !isViewSizeMatching(aTexture))
{
mWidgetView->setGeometry(QRect(0, 0, aTexture->getWidth(), aTexture->getHeight()));
}
}
示例14: CreateLegacyMaterials
void CreateLegacyMaterials(const std::string& texture_name, bool update)
{
Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
Ogre::TexturePtr tex = tm.getByName(texture_name);
bool has_alpha = false;
if (!tex.isNull())
{
if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
has_alpha = true;
}
// Early out: if texture does not yet exist and materials have already been created once
if (((tex.isNull()) || (!update)) && (!mm.getByName(texture_name).isNull()))
return;
for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
{
const std::string& base_material_name = BaseMaterials[i];
const std::string& alpha_base_material_name = AlphaBaseMaterials[i];
std::string material_name = texture_name + MaterialSuffix[i];
Ogre::MaterialPtr material = mm.getByName(material_name);
if (!material.get())
{
material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
assert(material.get());
}
Ogre::MaterialPtr base_material;
if (!has_alpha)
base_material = mm.getByName(base_material_name);
else
base_material = mm.getByName(alpha_base_material_name);
if (!base_material.get())
{
OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
return;
}
base_material->copyDetailsTo(material);
SetTextureUnitOnMaterial(material, texture_name, 0);
}
}
示例15: loadFromFile
//-----------------------------------------------------------------------
// l o a d F r o m F i l e
//-----------------------------------------------------------------------
void TGTexture::loadFromFile(const TGString& filename, const TGString& resourceGroup)
{
using namespace Ogre;
// unload old ogre texture
freeOgreTexture();
// create / load a new ogre texture from the specified image
try
{
TextureManager& textureManager = TextureManager::getSingleton();
// see if texture already exists
Ogre::TexturePtr ogreTexture = (Ogre::TexturePtr)textureManager.getByName(filename.c_str());
if (!ogreTexture.isNull())
{
// texture already exists, so create a 'linked' texture (ensures texture is not destroyed twice)
m_ogre_texture = ogreTexture;
m_isLinked = true;
}
// texture does not already exist, so load it in
else
{
String orpGroup;
if (resourceGroup.empty())
{
const String& defGrp = "";
orpGroup = defGrp.empty() ? Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() : defGrp;
}
else
{
orpGroup = resourceGroup;
}
m_ogre_texture = TextureManager::getSingleton().load(filename.c_str(), orpGroup.c_str(), TEX_TYPE_2D, 0, 1.0f);
m_isLinked = false;
}
}
catch(Ogre::Exception e)
{
throw Ogre::Exception(0,"Failed to create Texture object from file '" + filename + "'. Additional Information:\n" + e.getFullDescription().c_str(),"TGTexture");
}
// if we got a pointer cache some details
if (!m_ogre_texture.isNull())
{
m_width = m_ogre_texture->getWidth();
m_height = m_ogre_texture->getHeight();
}
// no texture from image so throw.
else
{
throw Ogre::Exception(0,"Failed to create Texture object from file '" + filename + "'. Ogre returned a NULL pointer.","TGTexture");
}
}