本文整理汇总了C++中ogre::Image::loadDynamicImage方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::loadDynamicImage方法的具体用法?C++ Image::loadDynamicImage怎么用?C++ Image::loadDynamicImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Image
的用法示例。
在下文中一共展示了Image::loadDynamicImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: saveToFile
void OgreTexture::saveToFile(const std::string& _filename)
{
Ogre::uchar* readrefdata = (Ogre::uchar*)lock(TextureUsage::Read);
Ogre::Image img;
img = img.loadDynamicImage(readrefdata, mTexture->getWidth(), mTexture->getHeight(), mTexture->getFormat());
img.save(_filename);
unlock();
}
示例4: captureImage
void WebView::captureImage(const std::string& filename)
{
#ifdef HAVE_AWESOMIUM
Ogre::Image result;
int bpp = isWebViewTransparent? 4 : 3;
unsigned char* buffer = OGRE_ALLOC_T(unsigned char, viewWidth * viewHeight * bpp, Ogre::MEMCATEGORY_GENERAL);
webView->render(buffer, viewWidth * bpp, bpp);
result.loadDynamicImage(buffer, viewWidth, viewHeight, 1, isWebViewTransparent? Ogre::PF_BYTE_BGRA : Ogre::PF_BYTE_BGR, false);
result.save(Awesomium::WebCore::Get().getBaseDirectory() + "\\" + filename);
OGRE_FREE(buffer, Ogre::MEMCATEGORY_GENERAL);
#endif
}
示例5: addLightingPass
void Simple::addLightingPass(Ogre::Technique* technique, std::set<std::string>& managedTextures) const
{
Ogre::Pass* lightingPass = technique->createPass();
lightingPass->setSceneBlending(Ogre::SBT_MODULATE);
lightingPass->setLightingEnabled(false);
Ogre::TextureUnitState * textureUnitStateSplat = lightingPass->createTextureUnitState();
//we need an unique name for our alpha texture
std::stringstream lightingTextureNameSS;
lightingTextureNameSS << technique->getParent()->getName() << "_lighting";
const Ogre::String lightingTextureName(lightingTextureNameSS.str());
Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(lightingTextureName));
if (texture.isNull()) {
texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(lightingTextureName, "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;
ogreImage.loadDynamicImage(const_cast<unsigned char*>(mLightingImage->getData()), mLightingImage->getResolution(), mLightingImage->getResolution(), 1, Ogre::PF_L8);
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);
}
textureUnitStateSplat->setTextureName(texture->getName());
textureUnitStateSplat->setTextureCoordSet(0);
textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
}
示例6: 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);
}
}
}
示例7: createTerrainFromFile
void MapView::createTerrainFromFile()
{
if (mMap->getTexture().size())
{
mMaterial = (Ogre::MaterialPtr)
Ogre::MaterialManager::getSingleton().getByName(mMap->getTexture());
if (mMaterial.isNull())
{
mMaterial = (Ogre::MaterialPtr)
Ogre::MaterialManager::getSingleton().create(mMap->getTexture(), "General");
mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mMap->getTexture());
mMaterial->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_AMBIENT);
}
}
else
{
mMaterial = (Ogre::MaterialPtr)
Ogre::MaterialManager::getSingleton().getByName("terrain");
}
Ogre::Image img;
Ogre::uchar* data = new Ogre::uchar[mMap->getTerrainData().size()];
float min = mMap->getTerrainData()[0];
float max = mMap->getTerrainData()[0];
for (size_t i = 1; i < mMap->getTerrainData().size(); ++i)
{
if (mMap->getTerrainData()[i] < min) min = mMap->getTerrainData()[i];
else if (mMap->getTerrainData()[i] > max) max = mMap->getTerrainData()[i];
}
for (size_t i = 0; i < mMap->getTerrainData().size(); ++i)
{
data[i] = mMap->getTerrainData()[i];
}
img.loadDynamicImage(
data,
mMap->getTerrainSize().x,
mMap->getTerrainSize().z,
1, Ogre::PF_L8);
// Save bitmap file.
std::string name(Convert::ToString(mMap->getID()));
img.save("..\\cache\\" + name + ".png");
// Create config file.
std::ofstream config(
("..\\cache\\" + name + ".cfg").c_str(),
std::ios::out | std::ios::trunc);
config << "DetailTile=3" << "\n";
config << "PageSource=Heightmap" << "\n";
config << "Heightmap.image=" << "..\\cache\\" << name << ".png" << "\n";
config << "PageSize=" << mMap->getTerrainSize().x << "\n";
config << "TileSize=33" << "\n";
config << "MaxPixelError=3" << "\n";
config << "PageWorldX=" << mMap->getSize().x << "\n";
config << "PageWorldZ=" << mMap->getSize().z << "\n";
config << "MaxHeight=255" << "\n";
config << "MaxMipMapLevel=5" << "\n";
config << "VertexNormals=yes" << "\n";
config << "VertexColors=yes" << "\n";
config << "VertexProgramMorph=yes" << "\n";
config << "LODMorphStart=0.2" << "\n";
config << "CustomMaterialName=" << mMaterial->getName() << "\n";
config.close();
delete[] data;
mManager->setWorldGeometry("..\\cache\\" + name + ".cfg");
}
示例8: frameStarted
//.........这里部分代码省略.........
mpCrowdObject->end();
// Move to the next frame
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 );
示例9: 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);
}
}
}
示例10: outputTextures
//.........这里部分代码省略.........
// 计算最终的mini map的大小
uint miniMapWidth = xIndex * mTexWidth;
uint miniMapHeight = zIndex * mTexHeight;
if ( miniMapWidth > 10000 || miniMapHeight > 10000 )
{
mLastErrorString = "texture size is out of range!";
return false;
}
// 创建mini map所需的内存空间
uchar* miniMapData = new uchar[miniMapWidth * miniMapHeight * Ogre::PixelUtil::getNumElemBytes(mOutPutFormat)];
//// 初始的摄像机位置
Real xPos = originPoint.x;
Real zPos = originPoint.z;
for ( int i=0; i<xIndex; ++i )
{
for ( int j=0; j<zIndex; ++j )
{
// 设置摄像机位置,并更新render texture的内容
mCamera->setPosition(xPos, yPos, zPos);
mRenderTexture->update();
String fileName = mPath + mSceneBaseName + Ogre::StringConverter::toString(i)
+ "_" + Ogre::StringConverter::toString(j) + "." + mTexExtension;
// 输出小纹理文件
mRenderTexture->writeContentsToFile(fileName);
mTempOutputFileNames.push_back(fileName);
// 读取刚创建的纹理
Ogre::Image* tempImage = new Ogre::Image;
tempImage->load(mSceneBaseName + Ogre::StringConverter::toString(i)
+ "_" + Ogre::StringConverter::toString(j) + "." + mTexExtension, TEMP_GROUP_NAME);
// 获取render texture中的内容
uchar* tempImageData = tempImage->getData();
// 定位在mini map中的左上角
uint miniMapIndex = ( j * mTexHeight * miniMapWidth + i * mTexWidth ) * Ogre::PixelUtil::getNumElemBytes(mOutPutFormat);
uchar* startData = miniMapData + miniMapIndex;
for ( size_t height = 0; height < tempImage->getHeight(); ++height )
{
for ( size_t width = 0; width < tempImage->getWidth(); ++width )
{
memcpy(startData, tempImageData, Ogre::PixelUtil::getNumElemBytes(mOutPutFormat));
startData += Ogre::PixelUtil::getNumElemBytes(mOutPutFormat);
tempImageData += Ogre::PixelUtil::getNumElemBytes( tempImage->getFormat() );
}
startData += (miniMapWidth - tempImage->getWidth()) * Ogre::PixelUtil::getNumElemBytes(mOutPutFormat);
}
delete tempImage;
// 移动摄像机的z坐标
if (mUseRealCameraAngle)
{
zPos += (mInvertCameraDir * (projectSize)).z;
xPos += (mInvertCameraDir * (projectSize)).x;
}
else
zPos += mTileSize;
}
if (mUseRealCameraAngle)
{
xPos = originPoint.x;
zPos = originPoint.z;
xPos += (mMoveZDir * (mTileSize) * (i+1)).x;
zPos += (mMoveZDir * (mTileSize) * (i+1)).z;
}
else
{
// 操作完每一列之后,重置摄像机的z坐标
zPos = terrainData->mMinZ;
// 移动摄像机的x坐标
xPos += mTileSize;
}
}
// 保存mini map并输出
Ogre::Image* miniMapImage = new Ogre::Image;
miniMapImage->loadDynamicImage(miniMapData, miniMapWidth, miniMapHeight, 1, mOutPutFormat, true);
miniMapImage->save(mPath + mOutFileName + "." + mTexExtension);
delete miniMapImage;
rgm.destroyResourceGroup(TEMP_GROUP_NAME);
return true;
}
示例11: addPassToTechnique
// void TerrainPageSurfaceCompiler::addTextureUnitsToPass(Ogre::Pass* pass, const Ogre::String& splatTextureName) {
//
// if (getMaxTextureUnits() - pass->getNumTextureUnitStates() < 2 || pass->getParent()->getNumPasses() > 1) {
// addPassToTechnique(pass->getParent(), splatTextureName);
// // S_LOG_WARNING("Trying to add texture units to pass with too few available texture unit states.");
// return;
// }
//
// S_LOG_VERBOSE("Adding new texture unit (detailtexture: " << mTextureName << " alphatexture: " << splatTextureName << ") to pass nr " << pass->getIndex() << " in technique for material " << pass->getParent()->getParent()->getName());
//
// /* pass->setSelfIllumination(Ogre::ColourValue(1,1,1));
// pass->setAmbient(Ogre::ColourValue(1,1,1));
// pass->setDiffuse(Ogre::ColourValue(1,1,1));
// pass->setLightingEnabled(true);*/
// Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState();
// textureUnitStateSplat->setTextureName(splatTextureName);
//
// textureUnitStateSplat->setTextureCoordSet(0);
// textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
// textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
// textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
// textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
// // textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
// // textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_TEXTURE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
//
// Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
// textureUnitState->setTextureName(mTextureName);
// textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// /* textureUnitState->setTextureCoordSet(0);*/
// textureUnitState->setTextureScale(0.025, 0.025);
// textureUnitState->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
//
// /* Ogre::TextureUnitState * alphaTextureState= pass->createTextureUnitState();
// alphaTextureState->setTextureName(mTextureName);
// // alphaTextureState->setTextureName(splatTextureName);
// alphaTextureState->setTextureCoordSet(0);
// alphaTextureState->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
// alphaTextureState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
// alphaTextureState->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
//
//
//
// // detailTextureState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
// // detailTextureState->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
//
// Ogre::TextureUnitState * detailTextureState = pass->createTextureUnitState();
// detailTextureState ->setTextureName(splatTextureName);
// // detailTextureState ->setTextureName(mTextureName);
// detailTextureState ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// detailTextureState ->setTextureCoordSet(0);
// detailTextureState ->setTextureScale(0.01, 0.01);
// //detailTextureState ->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);*/
//
// }
//
Ogre::Pass* Simple::addPassToTechnique(const TerrainPageGeometry& geometry, Ogre::Technique* technique, const Layer& layer, std::set<std::string>& managedTextures) const
{
//check if we instead can reuse the existing pass
// if (technique->getNumPasses() != 0) {
// Ogre::Pass* pass = technique->getPass(technique->getNumPasses() - 1);
// if (4 - pass->getNumTextureUnitStates() >= 2) {
// //there's more than two texture units available, use those instead of creating a new pass
// S_LOG_VERBOSE("Reusing existing pass. ("<< pass->getNumTextureUnitStates() << " of "<< mNumberOfTextureUnitsOnCard << " texture unit used)");
// addTextureUnitsToPass(pass, splatTextureName);
// return pass;
// }
//
// }
const OgreImage& ogreImage = *layer.blendMap;
Ogre::Image image;
image.loadDynamicImage(const_cast<unsigned char*>(ogreImage.getData()), ogreImage.getResolution(), ogreImage.getResolution(), 1, Ogre::PF_A8);
std::stringstream splatTextureNameSS;
splatTextureNameSS << "terrain_" << mPage.getWFPosition().x() << "_" << mPage.getWFPosition().y() << "_" << technique->getNumPasses();
const Ogre::String splatTextureName(splatTextureNameSS.str());
Ogre::TexturePtr blendMapTexture;
if (Ogre::Root::getSingletonPtr()->getTextureManager()->resourceExists(splatTextureName)) {
blendMapTexture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(splatTextureName));
blendMapTexture->loadImage(image);
Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(blendMapTexture->getBuffer());
//blit the whole image to the hardware buffer
Ogre::PixelBox sourceBox(image.getPixelBox());
hardwareBuffer->blitFromMemory(sourceBox);
} else {
blendMapTexture = Ogre::Root::getSingletonPtr()->getTextureManager()->loadImage(splatTextureName, "General", image, Ogre::TEX_TYPE_2D, 0);
managedTextures.insert(blendMapTexture->getName());
}
//we need to create the image, update it and then destroy it again (to keep the memory usage down)
// if (layer->getBlendMapTextureName() == "") {
// //no texture yet; let's create one
// layer->createBlendMapImage();
// layer->updateBlendMapImage(geometry);
// layer->createTexture();
// } else {
// //a texture exists, so we just need to update the image
// layer->updateBlendMapImage(geometry); //calling this will also update the texture since the method will blit the image onto it
//.........这里部分代码省略.........
示例12: getPreviewImage
void
MaterialPreviewDialog::buildPreviewBitmap( const Ogre::String &texName )
{
const Ogre::uchar BytePerPixel = 8;
// 读取原始image
Ogre::Image *oriImage = getPreviewImage(texName);
// 源大纹理的大小
size_t oriImageHeight = oriImage->getHeight();
size_t oriImageWidth = oriImage->getWidth();
Ogre::uchar *oriImageData = oriImage->getData();
// 分配一个足够大的空间来保存新建的image的数据
size_t newImagegetRowSpan = oriImageWidth*oriImage->getBPP()/BytePerPixel; // 新建的image的行宽(单位为字节)
Ogre::uchar *newImageData = OGRE_ALLOC_T(Ogre::uchar, oriImageHeight*newImagegetRowSpan, Ogre::MEMCATEGORY_GENERAL);//new Ogre::uchar[oriImageHeight*newImagegetRowSpan];
Ogre::uchar *newImageDataPointer = newImageData;
Ogre::uchar *oriImagedataPointer = oriImageData;
// 把所选的纹理的数据提取出来,并创建一个新的image
for ( Ogre::uint i=0; i<oriImageHeight; ++i )
{
memcpy(newImageDataPointer, oriImagedataPointer, newImagegetRowSpan);
newImageDataPointer += newImagegetRowSpan;
oriImagedataPointer += oriImage->getRowSpan();
}
Ogre::Image newImage;
newImage.loadDynamicImage(newImageData,oriImageWidth,oriImageHeight,1,oriImage->getFormat(),true);
// 如果所选纹理大于64*64,就先resize
if ( oriImageWidth > mPreviewImageWidth || oriImageHeight > mPreviewImageHeight )
newImage.resize(mPreviewImageWidth, mPreviewImageHeight);
// 如果有alpha,要与黑白图进行混合
if ( newImage.getHasAlpha() )
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
float alphaValue = col.a;
unsigned char r = col.r*255 * alphaValue;
unsigned char g = col.g*255 * alphaValue;
unsigned char b = col.b*255 * alphaValue;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
// 没有alpha,就直接拷贝数据
else
{
Ogre::ColourValue col;
for ( int i=0; i<mPreviewImageWidth; ++i )
{
for ( int j=0; j<mPreviewImageWidth; ++j )
{
col = newImage.getColourAt(j,i,0);
unsigned char r = col.r*255;
unsigned char g = col.g*255;
unsigned char b = col.b*255;
// 设置到image中
mCurrentPreviewImage.SetRGB(j,i,r,g,b);
}
}
}
}
示例13: CreateSurface
Surface*
FontFile::GetSurface(void)
{
int width = 512;
int height = 4096;
int chars = 0;
int char_num = 6165;
Surface* ret = CreateSurface(width, height);
int x_16 = 0;
int y_16 = 0;
struct ClutColor
{
u8 r; /**< @brief red color in CLUT */
u8 g; /**< @brief green color in CLUT */
u8 b; /**< @brief blue color in CLUT */
u8 a; /**< @brief alpha in CLUT */
};
ClutColor color;
color.r = 0;
color.g = 0;
color.b = 0;
color.a = 255;
u8 data = 0;
for (int chars = 0; chars < char_num; ++chars)
{
Surface* glyth = CreateSurface(16, 16);
for (int y = 0; y < 16; ++y)
{
data = (y < 11) ? GetU8(0xE + chars * 22 + y * 2 + 0) : 0;
//LOGGER->Log(LOGGER_INFO, "%x, %02x", y, data);
int j = 0;
for (int i = 7; i >= 0; --i)
{
color.r = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.g = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.b = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.a = ((data >> i) & 0x01 == 1) ? 255 : 255;
memcpy(glyth->pixels + 64 * y + j, &color, sizeof(ClutColor));
j += 4;
}
data = (y < 11) ? GetU8(0xE + chars * 22 + y * 2 + 1) : 0;
//LOGGER->Log(LOGGER_INFO, "%02x", data);
for (int i = 7; i >= 0; --i)
{
color.r = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.g = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.b = ((data >> i) & 0x01 == 1) ? 0 : 255;
color.a = ((data >> i) & 0x01 == 1) ? 255 : 255;
memcpy(glyth->pixels + 64 * y + j, &color, sizeof(ClutColor));
j += 4;
}
}
CopyToSurface(ret, x_16, y_16, glyth);
delete glyth;
x_16 += 16;
if (x_16 == ret->width)
{
y_16 += 16;
x_16 = 0;
}
}
Ogre::TexturePtr ptex;
Ogre::HardwarePixelBufferSharedPtr buffer;
ptex = Ogre::TextureManager::getSingleton().createManual("DynaTex", "General", Ogre::TEX_TYPE_2D, ret->width, ret->height, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC);
buffer = ptex->getBuffer(0, 0);
buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& pb = buffer->getCurrentLock();
for (Uint32 y = 0; y < ret->height; ++y)
{
Uint32* data = static_cast<Uint32*>(pb.data) + y * pb.rowPitch;
for (Uint32 x = 0; x < ret->width; ++x)
{
Uint32 clut = ret->pixels[y * ret->width * 4 + x * 4 + 3] | (ret->pixels[y * ret->width * 4 + x * 4 + 2] << 8) | (ret->pixels[y * ret->width * 4 + x * 4 + 1] << 16) | (ret->pixels[y * ret->width * 4 + x * 4 + 0] << 24);
data[x] = clut;
}
}
Ogre::Image image;
image.loadDynamicImage((Ogre::uchar*)pb.data, ret->width, ret->height, Ogre::PF_R8G8B8A8);
image.save("font.png");
buffer->unlock();
Ogre::TextureManager::getSingleton().remove("DynaTex");
return ret;
//.........这里部分代码省略.........
示例14: 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 );
//.........这里部分代码省略.........
示例15: process
//-----------------------------------------------------------------------
void AtlasImageTool::process (void)
{
Ogre::Root root("", "", "atlas.log");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(mImagePath, "FileSystem");
Ogre::StringVector::iterator itInputFileName;
Ogre::StringVector::iterator itFrame;
Ogre::StringVector::iterator itAlpha;
itAlpha = mAlpha.begin();
if (mInputFrames.empty() || mInputFrames[0] == Ogre::StringUtil::BLANK)
{
// No Frames are assigned so just add them
for (itInputFileName = mInputFileNames.begin(); itInputFileName != mInputFileNames.end(); ++itInputFileName)
{
Ogre::String imageFileName = *itInputFileName;
Ogre::Image image;
image.load(imageFileName, "General");
if (itAlpha != mAlpha.end() && *itAlpha != Ogre::StringUtil::BLANK)
{
Ogre::Real alpha = Ogre::StringConverter::parseReal(*itAlpha);
correctAlpha(image, alpha);
itAlpha++;
}
mAtlasImage.addImage(&image);
}
}
else
{
// Frames are assigned, so generate intermediate images
itInputFileName = mInputFileNames.begin();
Ogre::Real alpha = 1.0f;
Ogre::String nextImageFileName = *itInputFileName;
Ogre::Image nextImage;
itFrame = mInputFrames.begin();
size_t nextFrame = Ogre::StringConverter::parseUnsignedInt(*itFrame);
nextImage.load(nextImageFileName, "General");
size_t frameCounter = 0;
if (!mAlpha.empty() && mAlpha[0] != Ogre::StringUtil::BLANK)
{
itAlpha = mAlpha.begin();
Ogre::Real alpha = Ogre::StringConverter::parseReal(*itAlpha);
correctAlpha(nextImage, alpha);
itAlpha++;
}
mAtlasImage.addImage(&nextImage);
frameCounter++;
itInputFileName++;
itFrame++;
while (itInputFileName != mInputFileNames.end())
{
// Get the next filename
Ogre::Image firstImage(nextImage);
nextImageFileName = *itInputFileName;
nextImage.load(nextImageFileName, "General");
if (itAlpha != mAlpha.end() && *itAlpha != Ogre::StringUtil::BLANK)
{
Ogre::Real alpha = Ogre::StringConverter::parseReal(*itAlpha);
correctAlpha(nextImage, alpha);
itAlpha++;
}
if (itFrame != mInputFrames.end())
{
size_t firstFrame = nextFrame;
nextFrame = Ogre::StringConverter::parseUnsignedInt(*itFrame);
itFrame++;
frameCounter++;
// Generate and add interpolated images to the atlas image
size_t numberOfFrames = nextFrame - firstFrame;
for (size_t i = 1; i < numberOfFrames; ++i)
{
Ogre::Real fraction = (Ogre::Real)i / (Ogre::Real)numberOfFrames;
Ogre::Image interpolatedImage;
size_t pixelSize = Ogre::PixelUtil::getNumElemBytes(firstImage.getFormat());
size_t bufferSize = firstImage.getWidth() * firstImage.getHeight() * pixelSize;
Ogre::uchar* data = OGRE_ALLOC_T(Ogre::uchar, bufferSize, Ogre::MEMCATEGORY_GENERAL);
interpolatedImage.loadDynamicImage(data, firstImage.getWidth(), firstImage.getHeight(), 1, firstImage.getFormat(), true);
interpolate (interpolatedImage, firstImage, nextImage, fraction);
mAtlasImage.addImage(&interpolatedImage);
frameCounter++;
}
}
mAtlasImage.addImage(&nextImage);
frameCounter++;
itInputFileName++;
}
}
mAtlasImage._compile();
mAtlasImage.save(mImagePath + "//" + mOutputImage);
}