예제 #1
0
//------------------------------------------------------------------------------
Background2D::Background2D():
    m_AlphaMaxVertexCount( 0 ),
    m_AddMaxVertexCount( 0 ),

    m_ScrollEntity( NULL ),
    m_ScrollPositionStart( Ogre::Vector2::ZERO ),
    m_ScrollPositionEnd( Ogre::Vector2::ZERO ),
    m_ScrollType( Background2D::NONE ),
    m_ScrollSeconds( 0 ),
    m_ScrollCurrentSeconds( 0 ),
    m_Position( Ogre::Vector2::ZERO ),
    m_PositionReal( Ogre::Vector2::ZERO )

   ,m_range( Ogre::AxisAlignedBox::BOX_INFINITE )
    // for ffvii
   ,m_virtual_screen_size( 320, 240 )
{
    m_SceneManager = Ogre::Root::getSingleton().getSceneManager( "Scene" );
    m_RenderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem();

    CreateVertexBuffers();

    m_AlphaMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAlpha", "General" );
    Ogre::Pass* pass = m_AlphaMaterial->getTechnique( 0 )->getPass( 0 );
    pass->setVertexColourTracking( Ogre::TVC_AMBIENT );
    pass->setCullingMode( Ogre::CULL_NONE );
    pass->setDepthCheckEnabled( true );
    pass->setDepthWriteEnabled( true );
    pass->setLightingEnabled( false );
    pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
    pass->setAlphaRejectFunction( Ogre::CMPF_GREATER );
    pass->setAlphaRejectValue( 0 );
    Ogre::TextureUnitState* tex = pass->createTextureUnitState();
    tex->setTextureName( "system/blank.png" );
    tex->setNumMipmaps( -1 );
    tex->setTextureFiltering( Ogre::TFO_NONE );

    m_AddMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAdd", "General" );
    pass = m_AddMaterial->getTechnique( 0 )->getPass( 0 );
    pass->setVertexColourTracking( Ogre::TVC_AMBIENT );
    pass->setCullingMode( Ogre::CULL_NONE );
    pass->setDepthCheckEnabled( true );
    pass->setDepthWriteEnabled( true );
    pass->setLightingEnabled( false );
    pass->setSceneBlending( Ogre::SBT_ADD );
    pass->setAlphaRejectFunction( Ogre::CMPF_GREATER );
    pass->setAlphaRejectValue( 0 );
    tex = pass->createTextureUnitState();
    tex->setTextureName( "system/blank.png" );
    tex->setNumMipmaps( -1 );
    tex->setTextureFiltering( Ogre::TFO_NONE );

    m_SceneManager->addRenderQueueListener( this );
}
예제 #2
0
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tex->setTextureName(pImageFilename);
	tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);

	tech->setLightingEnabled(false);
}
예제 #3
0
void RenderWindow::CreateRenderTargetOverlay(int width, int height)
{
    width = max(1, width);
    height = max(1, height);

    Ogre::TexturePtr renderTarget = Ogre::TextureManager::getSingleton().createManual(
        rttTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::MaterialPtr rttMaterial = Ogre::MaterialManager::getSingleton().create(
        rttMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    Ogre::TextureUnitState *rttTuState = rttMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();

    rttTuState->setTextureName(rttTextureName);
    rttTuState->setTextureFiltering(Ogre::TFO_NONE);
    rttTuState->setNumMipmaps(1);
    rttTuState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);

    rttMaterial->setFog(true, Ogre::FOG_NONE); ///\todo Check, shouldn't here be false?
    rttMaterial->setReceiveShadows(false);
    rttMaterial->setTransparencyCastsShadows(false);

    rttMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE);

    overlayContainer = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "MainWindow Overlay Panel");
    overlayContainer->setMaterialName(rttMaterialName);
    overlayContainer->setMetricsMode(Ogre::GMM_PIXELS);
    overlayContainer->setPosition(0, 0);
    overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height);
    overlayContainer->setPosition(0,0);

    overlay = Ogre::OverlayManager::getSingleton().create("MainWindow Overlay");
    overlay->add2D(static_cast<Ogre::OverlayContainer *>(overlayContainer));
    overlay->setZOrder(500);
    overlay->show();

//    ResizeOverlay(width, height);
}
CRosRttTexture::CRosRttTexture(unsigned width, unsigned height, Ogre::Camera * camera, bool isDepth /*= false*/ )
: m_materialName("MyRttMaterial")
, width_(width)
, height_(height)
, frame_("/map")
, m_bIsDepth( isDepth )
{
  assert( height > 0 && width > 0 );

  {
    // Set encoding
    current_image_.encoding = ROS_IMAGE_FORMAT;

    // Set image size
    current_image_.width = width;
    current_image_.height = height;

    // Set image row length in bytes (row length * 3 bytes for a color)
    current_image_.step = width * BPP;

#if OGRE_ENDIAN == ENDIAN_BIG
    current_image_.is_bigendian = true;
#else
        current_image_.is_bigendian = false;
#endif

    // Resize data
    current_image_.data.resize( width_ * height_ * BPP);

  }

  Ogre::TextureManager & lTextureManager( Ogre::TextureManager::getSingleton() );
  Ogre::String textureName("RVIZ_CamCast_Texture");
  bool lGammaCorrection( false );
  unsigned int lAntiAliasing( 0 );
  unsigned int lNumMipmaps( 0 );

  if( isDepth )
  {
	  texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		  Ogre::TEX_TYPE_2D, width, height, lNumMipmaps,
		  OGRE_DEPTH_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing);
  }
  else
  {
	  texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	  		  Ogre::TEX_TYPE_2D, width, height, lNumMipmaps,
	  		  OGRE_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing);
  }

  // Create render target
  Ogre::RenderTexture* lRenderTarget = NULL;

  Ogre::HardwarePixelBufferSharedPtr lRttBuffer = texture_->getBuffer();
  lRenderTarget = lRttBuffer->getRenderTarget();
  lRenderTarget->setAutoUpdated(true);

  // Create and attach viewport

  Ogre::Viewport* lRttViewport1 = lRenderTarget->addViewport(camera, 50, 0.00f, 0.00f, 1.0f, 1.0f);
  lRttViewport1->setAutoUpdated(true);
  Ogre::ColourValue lBgColor1(0.0,0.0,0.0,1.0);
  lRttViewport1->setBackgroundColour(lBgColor1);

  // create a material using this texture.

  //Get a reference on the material manager, which is a singleton.
  Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton();
  Ogre::MaterialPtr lMaterial = lMaterialManager.create(m_materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  Ogre::Technique * lTechnique = lMaterial->getTechnique(0);
  Ogre::Pass* lPass = lTechnique->getPass(0);

  if( isDepth )
  {
	  lPass->setLightingEnabled(false);
  }

  Ogre::TextureUnitState* lTextureUnit = lPass->createTextureUnitState();
  lTextureUnit->setTextureName(textureName);

  lTextureUnit->setNumMipmaps(0);
  lTextureUnit->setTextureFiltering(Ogre::TFO_BILINEAR);

  update();
}
예제 #5
0
void UniversePlanet::create() {
    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true);
    Ogre::Technique* tech = mat->getTechnique(0);
    Ogre::Pass* pass = tech->getPass(0);
    Ogre::TextureUnitState* tex = pass->createTextureUnitState();

    tex->setTextureName("materials/textures/grass.png");
    tex->setNumMipmaps(4);
    tex->setTextureAnisotropy(1);
    tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

    ManualObject *meshChunk = new ManualObject("meshChunk_" + getName());
    int iVertex = 0;
    block_t currentBlock;
    block_t nextBlock;
    Ogre::Vector3 v;

    meshChunk->begin("BoxColor");

    for(int w = 0; w < 6; ++w)
        for(int z = 0; z < mWorldHeight; ++z)
            for(int y = 0; y < mWorldSize; ++y)
                for(int x = 0; x < mWorldSize; ++x) {
                    currentBlock = getBlock(w, x, y, z);
                    if(currentBlock == 0) continue;

                    //x-1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x - 1, y, z);
                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //x+1

                    nextBlock = 0;
                    nextBlock = getBlock(w, x + 1, y, z);
                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //y-1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y - 1, z);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //y+1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y + 1, z);

                    if(nextBlock == 0) {

                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //z-1 ok
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y, z - 1);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);
                        else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);

                        iVertex += 4;
                    }

                    //z+1 ok
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y, z + 1);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 1 || w == 2 || w == 4) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);
                        else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);

                        iVertex += 4;
                    }

                }
    meshChunk->end();
    Application::getSceneMgr()->getRootSceneNode()->createChildSceneNode()->attachObject(meshChunk);

    Application::getSceneMgr()->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
    Ogre::Light* l = Application::getSceneMgr()->createLight("MainLight");
    l->setPosition(20, 80, 50);
}