예제 #1
0
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);
}
예제 #2
0
	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();
		}
	}
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;
}
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;
	}
}
예제 #5
0
//----------------------------------------------------------------------------//
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;
}
예제 #6
0
/// 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();
}
예제 #7
0
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();
}
예제 #8
0
	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);
	}
예제 #9
0
//----------------------------------------------------------------------------------------
QImage ImageConverter::fromOgreImageName(const Ogre::String& name, const Ogre::String& resourceGroup)
{
    mResourceGroup = resourceGroup;
    Ogre::Image img;
    img.load(name, mResourceGroup);

    return fromOgreImage(img);
}
예제 #10
0
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
	img.load("terrain1.bmp", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    if (flipX)
        img.flipAroundY();
    if (flipY)
        img.flipAroundX();
}
void FvFTDTerrainPageSerializerImpl::ReadLodTextureMap(Ogre::DataStreamPtr &spStream, 
													   FvTerrainPage *pkDest)
{
	Ogre::Image kImage;
	kImage.load(spStream,"dds");
	pkDest->m_spLodMap = Ogre::TextureManager::getSingleton().loadImage(pkDest->m_kLodName,
		FvTerrainPage::TERRAIN_INERNAL_RESOURCE_GROUP, kImage);
}
예제 #12
0
void OgreWidget::getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
    img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    qDebug() << "OgreWidget::getTerrainImage(): loaded terrain heightmap, width is" << img.getWidth();
    if(flipX)
        img.flipAroundY();
    if(flipY)
        img.flipAroundX();

}
예제 #13
0
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();
}
예제 #14
0
void TerrainLoader::loadTerrain(std::string filename) {
	Ogre::Image img;
    img.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	terrainGroup->defineTerrain(0, 0, &img);
	terrainGroup->loadAllTerrains(true);
	Ogre::TerrainGroup::TerrainIterator ti = terrainGroup->getTerrainIterator();
	while(ti.hasMoreElements()) {
		Ogre::Terrain* t = ti.getNext()->instance;		
		initBlendMaps(t);
	}
	terrainGroup->freeTemporaryResources();
}
	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());
	}
//-----------------------------------------------------------------------------------------
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();
    }
예제 #17
0
//-----------------------------------------------------------------------------------------
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;
}
	void ListImageItem::setImage(const Ogre::String& name)
	{
		mDesc->listimageitem_imageName = name;

		if(mDesc->listimageitem_imageName != "")
		{
			// If texture not loaded, load it!
			if(!Ogre::TextureManager::getSingleton().resourceExists(mDesc->listimageitem_imageName))
			{
				Ogre::Image i;
				i.load(mDesc->listimageitem_imageName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			}
		}

		redraw();
	}
예제 #19
0
///  _Tool_ tex ..........................
//  (remove alpha channel for ter tex prv img)
void App::ToolTexAlpha()
{
	Ogre::Image im;
	im.load("jungle_5d.png", "General");

	PixelBox pb = im.getPixelBox();
	int w = pb.getWidth(), h = pb.getHeight();
	for(int j=0; j < h; ++j)
	for(int i=0; i < w; ++i)
	{
		ColourValue c = pb.getColourAt(i,j,0);
		c.a = 1.f;
		pb.setColourAt(c,i,j,0);
	}
	im.save(PATHMANAGER::Data()+"/prv.png");
}
	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);
		}
	}
예제 #21
0
//-----------------------------------------------------------------------------------------
void CTerrainGroupEditor::setBrushName(const std::string& brush)
{
    mBrushName = brush;
    if(!mDecalTexture.isNull())
    {
        Ogre::Image img;
        img.load(brush,"Brushes");
        
        unsigned char *dataptr = OGRE_ALLOC_T(unsigned char, img.getWidth() * img.getHeight() * 3, Ogre::MEMCATEGORY_GEOMETRY);
        Ogre::PixelBox resultbox(img.getWidth(),img.getHeight(),1,Ogre::PF_B8G8R8,dataptr);
        Ogre::PixelUtil::bulkPixelConversion(img.getPixelBox(), resultbox);

        resultbox.setConsecutive();
        int pos = 0;
        Ogre::ColourValue colval;
        for(unsigned int x = 0;x < img.getHeight() * img.getWidth();x++)
        {
                dataptr[pos] = 0;
                dataptr[pos + 1] = 0;
                dataptr[pos + 2] *= 0.8f;
                pos += 3;
        }

        mDecalTexture->setHeight(img.getHeight());
        mDecalTexture->setWidth(img.getWidth());
        Ogre::HardwarePixelBufferSharedPtr ptr = mDecalTexture->getBuffer();
        ptr->blitFromMemory(resultbox);
        OGRE_FREE(dataptr, Ogre::MEMCATEGORY_GEOMETRY);

        img.resize(mBrushSize, mBrushSize);
        img.resize(BRUSH_DATA_SIZE, BRUSH_DATA_SIZE);
        pos = 0;
        Ogre::ColourValue cval;
        for(unsigned int y = 0;y < BRUSH_DATA_SIZE ;y++)
        {
            pos = ((BRUSH_DATA_SIZE - 1) - y) * BRUSH_DATA_SIZE;
            for(unsigned int x = 0;x < BRUSH_DATA_SIZE ;x++)
            {
                cval = img.getColourAt(x,y,0);
                mBrushData[pos] = cval.r;
                pos++;
            }
        }
    }
예제 #22
0
void EMBOgre::createOgreTexture(EMBFile *file, size_t index) {
    string ogre_emb_name = name + "_";
    string emb_texture_name = file->getName();

    if (emb_texture_name.size()) {
        ogre_emb_name += emb_texture_name;
    }
    else {
        ogre_emb_name += ToString(index);
    }

    Ogre::DataStreamPtr data_stream(new EMBOgreDataStream(file));
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createResource(ogre_emb_name, XENOVIEWER_RESOURCE_GROUP).staticCast<Ogre::Texture>();
    Ogre::Image image;
    image.load(data_stream, "DDS");
    texture->loadImage(image);

    ogre_textures[index] = texture;
}
	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);
	}
예제 #24
0
int _tmain(int argc, _TCHAR* argv[])
{
  // Disable Ogre logging
  new LogManager;
  Log *log = LogManager::getSingleton().createLog("");
  //log->setDebugOutputEnabled(false);

  // Set up Root
  Root *root = new Root("","","");
  //MTGACodec::startup();
  //ArchiveManager::getSingleton().addArchiveFactory( new LODArchiveFactory );
  
  //addResourceLocation("D:/games/mm8bukarus/Data/bitmaps.lod", "Lod");
  ResourceGroupManager::getSingleton().addResourceLocation("D:/games/MMCollection/MM_VI/Data/Icons.lod", "Lod");
  ResourceGroupManager::getSingleton().addResourceLocation("D:/games/MMCollection/MM_VI/Data/BITMAPS.LOD", "Lod");
  ResourceGroupManager::getSingleton().addResourceLocation("D:/games/MMCollection/MM_VI/Data/games.lod", "Lod");
  ResourceGroupManager::getSingleton().addResourceLocation("D:/games/MMCollection/MM_VI/Data/SPRITES.LOD", "Lod");
  /*SaveStreamToFile("d:\\_\\2HAxe1", ResourceGroupManager::getSingleton().openResource("2HAxe1"));
  SaveStreamToFile("d:\\_\\2DEvents.txt", ResourceGroupManager::getSingleton().openResource("2DEvents.txt"));
  SaveStreamToFile("d:\\_\\ZNWC.STR", ResourceGroupManager::getSingleton().openResource("ZNWC.STR"));
  SaveStreamToFile("d:\\_\\armormid", ResourceGroupManager::getSingleton().openResource("armormid"));
  SaveStreamToFile("d:\\_\\WtrdrXNW", ResourceGroupManager::getSingleton().openResource("WtrdrXNW"));
  SaveStreamToFile("d:\\_\\d05.blv", ResourceGroupManager::getSingleton().openResource("d05.blv"));
  SaveStreamToFile("d:\\_\\oute3.ddm", ResourceGroupManager::getSingleton().openResource("oute3.ddm"));
  SaveStreamToFile("d:\\_\\3Gem07", ResourceGroupManager::getSingleton().openResource("3Gem07"));
  SaveStreamToFile("d:\\_\\wwalk1F2", ResourceGroupManager::getSingleton().openResource("wwalk1F2"));*/
  Ogre::Image img;
  img.load(Ogre::String("WtrdrXNW"),"General");
  img.save("d:\\_\\WtrdrXNW.png");
  ODMmap map;
  map.load("oute3.odm");
  /*Ogre::Image img2;
  img2.load(Ogre::String("armormid"),"General");
  img2.save("d:\\_\\armormid.png");*/
  //std::cout <<  ResourceGroupManager::getSingleton().resourceExists("General","alphanum1") << std::endl;
  
  //TestArchive();
  //TestStream();
  //cout << "End TestStream()" << endl;

  return 0;
}
예제 #25
0
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();
        }
    }
}
예제 #26
0
//-------------------------------------------------------------------------------------
bool UndeadLand::LoadImage(const Ogre::String& texture_name, const Ogre::String& texture_path)
{
  bool image_loaded = false;
  std::ifstream ifs( texture_path.c_str(), std::ios::binary|std::ios::in );
  if ( ifs.is_open( ) )
  {
    Ogre::String tex_ext;
    Ogre::String::size_type index_of_extension = texture_path.find_last_of('.');
    if ( index_of_extension != Ogre::String::npos )
    {
      tex_ext = texture_path.substr( index_of_extension + 1 );
      Ogre::DataStreamPtr data_stream( new Ogre::FileStreamDataStream( texture_path, &ifs, false ) );
      Ogre::Image img;
      img.load( data_stream, tex_ext );
      Ogre::TextureManager::getSingleton().loadImage( texture_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, img, Ogre::TEX_TYPE_2D, 0, 1.0f );
      image_loaded = true;
    }
    ifs.close();
  }
  return image_loaded;
}
예제 #27
0
	void initialize(void)
	{
		try
		{
			const gkString imgName = HALO_IMAGE_NAME;

			Ogre::DataStreamPtr stream(OGRE_NEW Ogre::MemoryDataStream((void*)(FLARE_ALPHA_64), FLARE_ALPHA_64_SIZE));
			Ogre::Image img;
			img.load(stream);
			Ogre::TextureManager::getSingleton().loadImage(imgName, GK_BUILTIN_GROUP, img);

			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(DEFAULT_HALO_MAT, GK_BUILTIN_GROUP);
			Ogre::Pass *pass = mat->getTechnique(0)->getPass(0);

			pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
			pass->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 150);
			pass->setDepthWriteEnabled(false);
			Ogre::TextureUnitState* tu = pass->createTextureUnitState(imgName);		
		}
		catch(Ogre::Exception& e)
		{
			gkLogMessage("gkParticleManager: " << e.getDescription());
		}
	}
예제 #28
0
    void GlobalMap::read(ESM::GlobalMap& map)
    {
        const ESM::GlobalMap::Bounds& bounds = map.mBounds;

        if (bounds.mMaxX-bounds.mMinX < 0)
            return;
        if (bounds.mMaxY-bounds.mMinY < 0)
            return;

        if (bounds.mMinX > bounds.mMaxX
                || bounds.mMinY > bounds.mMaxY)
            throw std::runtime_error("invalid map bounds");

        Ogre::Image image;
        Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&map.mImageData[0], map.mImageData.size()));
        image.load(stream, "png");

        int xLength = (bounds.mMaxX-bounds.mMinX+1);
        int yLength = (bounds.mMaxY-bounds.mMinY+1);

        // Size of one cell in image space
        int cellImageSizeSrc = image.getWidth() / xLength;
        if (int(image.getHeight() / yLength) != cellImageSizeSrc)
            throw std::runtime_error("cell size must be quadratic");

        // If cell bounds of the currently loaded content and the loaded savegame do not match,
        // we need to resize source/dest boxes to accommodate
        // This means nonexisting cells will be dropped silently
        int cellImageSizeDst = mCellSize;

        // Completely off-screen? -> no need to blit anything
        if (bounds.mMaxX < mMinX
                || bounds.mMaxY < mMinY
                || bounds.mMinX > mMaxX
                || bounds.mMinY > mMaxY)
            return;

        int leftDiff = (mMinX - bounds.mMinX);
        int topDiff = (bounds.mMaxY - mMaxY);
        int rightDiff = (bounds.mMaxX - mMaxX);
        int bottomDiff =  (mMinY - bounds.mMinY);
        Ogre::Image::Box srcBox ( std::max(0, leftDiff * cellImageSizeSrc),
                                  std::max(0, topDiff * cellImageSizeSrc),
                                  std::min(image.getWidth(), image.getWidth() - rightDiff * cellImageSizeSrc),
                                  std::min(image.getHeight(), image.getHeight() - bottomDiff * cellImageSizeSrc));

        Ogre::Image::Box destBox ( std::max(0, -leftDiff * cellImageSizeDst),
                                   std::max(0, -topDiff * cellImageSizeDst),
                                   std::min(mOverlayTexture->getWidth(), mOverlayTexture->getWidth() + rightDiff * cellImageSizeDst),
                                   std::min(mOverlayTexture->getHeight(), mOverlayTexture->getHeight() + bottomDiff * cellImageSizeDst));

        // Looks like there is no interface for blitting from memory with src/dst boxes.
        // So we create a temporary texture for blitting.
        Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual("@temp",
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, image.getWidth(),
                                                                                 image.getHeight(), 0, Ogre::PF_A8B8G8R8);
        tex->loadImage(image);

        mOverlayTexture->load();
        mOverlayTexture->getBuffer()->blit(tex->getBuffer(), srcBox, destBox);

        if (srcBox.left == destBox.left && srcBox.right == destBox.right
                && srcBox.top == destBox.top && srcBox.bottom == destBox.bottom
                && int(image.getWidth()) == mWidth && int(image.getHeight()) == mHeight)
            mOverlayImage = image;
        else
            mOverlayTexture->convertToImage(mOverlayImage);

        Ogre::TextureManager::getSingleton().remove("@temp");
    }
예제 #29
0
//-----------------------------------------------------------------------
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);
}
예제 #30
0
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);
		}
	}
}