本文整理汇总了C++中ogre::Image::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::getWidth方法的具体用法?C++ Image::getWidth怎么用?C++ Image::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Image
的用法示例。
在下文中一共展示了Image::getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: importFullTerrainFromHeightMap
//-----------------------------------------------------------------------------------------
void CTerrainGroupEditor::importFullTerrainFromHeightMap()
{
UTFStringVector extlist;
extlist.push_back(OTR("PNG Grayscale"));
extlist.push_back("*.png");
extlist.push_back(OTR("Raw 32bit Float File"));
extlist.push_back("*.raw;*.ohm;*.f32;*.r32");
Ogre::UTFString defaultPath = mSystem->GetSetting("system", "ExportTerrainPath", "");
Ogre::String filename = mSystem->DisplayOpenDialog(OTR("Import Heightmap"), extlist, defaultPath);
if(filename == "")
return;
mSystem->SetSetting("system", "ExportTerrainPath", OgitorsUtils::ExtractFilePath(filename));
Ogre::NameValuePairList params;
if(!mSystem->DisplayImportHeightMapDialog(params))
return;
Ogre::Real fScale = Ogre::StringConverter::parseReal(params["scale"]);
Ogre::Real fBias = Ogre::StringConverter::parseReal(params["bias"]);
Ogre::String normal = params["normal"];
Ogre::String diffuse = params["diffuse"];
bool flipV = Ogre::StringConverter::parseBool(params["inverted"]);
float *data = 0;
float *flipBV = 0;
Ogre::String namePart = OgitorsUtils::ExtractFileName(filename);
namePart.erase(0, namePart.find("."));
int imgW = 0;
int imgH = 0;
if(namePart == ".png")
{
std::fstream fstr(filename.c_str(), std::ios::in|std::ios::binary);
Ogre::DataStreamPtr stream = Ogre::DataStreamPtr(OGRE_NEW Ogre::FileStreamDataStream(&fstr, false));
Ogre::Image img;
img.load(stream);
data = OGRE_ALLOC_T(float, img.getWidth() * img.getHeight(), Ogre::MEMCATEGORY_GEOMETRY);
Ogre::PixelBox pb(img.getWidth(), img.getHeight(), 1, Ogre::PF_FLOAT32_R, data);
Ogre::PixelUtil::bulkPixelConversion(img.getPixelBox(), pb);
imgW = img.getWidth();
imgH = img.getHeight();
img.freeMemory();
stream.setNull();
}
示例3: 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();
}
}
示例4: loadResource
void gkTextureLoader::loadResource(Ogre::Resource* resource)
{
Ogre::Texture* texture = static_cast<Ogre::Texture*>(resource);
if (!m_stream)
{
gkPrintf("Warning: Skipping image %s no packed file information is present!", texture->getName().c_str());
return;
}
Ogre::DataStreamPtr stream(OGRE_NEW Ogre::MemoryDataStream(m_stream->ptr(), m_stream->size()));
Ogre::Image ima;
ima.load(stream);
texture->setUsage(Ogre::TU_DEFAULT);
texture->setTextureType(Ogre::TEX_TYPE_2D);
texture->setNumMipmaps(gkEngine::getSingleton().getUserDefs().defaultMipMap);
texture->setWidth(ima.getWidth());
texture->setHeight(ima.getHeight());
texture->setDepth(ima.getDepth());
texture->setFormat(ima.getFormat());
Ogre::ConstImagePtrList ptrs;
ptrs.push_back(&ima);
texture->_loadImages(ptrs);
}
示例5: createTerrain
void AppDemarrage::createTerrain()
{
// options globales
mTerrainOptions = OGRE_NEW Ogre::TerrainGlobalOptions();
mTerrainOptions->setMaxPixelError(8);
mTerrainOptions->setLightMapDirection(mLight->getDerivedDirection());
mTerrainOptions->setCompositeMapDistance(3000);
mTerrainOptions->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
mTerrainOptions->setCompositeMapDiffuse(mLight->getDiffuseColour());
mTerrain = OGRE_NEW Ogre::Terrain(mSceneMgr);
Ogre::Image img;
img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// informations géométriques
Ogre::Terrain::ImportData imp;
imp.inputImage = &img;
imp.terrainSize = img.getWidth();
imp.worldSize = 8000;
imp.inputScale = 600;
imp.minBatchSize = 33;
imp.maxBatchSize = 65;
// textures
imp.layerList.resize(3);
imp.layerList[0].worldSize = 100;
imp.layerList[0].textureNames.push_back("grass_green-01_diffusespecular.dds");
imp.layerList[0].textureNames.push_back("grass_green-01_normalheight.dds");
imp.layerList[1].worldSize = 30;
imp.layerList[1].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
imp.layerList[1].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
imp.layerList[2].worldSize = 200;
imp.layerList[2].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
imp.layerList[2].textureNames.push_back("dirt_grayrocky_normalheight.dds");
mTerrain->prepare(imp);
mTerrain->load();
// plaquage de texture
Ogre::TerrainLayerBlendMap* blendMap1 = mTerrain->getLayerBlendMap(1);
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < mTerrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < mTerrain->getLayerBlendMapSize(); ++x)
{
*pBlend1++ = 150;
}
}
blendMap1->dirty();
blendMap1->update();
mTerrain->freeTemporaryResources();
}
示例6: _setSkinType
void MouseCursor::_setSkinType(const Ogre::String type)
{
if(mSkinType == type)
return;
mSkinType = type;
Ogre::Image i;
i.load(mSkinTypeManager->getSkinType("MouseCursor",mSkinType)->getSkinElement(TEXTURE)->getTextureName(),Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// update cursor size to match texture used
setSize(i.getWidth(),i.getHeight());
}
示例7: onBeforeDisplay
//-----------------------------------------------------------------------------------------
QPixmap GenericImageEditorCodec::onBeforeDisplay(Ogre::DataStreamPtr stream)
{
Ogre::Image image;
image.load(stream);
ImageConverter imageConverter(image.getWidth(), image.getHeight());
if (mPixmap.convertFromImage(imageConverter.fromOgreImage(image)))
return mPixmap;
mPixmap = 0;
return mPixmap;
}
示例8: correctAlpha
//-----------------------------------------------------------------------
void AtlasImageTool::correctAlpha (Ogre::Image& image, Ogre::Real alphaCorrection)
{
size_t numPixels = image.getWidth() * image.getHeight();
size_t pointer = 0;
for (size_t i = 0; i < numPixels; ++i)
{
Ogre::ColourValue colour;
Ogre::PixelUtil::unpackColour(&colour, image.getFormat(), (image.getData() + pointer));
colour.a *= alphaCorrection;
Ogre::PixelUtil::packColour(colour, image.getFormat(), (image.getData() + pointer));
pointer += Ogre::PixelUtil::getNumElemBytes(image.getFormat());
}
}
示例9: setSkinType
void MouseCursor::setSkinType(const Ogre::String type)
{
mSkinType = type;
mDefaultSkinType = type;
Ogre::Image i;
i.load(mSkinTypeManager->getSkinType("MouseCursor",mSkinType)->getSkinElement(TEXTURE)->getTextureName(),Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// update cursor size to match texture used
setSize(i.getWidth(),i.getHeight());
Sheet* sheet = mMouseCursorDesc.guiManager->getActiveSheet();
if(sheet != NULL)
{
MouseEventArgs args(sheet);
args.position = getPosition();
sheet->fireSheetEvent(SHEET_EVENT_MOUSE_CURSOR_SKIN_CHANGED,args);
}
}
示例10:
MouseCursor::MouseCursor(const MouseCursorDesc& d) :
mSkinType("default"),
mDefaultSkinType("default")
{
mMouseCursorDesc.guiManager = d.guiManager;
mSkinTypeManager = SkinTypeManager::getSingletonPtr();
for(int i = 0; i < 4; ++i)
mEnteredBorders[i] = false;
// Update Size of Cursor to match Skin Texture
Ogre::Image i;
i.load(mSkinTypeManager->getSkinType("MouseCursor",mSkinType)->getSkinElement(TEXTURE)->getTextureName(),Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// update cursor size to match texture used
setSize(i.getWidth(),i.getHeight());
// Set default position
setPosition(0,0);
}
示例11: interpolate
//-----------------------------------------------------------------------
void AtlasImageTool::interpolate (Ogre::Image& interpolatedImage,
Ogre::Image& firstImage,
Ogre::Image& nextImage,
Ogre::Real fraction)
{
size_t numPixels = interpolatedImage.getWidth() * interpolatedImage.getHeight();
size_t pointer = 0;
for (size_t i = 0; i < numPixels; ++i)
{
Ogre::ColourValue firstColour;
Ogre::ColourValue nextColour;
Ogre::ColourValue interpolatedColour;
Ogre::PixelUtil::unpackColour(&firstColour, firstImage.getFormat(), (firstImage.getData() + pointer));
Ogre::PixelUtil::unpackColour(&nextColour, nextImage.getFormat(), (nextImage.getData() + pointer));
interpolatedColour = firstColour + fraction * (nextColour - firstColour);
Ogre::PixelUtil::packColour(interpolatedColour, interpolatedImage.getFormat(), (interpolatedImage.getData() + pointer));
pointer += Ogre::PixelUtil::getNumElemBytes(interpolatedImage.getFormat());
}
}
示例12: processBlendmaps
void DotSceneLoader::processBlendmaps(rapidxml::xml_node<>* XMLNode)
{
int pageX = Ogre::StringConverter::parseInt(XMLNode->first_attribute("pageX")->value());
int pageY = Ogre::StringConverter::parseInt(XMLNode->first_attribute("pageY")->value());
Ogre::String filename = mTerrainGroup->generateFilename(pageX, pageY);
// skip this is terrain page has been saved already
if (!Ogre::ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
{
rapidxml::xml_node<>* pElement;
// Process blendmaps (*)
std::vector<Ogre::String> blendMaps;
rapidxml::xml_node<>* pBlendmap;
pElement = XMLNode->first_node("blendMaps");
pBlendmap = pElement->first_node("blendMap");
while(pBlendmap)
{
blendMaps.push_back(getAttrib(pBlendmap, "texture",""));
pBlendmap = pBlendmap->next_sibling("blendMap");
}
for(int j = 1;j < mTerrainGroup->getTerrain(pageX, pageY)->getLayerCount();j++)
{
Ogre::TerrainLayerBlendMap *blendmap = mTerrainGroup->getTerrain(pageX, pageY)->getLayerBlendMap(j);
Ogre::Image img;
img.load(blendMaps[j-1],"General");
int blendmapsize = mTerrainGroup->getTerrain(pageX, pageY)->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();
}
}
}
示例13: exploreCell
void GlobalMap::exploreCell(int cellX, int cellY)
{
float originX = static_cast<float>((cellX - mMinX) * mCellSize);
// NB y + 1, because we want the top left corner, not bottom left where the origin of the cell is
float originY = static_cast<float>(mHeight - (cellY + 1 - mMinY) * mCellSize);
if (cellX > mMaxX || cellX < mMinX || cellY > mMaxY || cellY < mMinY)
return;
Ogre::TexturePtr localMapTexture = Ogre::TextureManager::getSingleton().getByName("Cell_"
+ boost::lexical_cast<std::string>(cellX) + "_" + boost::lexical_cast<std::string>(cellY));
if (!localMapTexture.isNull())
{
int mapWidth = localMapTexture->getWidth();
int mapHeight = localMapTexture->getHeight();
mOverlayTexture->load();
mOverlayTexture->getBuffer()->blit(localMapTexture->getBuffer(), Ogre::Image::Box(0,0,mapWidth,mapHeight),
Ogre::Image::Box(static_cast<Ogre::uint32>(originX), static_cast<Ogre::uint32>(originY),
static_cast<Ogre::uint32>(originX + mCellSize), static_cast<Ogre::uint32>(originY + mCellSize)));
Ogre::Image backup;
std::vector<Ogre::uchar> data;
data.resize(mCellSize*mCellSize*4, 0);
backup.loadDynamicImage(&data[0], mCellSize, mCellSize, Ogre::PF_A8B8G8R8);
localMapTexture->getBuffer()->blitToMemory(Ogre::Image::Box(0,0,mapWidth,mapHeight), backup.getPixelBox());
for (int x=0; x<mCellSize; ++x)
for (int y=0; y<mCellSize; ++y)
{
assert (originX+x < mOverlayImage.getWidth());
assert (originY+y < mOverlayImage.getHeight());
assert (x < int(backup.getWidth()));
assert (y < int(backup.getHeight()));
mOverlayImage.setColourAt(backup.getColourAt(x, y, 0), static_cast<size_t>(originX + x), static_cast<size_t>(originY + y), 0);
}
}
}
示例14: build
//------------------------------------------------------
void TextureAtlas::build() {
if (!mIsDirty)
return;
bool fitted;
size_t area = 0;
// build the fonts (if this didn't happen already)
// so we'll be sure the glyphs are there to be atlassed
FontSet::iterator fit = mMyFonts.begin();
while (fit != mMyFonts.end()) {
FontDrawSource* fdsp = *fit++;
if (!fdsp->isBuilt())
fdsp->build();
}
// First, we sort by size of the DrawSource
mMyDrawSources.sort(DrawSourceLess());
// now try to allocate all the draw sources. If we fail, grow and try again
do {
fitted = true;
area = 0;
// try to fit
DrawSourceList::iterator it = mMyDrawSources.begin();
while (it != mMyDrawSources.end()) {
const DrawSourcePtr& ds = *it++;
const PixelSize& ps = ds->getPixelSize();
area += ps.getPixelArea();
LOG_VERBOSE("TextureAtlas: (%s) Trying to place %d x %d (%d -> %d)", mAtlasName.c_str(), ps.width, ps.height, ps.getPixelArea(), area);
// try to allocate
FreeSpaceInfo* fsi = mAtlasAllocation->allocate(ps.width, ps.height);
if (fsi) {
ds->setPlacementPtr(fsi);
} else {
fitted = false;
break;
}
}
// fitted?
if (!fitted) // nope - Enlarge!
enlarge(area);
} while (!fitted);
LOG_INFO("TextureAtlas: (%s) Creating atlas with dimensions %d x %d", mAtlasName.c_str(), mAtlasSize.width, mAtlasSize.height);
if (mTexture.isNull())
prepareResources();
// TODO: Reallocate the texture here if needed!
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer();
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& targetBox = pixelBuffer->getCurrentLock();
size_t pixelsize = Ogre::PixelUtil::getNumElemBytes(targetBox.format);
size_t rowsize = targetBox.rowPitch * pixelsize;
Ogre::uint8* dstData = static_cast<Ogre::uint8*>(targetBox.data);
// We'll iterate over all draw sources, painting the pixels onto the allocated space
DrawSourceList::iterator it = mMyDrawSources.begin();
while (it != mMyDrawSources.end()) {
const DrawSourcePtr& ds = *it++;
// render all pixels into the right place
FreeSpaceInfo* fsi = reinterpret_cast<FreeSpaceInfo*>(ds->getPlacementPtr());
assert(fsi);
// render into the specified place
unsigned char* conversionBuf = NULL;
const PixelSize& dps = ds->getPixelSize();
Ogre::Image* img = ds->getImage();
Ogre::PixelBox srcPixels = img->getPixelBox();
// convert if the source data don't match
if(img->getFormat() != Ogre::PF_BYTE_BGRA) {
conversionBuf = new unsigned char[img->getWidth() * img->getHeight() * pixelsize];
Ogre::PixelBox convPixels(Ogre::Box(0, 0, dps.width, dps.height), Ogre::PF_BYTE_BGRA, conversionBuf);
Ogre::PixelUtil::bulkPixelConversion(srcPixels, convPixels);
srcPixels = convPixels;
}
size_t srcrowsize = srcPixels.rowPitch * pixelsize;
//.........这里部分代码省略.........
示例15: initBlendMaps
void TerrainGeometryManager::initBlendMaps(int x, int z, Ogre::Terrain* terrain )
{
bool debugBlendMaps = BOPT("DebugBlendMaps", false);
int layerCount = terrain->getLayerCount();
for (int i = 1; i < layerCount; i++)
{
blendLayerInfo_t &bi = blendInfo[i];
if(bi.blendMapTextureFilename.empty()) continue;
Ogre::Image img;
//std::pair<uint8,uint8> textureIndex = terrain->getLayerBlendTextureIndex(i);
//uint8 bti = terrain->getBlendTextureIndex(i);
try
{
img.load(bi.blendMapTextureFilename, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
} catch(Exception &e)
{
LOG("Error loading blendmap: " + bi.blendMapTextureFilename + " : " + e.getFullDescription());
continue;
}
TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(i);
// resize that blending map so it will fit
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
if (img.getWidth() != blendmapSize)
img.resize(blendmapSize, blendmapSize);
// now to the ugly part
float* ptr = blendmap->getBlendPointer();
for (Ogre::uint32 z = 0; z != blendmapSize; z++)
{
for (Ogre::uint32 x = 0; x != blendmapSize; x++)
{
Ogre::ColourValue c = img.getColourAt(x, z, 0);
float alpha = bi.alpha;
if (bi.blendMode == 'R')
*ptr++ = c.r * alpha;
else if (bi.blendMode == 'G')
*ptr++ = c.g * alpha;
else if (bi.blendMode == 'B')
*ptr++ = c.b * alpha;
else if (bi.blendMode == 'A')
*ptr++ = c.a * alpha;
}
}
blendmap->dirty();
blendmap->update();
}
if (debugBlendMaps)
{
for (int i = 1; i < layerCount; i++)
{
Ogre::TerrainLayerBlendMap* blendMap = terrain->getLayerBlendMap(i);
Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize();
Ogre::Image img;
unsigned short *idata = OGRE_ALLOC_T(unsigned short, blendmapSize * blendmapSize, Ogre::MEMCATEGORY_RESOURCE);
float scale = 65535.0f;
for (unsigned int x = 0; x < blendmapSize; x++)
for (unsigned int z = 0; z < blendmapSize; z++)
idata[x + z * blendmapSize] = (unsigned short)(blendMap->getBlendValue(x, blendmapSize - z) * scale);
img.loadDynamicImage((Ogre::uchar*)(idata), blendmapSize, blendmapSize, Ogre::PF_L16);
std::string fileName = "blendmap_layer_" + Ogre::StringConverter::toString(i) + ".png";
img.save(fileName);
OGRE_FREE(idata, Ogre::MEMCATEGORY_RESOURCE);
}
}
}