コード例 #1
0
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
0
ファイル: Simple.cpp プロジェクト: Arsakes/ember
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
0
ファイル: ogrewidget.cpp プロジェクト: wpfhtl/octocopter
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
0
ファイル: TextureManager.cpp プロジェクト: snus-mumrik/Khazad
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
0
ファイル: ShadowUpdateTask.cpp プロジェクト: sajty/ember
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
0
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
0
ファイル: ParticleUniverseNoise.cpp プロジェクト: dbabox/aomi
	//-----------------------------------------------------------------------
	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
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();
		}
	}
コード例 #9
0
ファイル: Simple.cpp プロジェクト: Chimangoo/ember
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
0
void getTerrainImage(bool flipX, bool flipY, Ogre::Image& img)
{
   if(flipX)
      img.flipAroundY();
   if(flipY)
      img.flipAroundX();
}
コード例 #11
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;
}
コード例 #12
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);
	}
コード例 #13
0
ファイル: imageconverter.cpp プロジェクト: jacmoe/ogitor
//----------------------------------------------------------------------------------------
QImage ImageConverter::fromOgreImageName(const Ogre::String& name, const Ogre::String& resourceGroup)
{
    mResourceGroup = resourceGroup;
    Ogre::Image img;
    img.load(name, mResourceGroup);

    return fromOgreImage(img);
}
コード例 #14
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();
}
コード例 #15
0
ファイル: Application.cpp プロジェクト: wilbefast/open-war
/// 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();
}
コード例 #16
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();
}
コード例 #17
0
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);
}
コード例 #18
0
ファイル: ogrewidget.cpp プロジェクト: wpfhtl/octocopter
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();

}
コード例 #19
0
	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();
	}
コード例 #20
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();
}
コード例 #21
0
ファイル: Terrain.cpp プロジェクト: szyszart/UberSiege
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();
}
コード例 #22
0
//-----------------------------------------------------------------------------------------
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();
    }
コード例 #23
0
	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());
	}
コード例 #24
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;
}
コード例 #25
0
void OnePixelMaterialGenerator::loadResource(Ogre::Resource* resource)
{

	Ogre::Texture* texture = static_cast<Ogre::Texture*>(resource);
	static Ogre::uchar data[3] = {0xFF, 0x7F, 0x7F};

	Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data, 3, false, true));
	Ogre::Image image;
	image.loadRawData(stream, 1,1,1, Ogre::PF_R8G8B8);
	Ogre::ConstImagePtrList images({&image});

	texture->_loadImages(images);
}
コード例 #26
0
ファイル: ReliefApp.cpp プロジェクト: jinghuaguo/magic3d
 void ReliefApp::GenerateRelief()
 {
     //Get depth data
     Ogre::TexturePtr depthTex = Ogre::TextureManager::getSingleton().createManual(  
         "DepthTexture",      // name   
         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
         Ogre::TEX_TYPE_2D,   // type   
         512,  // width   
         512,  // height   
         0,                   // number of mipmaps   
         //Ogre::PF_B8G8R8A8,   // pixel format
         Ogre::PF_FLOAT32_R,
         Ogre::TU_RENDERTARGET
         ); 
     Ogre::RenderTarget* pTarget = depthTex->getBuffer()->getRenderTarget();
     Ogre::Camera* pOrthCam = MagicCore::RenderSystem::GetSingleton()->GetMainCamera();
     pOrthCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
     pOrthCam->setOrthoWindow(3, 3);
     pOrthCam->setPosition(0, 0, 3);
     pOrthCam->lookAt(0, 0, 0);
     pOrthCam->setAspectRatio(1.0);
     pOrthCam->setNearClipDistance(0.5);
     pOrthCam->setFarClipDistance(5);
     Ogre::Viewport* pViewport = pTarget->addViewport(pOrthCam);
     pViewport->setDimensions(0, 0, 1, 1);
     MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "Depth", mpLightMesh);
     MagicCore::RenderSystem::GetSingleton()->Update();
     Ogre::Image img;
     depthTex->convertToImage(img);
     std::vector<double> heightField(512 * 512);
     for(int x = 0; x < 512; x++)  
     {  
         for(int y = 0; y < 512; y++)  
         {
             heightField.at(x * 512 + y) = (img.getColourAt(x, 511 - y, 0))[1];
         }
     }
     Ogre::TextureManager::getSingleton().remove("DepthTexture");
     //
     MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::PlaneReliefFromHeightField(heightField, 511, 511);
     //MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::CylinderReliefFromHeightField(heightField, 511, 511);
     if (pReliefMesh != NULL)
     {
         delete mpLightMesh;
         mpLightMesh = pReliefMesh;
         mpLightMesh->UnifyPosition(2);
         mpLightMesh->UpdateNormal();
     }
     MagicCore::RenderSystem::GetSingleton()->SetupCameraDefaultParameter();
     MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "MyCookTorrance", mpLightMesh);
 }
コード例 #27
0
ファイル: texturelayer.cpp プロジェクト: spookyboo/HLMSEditor
/****************************************************************************
**
** Copyright (C) 2016 - 2017
**
** This file is part of the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

#include "constants.h"
#include "texturelayer.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsManager.h"
#include "OgreLogManager.h"
#include "OgreStringConverter.h"
#include <fstream>
#include <ctime>

//****************************************************************************/
TextureLayer::TextureLayer(void) :
    mTextureOnWhichIsPaintedWidth(0),
    mTextureOnWhichIsPaintedHeight(0),
    mTextureOnWhichIsPaintedHasAlpha(false),
    mNumMipMaps(0),
    mTextureTypeDefined(false),
    mMaxSequence(0)
{
    mTextureType = Ogre::PBSM_DIFFUSE;
    mDatablockId = "";
    mTextureFileName = "";
}

//****************************************************************************/
TextureLayer::~TextureLayer(void)
{
}

//****************************************************************************/
void TextureLayer::setDatablockIdAndTexture (const Ogre::IdString& datablockId,
                                             Ogre::PbsTextureTypes textureType,
                                             const Ogre::String& textureFileName)
{
    mDatablockId = datablockId;
    mTextureType = textureType;
    mTextureFileName = textureFileName;
    mTextureTypeDefined = true;

    // Load the texture as image; assume it can be loaded, because it was already loaded as part of the material
    setFirstTextureGeneration();

    // Create the pixelbox of the original texture; this MUST be a separate image
    mOriginalTexture.load(textureFileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    mPixelboxOriginalTexture = mOriginalTexture.getPixelBox(0, 0);

    // Debug texture
    //Ogre::LogManager::getSingleton().logMessage("Debug texture: " + textureFileName);
    //Ogre::LogManager::getSingleton().logMessage("Depth: " + Ogre::StringConverter::toString(mOriginalTexture.getDepth()));
    //Ogre::LogManager::getSingleton().logMessage("Pixel format: " + Ogre::StringConverter::toString(mOriginalTexture.getFormat()));
    //Ogre::LogManager::getSingleton().logMessage("Alpha: " + Ogre::StringConverter::toString(mOriginalTexture.getHasAlpha()));
    //Ogre::LogManager::getSingleton().logMessage("Height: " + Ogre::StringConverter::toString(mOriginalTexture.getHeight()));
    //Ogre::LogManager::getSingleton().logMessage("Number of faces: " + Ogre::StringConverter::toString(mOriginalTexture.getNumFaces()));
    //Ogre::LogManager::getSingleton().logMessage("Number of mipmaps: " + Ogre::StringConverter::toString(mOriginalTexture.getNumMipmaps()));
    //Ogre::LogManager::getSingleton().logMessage("Width: " + Ogre::StringConverter::toString(mOriginalTexture.getWidth()));
}

//****************************************************************************/
void TextureLayer::blitTexture (void)
{
    /* Always get the actual pointers, because they may change. That is the reason why the datablock pointer cannot be cached.
     * The same seems to apply to the texture pointer.
     */
    Ogre::HlmsDatablock* datablock;
    Ogre::HlmsPbsDatablock* datablockPbs;
    Ogre::TexturePtr texture;
    Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
    Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS));
    datablock = hlmsPbs->getDatablock(mDatablockId);
    if (!datablock)
        return;

    datablockPbs = static_cast<Ogre::HlmsPbsDatablock*>(datablock);
    try
    {
        // Get texture on GPU
        if (!datablockPbs->getTexture(mTextureType).isNull())
        {
            texture = datablockPbs->getTexture(mTextureType); // TextureType MUST exist, otherwise the application crashes
            mNumMipMaps = texture->getNumMipmaps();
        }
    }
    catch (Ogre::Exception e){}

    if (texture.isNull())
        return;

    Ogre::uint8 maxMipMaps = mNumMipMaps + 1; // Increase with one, because there is always one image to blit
    maxMipMaps = maxMipMaps > PAINT_MAX_MIP_MAPS ? PAINT_MAX_MIP_MAPS : maxMipMaps; // Just paint a few mipmaps (not all)
    Ogre::Image textureOnWhichIsPaintedScaled = mTextureOnWhichIsPainted; // Temporary image must be used, otherwise painting doesn't work
    size_t w = mTextureOnWhichIsPaintedWidth;
    size_t h = mTextureOnWhichIsPaintedHeight;
    Ogre::v1::HardwarePixelBuffer* buffer;
    for (Ogre::uint8 i = 0; i < maxMipMaps; ++i)
    {
        buffer = texture->getBuffer(0, i).getPointer();
        buffer->blitFromMemory(textureOnWhichIsPaintedScaled.getPixelBox(0, 0), Ogre::Box(0, 0, 0, w, h, 1));
        w*=0.5f; // Mipmaps always are half of the previous one
        h*=0.5f;
        if (w < 1.0f || h < 1.0f)
            break; // Stop when the mipmaps are too small

        textureOnWhichIsPaintedScaled.resize(w, h);

    }
    textureOnWhichIsPaintedScaled.freeMemory();
}
コード例 #28
0
	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();
	}
コード例 #29
0
ファイル: Tools.cpp プロジェクト: jacobgogogo/stuntrally
///  _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");
}
コード例 #30
0
ファイル: WebView.cpp プロジェクト: danx0r/sirikata
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
}