本文整理汇总了C++中ogre::Image类的典型用法代码示例。如果您正苦于以下问题:C++ Image类的具体用法?C++ Image怎么用?C++ Image使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: downloadPicture
void TileDownloader::downloadPicture(unsigned int index)
{
const PictureInfo& info = mPictures[index];
//Downloading all tiles in parallel
{
boost::threadpool::pool tp(info.tiles.size());
for (unsigned int i=0; i<info.tiles.size(); ++i)
tp.schedule(boost::bind(&TileDownloader::downloadPictureTile, this, index, i));
}
//compose all tiles on the canvas
unsigned int width = info.width;
unsigned int height = info.height;
Ogre::Canvas::Context* ctx = new Ogre::Canvas::Context(width, height, false);
for (unsigned int i=0; i<info.tiles.size(); ++i)
{
const TileInfo& tileInfo = info.tiles[i];
Ogre::Image img;
std::stringstream filename;
filename << tileInfo.j << "_" << tileInfo.i << ".jpg";
img.load(filename.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
float x = (tileInfo.i == 0) ? 0 : 509.0f + (tileInfo.i-1)*510.0f;
float y = (tileInfo.j == 0) ? 0 : 509.0f + (tileInfo.j-1)*510.0f;
ctx->drawImage(img, x, y);
}
//save canvas to jpeg
ctx->saveToFile(info.filePath);
delete ctx;
}
示例2: 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;
}
示例3: defineTerrain
void OgreWidget::defineTerrain(long x, long y, bool flat)
{
// First, we ask our TerrainGroup what file name it would use to generate the terrain. Then we check if
// there is a file by that name in our resource group. If there is, it means that we generated a binary
// terrain data file already, and thus there is no need to import it from an image. If there isn't a data
// file present, it means we have to generate our terrain, and we load the image and uses that to define it.
if(flat)
{
qDebug() << "OgreWidget::defineTerrain(): flat";
mTerrainGroup->defineTerrain(x, y, 0.0f);
}
else
{
Ogre::String filename = mTerrainGroup->generateFilename(x, y);
qDebug() << "OgreWidget::defineTerrain(): filename" << QString::fromStdString((std::string)filename) << "resourceGroup" << QString::fromStdString((std::string)mTerrainGroup->getResourceGroup());
if(Ogre::ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
{
qDebug() << "OgreWidget::defineTerrain(): resource exists, calling TerrainGroup::defineTerrain with x y" << x << y;
mTerrainGroup->defineTerrain(x, y);
}
else
{
qDebug() << "OgreWidget::defineTerrain(): resource absent, calling TerrainGroup::defineTerrain with image for x y" << x << y;
Ogre::Image img;
getTerrainImage(x % 2 != 0, y % 2 != 0, img);
img.save("test2.png");
mTerrainGroup->defineTerrain(x, y, &img);
mTerrainGroup->getTerrainDefinition(x, y)->importData->inputImage->save("test3.png");
mTerrainsImported = true;
}
}
}
示例4: makeOgreMaterial
Ogre::MaterialPtr TextureManager::makeOgreMaterial(int16_t MaterialTypeID, int16_t TextureID)
{
Ogre::MaterialPtr NewMaterial = Ogre::MaterialManager::getSingleton().create("GrassMaterial", "General", true);
Ogre::Image* NewImage = new Ogre::Image(); // Delete?
uint16_t ImageID = IMAGE->GenerateMaterialImage(MaterialTypeID, TextureID);
uint8_t* iData = IMAGE->getImageData(ImageID);
uint16_t Width = IMAGE->getImageWidth(ImageID);
uint16_t Height = IMAGE->getImageHeight(ImageID);
NewImage->loadDynamicImage(iData, Width, Height, Ogre::PF_A8R8G8B8);
Ogre::TexturePtr NewTex = Ogre::TextureManager::getSingleton().loadImage("TextureX", "General", *NewImage, Ogre::TEX_TYPE_2D, 1);
Ogre::Technique* FirstTechnique = NewMaterial->getTechnique(0);
Ogre::Pass* FirstPass = FirstTechnique->getPass(0);
FirstPass->setLightingEnabled(false);
Ogre::TextureUnitState* TextureUnit = FirstPass->createTextureUnitState();
TextureUnit->setTextureName("TextureX", Ogre::TEX_TYPE_2D);
delete NewImage;
return NewMaterial;
}
示例5: executeTaskInMainThread
bool ShadowUpdateTask::executeTaskInMainThread()
{
if (!mPageGeometries.empty()) {
auto pageGeometry = mPageGeometries.back();
mPageGeometries.pop_back();
auto& page = pageGeometry->getPage();
if (page.getSurface()) {
auto shadow = page.getSurface()->getShadow();
if (shadow) {
auto& shadowTextureName = shadow->getShadowTextureName();
if (!shadowTextureName.empty()) {
Ogre::TexturePtr texture = Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (texture) {
Ogre::Image ogreImage;
shadow->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 mPageGeometries.empty();
}
示例6:
Ogre::Image *
MaterialPreviewDialog::getPreviewImage( const Ogre::String &textureName )
{
PreviewImageMap::iterator it = mPreviewImageMap.find(textureName);
if ( it == mPreviewImageMap.end() )
{
Ogre::Image *image = new Ogre::Image;
image->load(textureName,"General");
assert (image);
std::pair< PreviewImageMap::iterator, bool > inserted =
mPreviewImageMap.insert(PreviewImageMap::value_type(textureName,image));
assert (inserted.second);
return image;
}
else
{
assert (it->second);
return it->second;
}
}
示例7: bits
//-----------------------------------------------------------------------
void Noise3D::noise2img(Ogre::ushort dimension)
{
double x = 0.0;
double y = 0.0;
double step = 1.0 / (double)dimension;
size_t buffSize = 4 * dimension * dimension; // Assume Image of pixelformat 32 bits (i.e. PF_R8G8B8A8)
Ogre::uchar* buff = new Ogre::uchar[buffSize];
size_t p = 0;
while (p < buffSize)
{
Ogre::uchar n = (Ogre::uchar)(255 * noise(x, y, 0.5));
buff[p] = n;
buff[p+1] = n;
buff[p+2] = n;
buff[p+3] = n;
p += 4;
x += step;
if (x >= 1.0)
{
x = 0.0;
y += step;
}
}
Ogre::Image* image = new Ogre::Image();
image->loadDynamicImage(buff, dimension, dimension, 0, Ogre::PF_R8G8B8A8 , false, 1, 0);
image->save("noise2img.png");
delete image;
delete [] buff;
}
示例8: initBlendMaps
void SnowTerrain::initBlendMaps(Terrain* terrain)
{
TextureLayerFileList blendImages = mSnowConfig->terrainSettings.textureBlendFileList;
// load those blendmaps into the layers
for(int j = 0;j < terrain->getLayerCount();j++)
{
// skip first layer
if(j==0)
continue;
// no blend map for this layer
if(blendImages.size() >= j && blendImages[j].length() == 0)
continue;
Ogre::TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(j);
Ogre::Image img;
img.load(blendImages[j],"General");
int blendmapsize = terrain->getLayerBlendMapSize();
if(img.getWidth() != blendmapsize)
img.resize(blendmapsize, blendmapsize);
float *ptr = blendmap->getBlendPointer();
Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data);
for(int bp = 0;bp < blendmapsize * blendmapsize;bp++)
ptr[bp] = static_cast<float>(data[bp]) / 255.0f;
blendmap->dirty();
blendmap->update();
}
}
示例9: 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;
}
示例10: getTerrainImage
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
if(flipX)
img.flipAroundY();
if(flipY)
img.flipAroundX();
}
示例11: load
//----------------------------------------------------------------------------//
Texture* OgreImageCodec::load(const RawDataContainer& data, Texture* result)
{
using namespace Ogre;
// wrap the buffer of the RawDataContainer with an Ogre::MemoryDataStream.
DataStreamPtr stream(
new MemoryDataStream(
const_cast<void*>(static_cast<const void*>(data.getDataPtr())),
data.getSize(), false));
// load the image
Ogre::Image image;
image.load(stream);
// discover the pixel format and number of pixel components
Texture::PixelFormat format;
int components;
switch (image.getFormat())
{
case PF_R8G8B8:
format = Texture::PF_RGB;
components = 3;
break;
case PF_A8R8G8B8:
format = Texture::PF_RGBA;
components = 4;
break;
default:
throw FileIOException("OgreImageCodec::load: File data was of an "
"unsupported format.");
break;
}
// do the old switcharoo on R and B...
// (we could 'fix' this in the CEGUI::OgreTexture, but that would break all
// the other ImageCodecs when used with the Ogre renderer, hence we don't)
uchar* dat = image.getData();
for (uint j = 0; j < image.getHeight(); ++j)
{
for (uint i = 0; i < image.getWidth(); ++i)
{
uchar tmp = dat[i * components + 0];
dat[i * components + 0] = dat[i * components + 2];
dat[i * components + 2] = tmp;
}
dat += image.getRowSpan();
}
// load the resulting image into the texture
result->loadFromMemory(image.getData(),
Size(image.getWidth(),
image.getHeight()),
format);
return result;
}
示例12: GetDefaultTexture
void LodTextureManager::GetDefaultTexture(Ogre::Resource* res)
{
// Create the texture
Texture* texture = static_cast<Texture*>(res);
Ogre::Image img;
img.load("pending.png",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
texture->loadImage(img);
}
示例13: fromOgreImageName
//----------------------------------------------------------------------------------------
QImage ImageConverter::fromOgreImageName(const Ogre::String& name, const Ogre::String& resourceGroup)
{
mResourceGroup = resourceGroup;
Ogre::Image img;
img.load(name, mResourceGroup);
return fromOgreImage(img);
}
示例14: GetTerrainImage
void TerrainManager::GetTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
img.load(mHeightMapFileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (flipX)
img.flipAroundY();
if (flipY)
img.flipAroundX();
}
示例15: getTerrainImage
/// FIXME
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
img.load("height_map.png", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
if (flipX)
img.flipAroundY();
if (flipY)
img.flipAroundX();
}