void RenderingManager::configureFog(const MWWorld::CellStore &mCell)
{
    Ogre::ColourValue color;
    color.setAsABGR (mCell.getCell()->mAmbi.mFog);

    configureFog (mCell.getCell()->mAmbi.mFogDensity, color);
}
Beispiel #2
0
void RenderingManager::configureFog(ESMS::CellStore<MWWorld::RefData> &mCell)
{
  Ogre::ColourValue color;
  color.setAsABGR (mCell.cell->ambi.fog);

  configureFog(mCell.cell->ambi.fogDensity, color);
}
void  OgreWidget::setBackgroundColor(QColor c)
{
  if (m_viewport)
    {
      Ogre::ColourValue ogreColour;
      ogreColour.setAsARGB(c.rgba());
      m_viewport->setBackgroundColour(ogreColour);
    }
}
void GameObjectFlashLight::applyTintColour(int colour)
{
	Ogre::ColourValue tint;
	tint.setAsRGBA(colour);
	Ogre::MaterialPtr mat=Ogre::MaterialManager::getSingleton().getByName(CONE_MATERIAL_NAME);
	Ogre::TextureUnitState* tex= mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
	if (tex)
	{
		tex->setColourOperationEx(Ogre::LBX_MODULATE,Ogre::LBS_MANUAL,Ogre::LBS_CURRENT,tint);
	}
}
void CSVRender::UnpagedWorldspaceWidget::update()
{
    const CSMWorld::Record<CSMWorld::Cell>& record =
        dynamic_cast<const CSMWorld::Record<CSMWorld::Cell>&> (mCellsModel->getRecord (mCellId));

    Ogre::ColourValue colour;
    colour.setAsABGR (record.get().mAmbi.mAmbient);
    setAmbient (colour);

    /// \todo deal with mSunlight and mFog/mForDensity
}
Beispiel #6
0
// configure fog according to cell
void InteriorCellRender::configureFog()
{
  Ogre::ColourValue color;
  color.setAsABGR (cell.cell->ambi.fog);

  float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity);
  float low = 200;

  scene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high);
  scene.getCamera()->setFarClipDistance (high + 10);
  scene.getViewport()->setBackgroundColour (color);
}
Beispiel #7
0
void InteriorCellRender::configureAmbient()
{
  ambientColor.setAsABGR (cell.cell->ambi.ambient);
  setAmbientMode();

  // Create a "sun" that shines light downwards. It doesn't look
  // completely right, but leave it for now.
  Ogre::Light *light = scene.getMgr()->createLight();
  Ogre::ColourValue colour;
  colour.setAsABGR (cell.cell->ambi.sunlight);
  light->setDiffuseColour (colour);
  light->setType(Ogre::Light::LT_DIRECTIONAL);
  light->setDirection(0,-1,0);
}
Beispiel #8
0
void RenderingManager::configureAmbient(MWWorld::Ptr::CellStore &mCell)
{
    mAmbientColor.setAsABGR (mCell.mCell->mAmbi.mAmbient);
    setAmbientMode();

    // Create a "sun" that shines light downwards. It doesn't look
    // completely right, but leave it for now.
    if(!mSun)
    {
        mSun = mRendering.getScene()->createLight();
    }
    Ogre::ColourValue colour;
    colour.setAsABGR (mCell.mCell->mAmbi.mSunlight);
    mSun->setDiffuseColour (colour);
    mSun->setType(Ogre::Light::LT_DIRECTIONAL);
    mSun->setDirection(0,-1,0);
}
void RenderingManager::configureAmbient(MWWorld::CellStore &mCell)
{
    if (mCell.getCell()->mData.mFlags & ESM::Cell::Interior)
        mAmbientColor.setAsABGR (mCell.getCell()->mAmbi.mAmbient);
    setAmbientMode();

    // Create a "sun" that shines light downwards. It doesn't look
    // completely right, but leave it for now.
    if(!mSun)
    {
        mSun = mRendering.getScene()->createLight();
        mSun->setType(Ogre::Light::LT_DIRECTIONAL);
    }
    if (mCell.getCell()->mData.mFlags & ESM::Cell::Interior)
    {
        Ogre::ColourValue colour;
        colour.setAsABGR (mCell.getCell()->mAmbi.mSunlight);
        mSun->setDiffuseColour (colour);
        mSun->setDirection(1,-1,-1);
        sunEnable(false);
    }
}
void CReflectiveUI::BuildUIForObject(CMFCPropertyGridProperty* root, RTTIObject* pObject, const char* szName )
{
	CMFCPropertyGridProperty* pRoot = new CMFCPropertyGridProperty(szName);
	if (root)
	{
		root->AddSubItem( pRoot );
	}
	else
	{
		m_pGrid->AddProperty(pRoot);
	}

	std::vector<BaseProperty*> Properties;
	pObject->GetRTTI()->EnumProperties( Properties );

	for ( size_t i = 0; i < Properties.size(); i++ )
	{
		switch ( Properties[i]->GetTypeID() )
		{
		case eptBool:
			{
				AddPropertyToGrid<bool>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptByte:
			{
				AddPropertyToGrid<char>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptInt:
			{
				AddPropertyToGrid<int>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptShort:
			{
				AddPropertyToGrid<short>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptLong :
			{
				AddPropertyToGrid<long>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptPtr:
			{
				TypedProperty<RTTIObject*>* pTypedProperty = (TypedProperty<RTTIObject*>*)Properties[i];
				BuildUIForObject(pRoot
					, pTypedProperty->GetValue( pObject )
					, pTypedProperty->GetName().c_str()
					);
				break;
			}
		case eptOgreReal:
			{
				AddPropertyToGrid<Ogre::Real>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptOgreString:
			{
				AddPropertyToGrid_AsString<Ogre::String>(pRoot, pObject, Properties[i]);
				break;
			}
		case eptOgreVector2:
			{
				AddPropertyToGrid_AsString<Ogre::Vector2>(pRoot, pObject, Properties[i]);
			}
			break;
		case eptOgreVector3:
			{
				AddPropertyToGrid_AsString<Ogre::Vector3>(pRoot, pObject, Properties[i]);
			}
			break;
		case eptOgreVector4:
			{
				AddPropertyToGrid_AsString<Ogre::Vector4>(pRoot, pObject, Properties[i]);
			}
			break;
		case eptOgreColorValue:
			{
				TypedProperty<Ogre::ColourValue>* pTypedProperty = (TypedProperty<Ogre::ColourValue>*)Properties[i];
				Ogre::ColourValue val = pTypedProperty->GetValue(pObject);

				CMFCPropertyGridProperty* pGrid = new CMFCPropertyGridColorProperty(
					pTypedProperty->GetName().c_str()
					, val.getAsRGBA()
					, 0
					, pTypedProperty->GetDescription().c_str()
					);

				pRoot->AddSubItem( pGrid );

				CReflectiveUI::SPropertyObject PO(Properties[i], pObject);
				_GridPropertyMap[pGrid] = PO;
			}
			break;
		case eptOgreQuaternion:
			{
				AddPropertyToGrid_AsString<Ogre::Quaternion>(pRoot, pObject, Properties[i]);
			}
			break;
		case eptOgreMatrix3:
			{
				AddPropertyToGrid_AsString<Ogre::Matrix3>(pRoot, pObject, Properties[i]);
			}
			break;
		case eptOgreMatrix4:
			{
				AddPropertyToGrid_AsString<Ogre::Matrix4>(pRoot, pObject, Properties[i]);
			}
			break;
		};
	}

	pRoot->Expand();
}
Beispiel #11
0
 bool operator()(const Ogre::ColourValue &a, const Ogre::ColourValue &b) const
 {
     return a.getAsBGRA() < b.getAsBGRA();
 }
Beispiel #12
0
void CubeWorld::createChunk (Ogre::ManualObject* MeshChunk, const int StartX, const int StartY, const int StartZ)
{
	block_t LastBlock = 0;

	//Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshMatChunk" + Ogre::StringConverter::toString(m_ChunkID));
	//MeshChunk->begin("TerrainImage");

	int iVertex = 0;
	block_t Block;
	block_t Block1;

	/* Only create visible faces of each chunk */
	block_t DefaultBlock = 1;
	int SX = 0;
	int SY = 0;
	int SZ = 0;
	int MaxSize = WORLD_SIZE;
	float V1, V2;
	float BlockLight;

	Ogre::ColourValue BlockColory1;    //Top face
	Ogre::ColourValue BlockColory2;    //Bottom face
	Ogre::ColourValue BlockColorx1;    //Sunset face
	Ogre::ColourValue BlockColorx2;    //Sunrise face
	Ogre::ColourValue BlockColorz;     //Front/back faces

	for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
	    {
		    for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
			{
				for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
				    {
					    Block = GetBlock(x,y,z);
					    if (Block == 0) continue; // Ignore air blocks
					    if (Block == 5) continue; // Ignore water blocks

					    //Compute the block's texture coordinates
					    V1 = 0.25f * (float)(Block - 1);
					    V2 = V1 + 0.25f;

					    BlockLight  = GetBlockLight(x, y, z) / 255.0f;  //For the two x faces
					    float BlockLight1 = BlockLight * 0.9f;		//For the two z faces
					    float BlockLight2 = BlockLight * 0.8f;		//For the two y faces
					    // std::cerr << "*** BlockLight: " << BlockLight << std::endl;
					    // std::cerr << "*** BlockLight1: " << BlockLight1 << std::endl;
					    // std::cerr << "*** BlockLight2: " << BlockLight2 << std::endl;

					    float BaseLight = GetBlockLight(x, y, z) / 255.0f;
					    float Factor;

					    if (m_LightAngle >= 0 && m_LightAngle <= 180)
						    Factor = sin(m_LightAngle * 3.1415926f / 180.0f);
					    else
						    Factor = 0;

					    if (Factor < 0.1f)
						    Factor = 0.1f;
					    BlockColory1 = m_LightColor * (Factor * BaseLight) + m_AmbientColor;
					    BlockColory1.saturate();
					    BlockColory2 = m_LightColor * (Factor / 2.0f * BaseLight) + m_AmbientColor;
					    BlockColory2.saturate();
					    BlockColorz  = m_LightColor * (Factor * 0.70f * BaseLight) + m_AmbientColor;
					    BlockColorz.saturate();
					    BlockColorz *= 0.80f;

					    if (m_LightAngle >= 315 || m_LightAngle <= 45)
						    Factor = fabs(cos(m_LightAngle * 3.1415926f / 180.0f));
					    else
						    Factor = fabs(sin(m_LightAngle * 3.1415926f / 180.0f));
					    if (Factor < 0.1f)
						    Factor = 0.1f;
					    BlockColorx1 = m_LightColor * (Factor * 0.80f * BaseLight) + m_AmbientColor;
					    BlockColorx1.saturate();
					    BlockColorx1 *= 0.95f;

					    if (m_LightAngle >= 135 && m_LightAngle <= 225)
						    Factor = fabs(cos(m_LightAngle * 3.1415926f / 180.0f));
					    else
						    Factor = fabs(sin(m_LightAngle * 3.1415926f / 180.0f));

					    if (Factor < 0.1f)
						    Factor = 0.1f;
					    BlockColorx2 = m_LightColor * (Factor * 0.80f * BaseLight) + m_AmbientColor;
					    BlockColorx2.saturate();
					    BlockColorx2 *= 0.95f;


					    Block1 = DefaultBlock;
					    if (x > SX)
						    Block1 = GetBlock(x-1,y,z);
					    //x-1
					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x, y,   z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColorx1);
							MeshChunk->position(x, y+1, z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColorx1);
							MeshChunk->position(x, y+1, z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColorx1);
							MeshChunk->position(x, y,   z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColorx1);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}

					    //x+1
					    Block1 = DefaultBlock;
					    if (x < SX + MaxSize - 1)
						    Block1 = GetBlock(x+1,y,z);

					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x+1, y,   z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColorx2);
							MeshChunk->position(x+1, y+1, z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColorx2);
							MeshChunk->position(x+1, y+1, z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColorx2);
							MeshChunk->position(x+1, y,   z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColorx2);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}

					    //y-1
					    Block1 = DefaultBlock;
					    if (y > SY)
						    Block1 = GetBlock(x,y-1,z);

					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x,   y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColory1);
							MeshChunk->position(x+1, y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColory1);
							MeshChunk->position(x+1, y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColory1);
							MeshChunk->position(x,   y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColory1);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}


					    //y+1
					    Block1 = DefaultBlock;
					    if (y < SY + MaxSize - 1)
						    Block1 = GetBlock(x,y+1,z);

					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColory2);
							MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColory2);
							MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColory2);
							MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColory2);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}

					    //z-1
					    Block1 = DefaultBlock;
					    if (z > SZ)
						    Block1 = GetBlock(x,y,z-1);

					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x+1, y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x,   y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColorz);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}


					    //z+1
					    Block1 = DefaultBlock;
					    if (z < SZ + MaxSize - 1)
						    Block1 = GetBlock(x,y,z+1);

					    if (g_BlockInfo[Block1].Transparent)
						{
							MeshChunk->position(x,   y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x+1, y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockColorz);
							MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockColorz);

							MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
							MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

							iVertex += 4;
						}



				    }
			}
	    }

	MeshChunk->end();
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(MeshChunk);
	++m_ChunkID;

}
Beispiel #13
0
bool MaterialVertexBuffer::setSubMeshColors(
	EntityMaterial* entity,
	unsigned short mesh_index,
	size_t ui32VertexColorCount,
	const float* pVertexColorArray) const
{
	if(entity->getOgreEntity() == NULL)
	{
		m_rKernelContext.getLogManager() << LogLevel_Error << "Can't set colors : no Entity found!\n";
		return false;
	}

	Ogre::Mesh* mesh = entity->getOgreEntity()->getMesh().get();

	if(mesh == NULL || mesh_index >= mesh->getNumSubMeshes())
	{
		m_rKernelContext.getLogManager() << LogLevel_Error << "Can't set colors : no Mesh found!\n";
		return false;
	}

	Ogre::SubMesh* submesh = mesh->getSubMesh( mesh_index );

	if(submesh->useSharedVertices)
	{
		m_rKernelContext.getLogManager() << LogLevel_Error << "Can't set colors : vertices are shared and thus not accessible from SubMesh!\n";
		return false;
	}
	else
	{
		if(ui32VertexColorCount != submesh->vertexData->vertexCount)
		{
			m_rKernelContext.getLogManager() << LogLevel_Error << "Can't set colors : vertex count mismatch!\n";
			return false;
		}

		//get pointer to submesh vertex data
		Ogre::VertexData* vertex_data = submesh->vertexData;

		//get pointer to DIFFUSE element
		const Ogre::VertexElement* difElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_DIFFUSE);

		if(difElem == NULL)
		{
			m_rKernelContext.getLogManager() << LogLevel_Error << "Can't set colors : no colours_diffuse element found in vertex buffer!\n";
			return false;
		}

		//convert color to current RenderSystem's format
		Ogre::VertexElementType type = difElem->getType();

		//retrieve VB for DIFFUSE element
		Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(difElem->getSource());

		//lock VB for reading
		unsigned char* color = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL));

		// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
		//  as second argument. So make it float, to avoid trouble when Ogre::Real will
		//  be comiled/typedefed as double:
		//      Ogre::Real* pReal;
		Ogre::RGBA* pRGBA;
		Ogre::ColourValue colour;

		for( size_t j = 0; j < vertex_data->vertexCount; ++j, color += vbuf->getVertexSize())
		{
			//get pointer to RGBA DIFFUSE data
			difElem->baseVertexPointerToElement(color, &pRGBA);

			colour.r = pVertexColorArray[4*j];
			colour.g = pVertexColorArray[4*j+1];
			colour.b = pVertexColorArray[4*j+2];
			colour.a = pVertexColorArray[4*j+3];

			//convert color from RGBA floats to a single ARGB uint32
			if(type == Ogre::VET_COLOUR_ARGB) //D3D format
			{
				*pRGBA = colour.getAsARGB();
			}
			else /*if type == OGRE::VET_COLOUR_ABGR)*/ //GL format
			{
				*pRGBA = colour.getAsABGR();
			}
		}

		//unlock VB
		vbuf->unlock();
	}

	return true;
}
Beispiel #14
0
void PlantAreaQueryResult::setDefaultShadowColour(const Ogre::ColourValue& colour)
{
	//Make sure to saturate so the values are clamped to [0..1]
	mDefaultShadowColourValue = colour.saturateCopy();
	mDefaultShadowColourLong = mDefaultShadowColourValue.getAsARGB();
}
    // ----------------------------------------------------------------------
    void FontSerializer::importFont(Ogre::DataStreamPtr &stream, Font *pDest)
    {
        uint32 fccomp;
        stream->read(&fccomp, sizeof(uint32));
        if(fccomp != Font::mFourCC)
            SONETTO_THROW("Invalid Font File");
        stream->read(&pDest->mVersion, sizeof(uint32));
        stream->read(&pDest->mEncode, sizeof(uint32));
        stream->read(&pDest->mVerticalOffsetTop, sizeof(float));
        stream->read(&pDest->mVerticalOffsetBottom, sizeof(float));
        stream->read(&pDest->mHorizontalScale, sizeof(float));

        pDest->mIName = loadString(stream);

        // setup material
        pDest->mMaterial = Ogre::MaterialManager::getSingleton().create(pDest->mIName+"_mat",pDest->getGroup());

        if(pDest->mMaterial.isNull())
            SONETTO_THROW("Unable to create material for font.");

        Ogre::Pass * pass = pDest->mMaterial->getTechnique(0)->getPass(0);

        bool has_separate_blend;
        uint32 mat_scene_blend_source;
        uint32 mat_scene_blend_dest;
        uint32 mat_scene_blend_source_a;
        uint32 mat_scene_blend_dest_a;
        stream->read(&has_separate_blend, sizeof(bool));
        stream->read(&mat_scene_blend_source, sizeof(uint32));
        stream->read(&mat_scene_blend_dest, sizeof(uint32));
        stream->read(&mat_scene_blend_source_a, sizeof(uint32));
        stream->read(&mat_scene_blend_dest_a, sizeof(uint32));

        if(has_separate_blend)
        {
            pass->setSeparateSceneBlending( (Ogre::SceneBlendFactor)mat_scene_blend_source,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_dest,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_source_a,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_dest_a);
        } else {
            pass->setSceneBlending((Ogre::SceneBlendFactor)mat_scene_blend_source,(Ogre::SceneBlendFactor)mat_scene_blend_dest);
        }
        uint32 mat_alpha_reject_func;
        uint8 mat_alpha_reject_val;
        bool map_alpha_reject_atc;
        stream->read(&mat_alpha_reject_func, sizeof(uint32));
        stream->read(&mat_alpha_reject_val, sizeof(uint8));
        stream->read(&map_alpha_reject_atc, sizeof(bool));

        pass->setAlphaRejectSettings((Ogre::CompareFunction) mat_alpha_reject_func, mat_alpha_reject_val, map_alpha_reject_atc);

        pass->setDepthCheckEnabled(false);
        pass->setDepthWriteEnabled(false);
        pass->setLightingEnabled(false);

        Ogre::TextureUnitState * tex_unit = pass->createTextureUnitState();

        uint32 tex_address_mode_u;
        uint32 tex_address_mode_v;
        uint32 tex_address_mode_w;
        uint32 tex_filtering_min;
        uint32 tex_filtering_mag;
        Ogre::ColourValue tex_border_color;
        stream->read(&tex_address_mode_u, sizeof(uint32));
        stream->read(&tex_address_mode_v, sizeof(uint32));
        stream->read(&tex_address_mode_w, sizeof(uint32));
        stream->read(&tex_filtering_min, sizeof(uint32));
        stream->read(&tex_filtering_mag, sizeof(uint32));
        stream->read(tex_border_color.ptr(), sizeof(float) * 4);

        tex_unit->setTextureAddressingMode( (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_u,
                                            (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_v,
                                            (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_w);
        tex_unit->setTextureFiltering((Ogre::FilterOptions)tex_filtering_min, (Ogre::FilterOptions)tex_filtering_mag, Ogre::FO_NONE);
        tex_unit->setTextureBorderColour(tex_border_color);

        uint32 numcol = 0;
        stream->read(&numcol, sizeof(uint32));
        for(uint32 l = 0; l != numcol; ++l)
        {
            std::cout << "reading color #"<<l<<"...\n";
            Ogre::ColourValue color;
            stream->read(color.ptr(), sizeof(float) * 4);
            pDest->mColorList.push_back(color);
            std::cout << "color #"<<l<<" read complete...\n";
        }
        std::cout << "all color values have been read correctly...\n";
        std::cout << "reading font glyph list...\n";
        for(uint16 i = 0; i != 256; ++i)
        {
            std::cout << "reading glyph #"<<(int)i<<"...\n";
            FontGlyph glyph;
            stream->read(&glyph, sizeof(FontGlyph));
            pDest->mGlyph.push_back(glyph);
            std::cout << "glyph #"<<(int)i<<" read complete...\n";
        }
        std::cout << "all font glyph have been read correctly...\n";
        // size_t width, size_t height, size_t depth, size_t pixel format
        size_t txt_width, txt_height, txt_depth, txt_pixelformat, txt_faces, txt_mipmaps = 0;
        stream->read(&txt_width, sizeof(size_t));
        stream->read(&txt_height, sizeof(size_t));
        stream->read(&txt_depth, sizeof(size_t));
        stream->read(&txt_pixelformat, sizeof(size_t));
        stream->read(&txt_faces, sizeof(size_t));
        stream->read(&txt_mipmaps, sizeof(size_t));

        std::cout <<
        "Loading Font Texture Data...\n"
        "Texture Width: "<<txt_width<<"\n"
        "Texture Height: "<<txt_height<<"\n"
        "Texture Depth: "<<txt_depth<<"\n"
        "Texture Pixel Format: "<<txt_pixelformat<<"\n"
        "Texture Faces: "<<txt_faces<<"\n"
        "Texture Mipmaps: "<<txt_mipmaps<<"\n";

        pDest->mFontImage = new Ogre::Image();

        size_t totalimagesize = Ogre::Image::calculateSize(txt_mipmaps, txt_faces, txt_width, txt_height, txt_depth, (Ogre::PixelFormat)txt_pixelformat);

        std::cout << "Current position at file: "<<stream->tell()<<"\n"
        "Target Image Size: "<<totalimagesize<<"\n"
        "Remaining File Size: "<<stream->size()<<"\n";

        unsigned char * imgbuffer = new unsigned char [totalimagesize];

        stream->read(imgbuffer, totalimagesize);

        pDest->mFontImage->loadDynamicImage(imgbuffer, txt_width, txt_height, txt_depth, (Ogre::PixelFormat)txt_pixelformat, true, txt_faces, txt_mipmaps);

        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().loadImage(pDest->mIName+"_tex",pDest->getGroup(), *pDest->mFontImage, Ogre::TEX_TYPE_2D, 0);

        tex_unit->setTextureName(texture->getName(), Ogre::TEX_TYPE_2D);
    }
void SubChunkMeshGenerator::generateSideMesh(Ogre::ManualObject * obj,
    const Int3D & absolute_position, const Block & block,
    const BlockData & block_data, BlockFaceDirection side_index)
{
    if (block_data.side_textures.at(side_index).isEmpty())
        return;


    // if the block on this side is opaque or the same block, skip
    Block neighbor_block = m_owner->game()->blockAt(absolute_position + c_side_offset[side_index]);
    Item::ItemType side_type = neighbor_block.type();
    if ((side_type == block.type() && (block_data.partial_alpha || side_type == Item::Glass)) ||
        ! m_block_data.value(side_type, m_air).see_through)
    {
        return;
    }

    // add this side to mesh
    Ogre::Vector3 abs_block_loc(absolute_position.x, absolute_position.y, absolute_position.z);

    // special cases for textures
    QString texture_name = block_data.side_textures.at(side_index);
    switch (block.type()) {
        case Item::Wood:
        if (side_index != NegativeZ && side_index != PositiveZ) {
            switch (block.woodMetadata()) {
            case Item::NormalTrunkTexture:
                texture_name = "WoodSide";
                break;
            case Item::RedwoodTrunkTexture:
                texture_name = "RedwoodTrunkSide";
                break;
            case Item::BirchTrunkTexture:
                texture_name = "BirchTrunkSide";
                break;
            }
        }
        break;
        case Item::Leaves:
        {
            switch (block.leavesMetadata()) {
            case Item::NormalLeavesTexture:
                texture_name = "LeavesRegular";
                break;
            case Item::RedwoodLeavesTexture:
                texture_name = "RedwoodLeaves";
                break;
            case Item::BirchLeavesTexture:
                texture_name = "BirchLeaves";
                break;
            }
        }
        break;
        case Item::Farmland:
        if (side_index == PositiveZ)
            texture_name = block.farmlandMetadata() == 0 ? "FarmlandDry" : "FarmlandWet";
        break;
        case Item::Crops:
        texture_name = QString("Crops") + QString::number(block.cropsMetadata());
        break;
        case Item::Wool:
        texture_name = c_wool_texture_names[block.woolMetadata()];
        break;
        case Item::Furnace:
        case Item::BurningFurnace:
        case Item::Dispenser:
        {
            if (side_index != NegativeZ && side_index != PositiveZ) {
                if ((block.furnaceMetadata() == Item::EastFacingFurnace && side_index == PositiveX) ||
                    (block.furnaceMetadata() == Item::WestFacingFurnace && side_index == NegativeX) ||
                    (block.furnaceMetadata() == Item::NorthFacingFurnace && side_index == PositiveY) ||
                    (block.furnaceMetadata() == Item::SouthFacingFurnace && side_index == NegativeY))
                {
                    texture_name = block_data.side_textures.value(NegativeY);
                } else {
                    texture_name = "FurnaceBack";
                }
            }
        }
        break;
        case Item::Pumpkin:
        case Item::JackOLantern:
        {
            if (side_index != NegativeZ && side_index != PositiveZ) {
                if ((block.pumpkinMetadata() == Item::EastFacingPumpkin && side_index == PositiveX) ||
                    (block.pumpkinMetadata() == Item::WestFacingPumpkin && side_index == NegativeX) ||
                    (block.pumpkinMetadata() == Item::NorthFacingPumpkin && side_index == PositiveY) ||
                    (block.pumpkinMetadata() == Item::SouthFacingPumpkin && side_index == NegativeY))
                {
                    texture_name = block_data.side_textures.value(NegativeY);
                } else {
                    texture_name = "PumpkinBack";
                }
            }
        }
        break;
        case Item::RedstoneWire_placed:
        {
            if (block.redstoneMetadata() == 0) {
                texture_name = "RedWire4wayOff";
            } else {
                texture_name = "RedWire4wayOn";
            }
        }
        break;
        default:;
    }
    MainWindow::BlockTextureCoord btc = m_owner->texCoords(texture_name);

    Ogre::Vector3 squish = block_data.squish_amount.at(side_index);

    float brightness;
    int night_darkness = 0;
    brightness = c_light_brightness[qMax(neighbor_block.skyLight() - night_darkness, neighbor_block.light())];

    Ogre::ColourValue color = Ogre::ColourValue::White;
    if (block.type() == Item::Grass && side_index == PositiveZ)
        color.setAsRGBA(0x8DD55EFF);
    else if (block.type() == Item::Leaves)
        color.setAsRGBA(0x8DD55EFF);

    color *= brightness;
    color *= c_brightness_bias[side_index];

    for (int triangle_index = 0; triangle_index < 2; triangle_index++) {
        for (int point_index = 0; point_index < 3; point_index++) {
            Ogre::Vector3 pos = c_side_coord[side_index][triangle_index][point_index] - squish;
            if (block_data.rotate) {
                pos -= 0.5f;
                pos = Ogre::Quaternion(Ogre::Degree(45), Ogre::Vector3::UNIT_Z) * pos;
                pos += 0.5f;
            }
            obj->position(pos + abs_block_loc);

            Ogre::Vector2 tex_coord = c_tex_coord[triangle_index][point_index];
            obj->textureCoord((btc.x+tex_coord.x*btc.w) / c_terrain_png_width, (btc.y+tex_coord.y*btc.h) / c_terrain_png_height);

            obj->colour(color);
        }
    }
}
void CReflectiveUI::OnPropertyChanged(CMFCPropertyGridProperty* pProp)
{
	//if (!ValidateItemData(pProp))
	//{
	//	return;
	//}

	CMFCPropertyGridProperty* pItem = pProp;

	const COleVariant variant = pItem->GetValue();

	assert( _GridPropertyMap.find(pItem) != _GridPropertyMap.end() );
	SPropertyObject PO = _GridPropertyMap[pItem];

	switch ( PO._pProperty->GetTypeID() )
	{
	case eptBool:
		{
			TypedProperty<bool>* pTypedProperty = (TypedProperty<bool>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().boolVal != 0);
			break;
		}
	case eptByte:
		{
			TypedProperty<char>* pTypedProperty = (TypedProperty<char>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().bVal );
			break;
		}
	case eptShort:
		{
			TypedProperty<short>* pTypedProperty = (TypedProperty<short>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().iVal );
			break;
		}
	case eptInt:
		{
			TypedProperty<int>* pTypedProperty = (TypedProperty<int>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().intVal );
			break;
		}
	case eptLong:
		{
			TypedProperty<long>* pTypedProperty = (TypedProperty<long>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().lVal );
			break;
		}
	case eptPtr:
		{
			break;
		}
	case eptOgreReal:
		{
			TypedProperty<Ogre::Real>* pTypedProperty = (TypedProperty<Ogre::Real>*)PO._pProperty;
			pTypedProperty->SetValue( PO._pObject, pItem->GetValue().fltVal );
			break;
		}
	case eptOgreString:
		{
			TypedProperty<Ogre::String>* pTypedProperty = (TypedProperty<Ogre::String>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
			break;
		}
	case eptOgreVector2:
		{
			TypedProperty<Ogre::Vector2>* pTypedProperty = (TypedProperty<Ogre::Vector2>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	case eptOgreVector3:
		{
			TypedProperty<Ogre::Vector3>* pTypedProperty = (TypedProperty<Ogre::Vector3>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	case eptOgreVector4:
		{
			TypedProperty<Ogre::Vector4>* pTypedProperty = (TypedProperty<Ogre::Vector4>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	case eptOgreColorValue:
		{
			TypedProperty<Ogre::ColourValue>* pTypedProperty = (TypedProperty<Ogre::ColourValue>*)PO._pProperty;
			Ogre::ColourValue val;
			val.setAsABGR(pItem->GetValue().intVal);
			pTypedProperty->SetValue( PO._pObject, val);
		}
		break;
	case eptOgreQuaternion:
		{
			TypedProperty<Ogre::Quaternion>* pTypedProperty = (TypedProperty<Ogre::Quaternion>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	case eptOgreMatrix3:
		{
			TypedProperty<Ogre::Matrix3>* pTypedProperty = (TypedProperty<Ogre::Matrix3>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	case eptOgreMatrix4:
		{
			TypedProperty<Ogre::Matrix4>* pTypedProperty = (TypedProperty<Ogre::Matrix4>*)PO._pProperty;
			GString gStr(pItem->GetValue().bstrVal);
			pTypedProperty->SetValueFromString( PO._pObject, gStr.ToMbcs() );
		}
		break;
	};
}