本文整理汇总了C++中ogre::Image::loadRawData方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::loadRawData方法的具体用法?C++ Image::loadRawData怎么用?C++ Image::loadRawData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Image
的用法示例。
在下文中一共展示了Image::loadRawData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadResource
void OnePixelMaterialGenerator::loadResource(Ogre::Resource* resource)
{
Ogre::Texture* texture = static_cast<Ogre::Texture*>(resource);
static Ogre::uchar data[3] = {0xFF, 0x7F, 0x7F};
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data, 3, false, true));
Ogre::Image image;
image.loadRawData(stream, 1,1,1, Ogre::PF_R8G8B8);
Ogre::ConstImagePtrList images({&image});
texture->_loadImages(images);
}
示例2: displayMap
void NavViewPanel::displayMap(const nav_msgs::OccupancyGrid& map)
{
boost::mutex::scoped_lock lock(map_lock_);
map_resolution_ = map.info.resolution;
// Pad dimensions to power of 2
map_width_ = map.info.width;//(int)pow(2,ceil(log2(map.info.width)));
map_height_ = map.info.height;//(int)pow(2,ceil(log2(map.info.height)));
map_origin_x_ = map.info.origin.position.x;
map_origin_y_ = map.info.origin.position.y;
//ROS_INFO("Padded dimensions to %d X %d\n", map_width_, map_height_);
// Expand it to be RGB data
int pixels_size = map_width_ * map_height_ * 3;
unsigned char* pixels = new unsigned char[pixels_size];
memset(pixels, 255, pixels_size);
for(unsigned int j=0;j<map.info.height;j++)
{
for(unsigned int i=0;i<map.info.width;i++)
{
unsigned char val;
if(map.data[j*map.info.width+i] == 100)
val = 0;
else if(map.data[j*map.info.width+i] == 0)
val = 255;
else
val = 127;
int pidx = 3*(j*map_width_ + i);
pixels[pidx+0] = val;
pixels[pidx+1] = val;
pixels[pidx+2] = val;
}
}
Ogre::DataStreamPtr pixel_stream;
pixel_stream.bind(new Ogre::MemoryDataStream( pixels, pixels_size ));
static int tex_count = 0;
std::stringstream ss;
ss << "NavViewMapTexture" << tex_count++;
try
{
map_texture_ = Ogre::TextureManager::getSingleton().loadRawData( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
pixel_stream, map_width_, map_height_, Ogre::PF_BYTE_RGB, Ogre::TEX_TYPE_2D,
0);
}
catch(Ogre::RenderingAPIException&)
{
Ogre::Image image;
pixel_stream->seek(0);
float width = map_width_;
float height = map_height_;
if (map_width_ > map_height_)
{
float aspect = height / width;
width = 2048;
height = width * aspect;
}
else
{
float aspect = width / height;
height = 2048;
width = height * aspect;
}
ROS_WARN("Failed to create full-size map texture, likely because your graphics card does not support textures of size > 2048. Downsampling to [%d x %d]...", (int)width, (int)height);
image.loadRawData(pixel_stream, map_width_, map_height_, Ogre::PF_BYTE_RGB);
image.resize(width, height, Ogre::Image::FILTER_NEAREST);
ss << "Downsampled";
map_texture_ = Ogre::TextureManager::getSingleton().loadImage(ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image);
}
delete [] pixels;
Ogre::SceneNode* map_node = NULL;
if ( !map_object_ )
{
static int map_count = 0;
std::stringstream ss;
ss << "NavViewMapObject" << map_count++;
map_object_ = scene_manager_->createManualObject( ss.str() );
map_node = root_node_->createChildSceneNode();
map_node->attachObject( map_object_ );
ss << "Material";
map_material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
map_material_->setReceiveShadows(false);
map_material_->getTechnique(0)->setLightingEnabled(false);
}
else
{
map_node = map_object_->getParentSceneNode();
}
Ogre::Pass* pass = map_material_->getTechnique(0)->getPass(0);
Ogre::TextureUnitState* tex_unit = NULL;
if (pass->getNumTextureUnitStates() > 0)
//.........这里部分代码省略.........
示例3: resourcesLoaded
void Terrain::resourcesLoaded()
{
mTerrain = OGRE_NEW Ogre::Terrain( GlobalsBase::mScene );
Ogre::Terrain::ImportData imp;
Ogre::Image img;
switch( mHeightmapType )
{
case HEIGHTMAPTYPE_IMAGE:
{
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(
mHeightmapFile.string(), mResourceManager.getGroup() );
texture->convertToImage( img );
imp.inputImage = &img;
imp.terrainSize = img.getWidth();
imp.inputScale = mInputScale;
break;
}
case HEIGHTMAPTYPE_RAW:
{
Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(
mHeightmapFile.string(), mResourceManager.getGroup() );
img.loadRawData( stream, 1025, 1025, Ogre::PF_FLOAT32_R );
imp.inputImage = &img;
imp.terrainSize = img.getWidth();
imp.inputScale = 1;
break;
}
case HEIGHTMAPTYPE_OGREBINARY:
break;
}
if( mTerrainType != TERRAINTYPE_OGREBINARY )
{
// Generic import data
imp.worldSize = 1025;
imp.minBatchSize = 33;
imp.maxBatchSize = 65;
imp.pos = toVector3<Ogre::Vector3>(
ServerPosition( ClientPlugin::getServer().getGridPosition() ).get3DPosition() );
mTerrain->setPosition( imp.pos );
// Set textures
imp.layerList.resize( mLayerInstances.size() );
for( unsigned int i = 0; i < mLayerInstances.size(); ++i )
{
imp.layerList[i].worldSize = mLayerInstances[i].mWorldSize;
for( std::vector<Path>::iterator j = mLayerInstances[i].mTextureFiles.begin();
j != mLayerInstances[i].mTextureFiles.end(); ++j )
{
imp.layerList[i].textureNames.push_back( (*j).string() );
}
}
// Load the terrain
mTerrain->prepare( imp );
mTerrain->load();
}
// Set blending
switch( mTerrainType )
{
case TERRAINTYPE_AUTOBLENDMAP:
{
Ogre::TerrainLayerBlendMap* blendMap0 = mTerrain->getLayerBlendMap(1);
Ogre::TerrainLayerBlendMap* blendMap1 = mTerrain->getLayerBlendMap(2);
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < mTerrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < mTerrain->getLayerBlendMapSize(); ++x)
{
Ogre::Real tx, ty;
blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
Ogre::Real height = mTerrain->getHeightAtTerrainPosition(tx, ty);
Ogre::Real val = (height - mMinHeight0) / mFadeDistance0;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
val = (height - mMinHeight1) / mFadeDistance1;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
*pBlend1++ = val;
}
}
blendMap0->dirty();
blendMap1->dirty();
blendMap0->update();
blendMap1->update();
break;
}
case TERRAINTYPE_OGREBINARY:
// Everything is embedded in the binary file.
mTerrain->setResourceGroup( mResourceManager.getGroup() );
mTerrain->prepare( mHeightmapFile.string() );
mTerrain->load( mHeightmapFile.string() );
break;
}
mTerrain->freeTemporaryResources();
//.........这里部分代码省略.........