Example #1
0
bool KinectDevice::UpdateColorDepthTexture()
{
	bool updated = false;

	if (!mColorTexture.isNull() && mColorTextureAvailable)
	{
		Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mColorTexture->getBuffer();
		pixelBuffer->blitFromMemory(mColorPixelBox);
		mColorTextureAvailable = false;
		updated = true;
	}
	if (!mDepthTexture.isNull() && mDepthTextureAvailable)
	{
		Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mDepthTexture->getBuffer();
		pixelBuffer->blitFromMemory(mDepthPixelBox);
		mDepthTextureAvailable = false;
		updated = true;
	}
	if (!mColoredDepthTexture.isNull()&& mColoredDepthTextureAvailable)
	{
		Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mColoredDepthTexture->getBuffer();
		pixelBuffer->blitFromMemory(mColoredDepthPixelBox);		
		mColoredDepthTextureAvailable = false;
		updated = true;
	}

	return updated;
}
void video_display(VideoState *is)
{
  VideoPicture *vp;

  vp = &is->pictq[is->pictq_rindex];

  if (is->video_st->codec->width != 0 && is->video_st->codec->height != 0)
  {
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton ().getByName("VideoTexture");
    if (texture.isNull () || texture->getWidth() != is->video_st->codec->width || texture->getHeight() != is->video_st->codec->height)
    {
      Ogre::TextureManager::getSingleton ().remove ("VideoTexture");
      texture = Ogre::TextureManager::getSingleton().createManual(
                  "VideoTexture",
                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                  Ogre::TEX_TYPE_2D,
                  is->video_st->codec->width, is->video_st->codec->height,
                  0,
                  Ogre::PF_BYTE_RGBA,
                  Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
    }
    Ogre::PixelBox pb(is->video_st->codec->width, is->video_st->codec->height, 1, Ogre::PF_BYTE_RGBA, vp->data);
    Ogre::HardwarePixelBufferSharedPtr buffer = texture->getBuffer();
    buffer->blitFromMemory(pb);
  }

  free(vp->data);
}
/**
 * @inheritDoc.
 */
void BrowserWindow::onPaint(Berkelium::Window *win, const unsigned char *sourceBuffer, const Berkelium::Rect &sourceBufferRect, size_t numCopyRects, const Berkelium::Rect *copyRects, int dx, int dy, const Berkelium::Rect &scrollRect) {
    const Ogre::HardwarePixelBufferSharedPtr textureBuffer = m_texture->getBuffer();
    const Ogre::PixelBox srcBox = Ogre::PixelBox(rectToBox(sourceBufferRect), Ogre::PF_BYTE_BGRA, const_cast<unsigned char*>(sourceBuffer));

    for(int i = 0; i < numCopyRects; i++) {
        const Ogre::Box destBox = rectToBox(copyRects[i]);
        textureBuffer->blitFromMemory(srcBox.getSubVolume(destBox), destBox);
    }
}
Example #4
0
void HTML::Paint(Ogre::HardwarePixelBufferSharedPtr pixelBuffer, const unsigned char*srcBuffer, const Berkelium::Rect& srcRect, size_t num_copy_rects, const Berkelium::Rect *copy_rects)
{
  /**/
  const Ogre::PixelBox srcBox = Ogre::PixelBox(ToBox(srcRect), Ogre::PF_BYTE_BGRA, const_cast<unsigned char*>(srcBuffer));

  for(unsigned int i = 0; i < num_copy_rects; i++)
  {
    const Ogre::Box destBox = ToBox(copy_rects[i]);
    pixelBuffer->blitFromMemory(srcBox.getSubVolume(destBox), destBox);
  }

}
Example #5
0
bool OgreARAppLogic::update(Ogre::Real deltaTime)
{
	if (!pause) {
		if( !userUpdate(this)) return false; // call user-defined funcions

		// update background image
		if (!mTexture.isNull())
		{
			//Pedimos a ogre que actualice la imagen desde el PixelBox
			Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer();
			pixelBuffer->blitFromMemory(mPixelBox);
		}	  	  
	}

	bool result = processInputs(deltaTime);
	return result;
}
Example #6
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++;
            }
        }
    }
Example #7
0
void
Terrain::loadResource(Ogre::Resource* resource)
{
	const Ogre::String& name = resource->getName();
    if (name.find("<Lightmap>") !=Ogre::String::npos)
	{
       Ogre::String::size_type left_parentheses = name.find_first_of('(');
       Ogre::String::size_type right_parentheses = name.find_last_of(')');
        if (left_parentheses ==Ogre::String::npos ||
            right_parentheses ==Ogre::String::npos)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
                "Unorganised lightmap texture name '" + name + "'",
                "Terrain::loadResource");
        }

        Ogre::StringVector vec = Ogre::StringUtil::split(
            name.substr(left_parentheses + 1, right_parentheses - left_parentheses - 1), ",", 2);
        if (vec.size() != 2)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
                "Unorganised lightmap texture name '" + name + "'",
                "Terrain::loadResource");
        }

        int nPosX = Ogre::StringConverter::parseInt(vec[0]);
        int nPosZ = Ogre::StringConverter::parseInt(vec[1]);
        if (nPosX < 0 || nPosX >= mData->mNumTilePerX ||
            nPosZ < 0 || nPosZ >= mData->mNumTilePerZ)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
                "Unorganised lightmap texture name '" + name + "'",
                "Terrain::loadResource");
        }

        Ogre::uint uWidth, uHeight;
        if (getLightmapQuality() == LMQ_LOW)
        {
            uWidth = mData->mTileSize * 2;
            uHeight = mData->mTileSize * 2;
        }
        else
        {
            uWidth = mData->mTileSize * 8;
            uHeight = mData->mTileSize * 8;
        }

		Ogre::Texture* pTexture = static_cast<Ogre::Texture*>(resource);
        if (pTexture->getWidth() != uWidth || pTexture->getHeight() != uHeight)
        {
            pTexture->freeInternalResources();
            pTexture->setWidth(uWidth);
            pTexture->setHeight(uHeight);
        }
		pTexture->createInternalResources();

		Ogre::HardwarePixelBufferSharedPtr bufferPtr = pTexture->getBuffer();
        size_t l = nPosX * mData->mTileSize * 8;
        size_t t = nPosZ * mData->mTileSize * 8;
        size_t r = l + mData->mTileSize * 8;
        size_t b = t + mData->mTileSize * 8;
        if (r > mData->mLightmapImage->getWidth())
            r = mData->mLightmapImage->getWidth();
        if (b > mData->mLightmapImage->getHeight())
            b = mData->mLightmapImage->getHeight();
		bufferPtr->blitFromMemory(
			mData->mLightmapImage->getPixelBox().getSubVolume(Ogre::Box(l, t, r, b)));
	}
	else
	{
		for (AtlasArray::const_iterator it = mAtlases.begin(); it != mAtlases.end(); ++it)
		{
			if (it->texture.get() == resource)
			{
                assert(!it->image.isNull());
				it->texture->loadImage(*it->image);
				break;
			}
		}
	}
}
Example #8
0
void TextureBlitTest::setupContent()
{
    static const Ogre::String ColorTextureName = "VTests_TextureBlit_color_texture";
    static const Ogre::String DepthTextureName = "VTests_TextureBlit_depth_texture";
    static const int TextureSize = 8;

    mViewport->setBackgroundColour(ColourValue(0.8,0.8,0.8));

    /// TEST COLOUR
    m_colorTexture = Ogre::TextureManager::getSingleton().createManual(
                         ColorTextureName,
                         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                         Ogre::TEX_TYPE_2D,
                         TextureSize, TextureSize,
                         0,
                         Ogre::PF_BYTE_RGB,
                         Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::PixelBox pb(ColorImage.width, ColorImage.height, 1, Ogre::PF_BYTE_RGB, (void *)ColorImage.pixel_data);
    Ogre::HardwarePixelBufferSharedPtr buffer = m_colorTexture->getBuffer();
    buffer->blitFromMemory(pb);

    // Get the material
    Ogre::MaterialPtr matColourPtr = Ogre::MaterialManager::getSingleton().getByName("Examples/OgreDance");

    ReplaceTexture(matColourPtr, ColorTextureName);

    // create a standard plane entity
    Entity* ent = mSceneMgr->createEntity("Plane_color", SceneManager::PT_PLANE);

    // attach it to a node, scale it, and position appropriately
    SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    node->setPosition(-30.0, 0.0, 0.0);
    node->setScale(0.25, 0.25, 0.25);
    node->attachObject(ent);

    ent->setMaterial(matColourPtr);  // give it the material we prepared

    /// TEST DEPTH
    m_depthTexture = Ogre::TextureManager::getSingleton().createManual(
                         DepthTextureName,
                         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                         Ogre::TEX_TYPE_2D,
                         TextureSize, TextureSize,
                         0,
                         Ogre::PF_DEPTH,
                         Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::PixelBox dpb(DepthImage.width, DepthImage.height, 1, Ogre::PF_DEPTH, (void *)DepthImage.pixel_data);
    Ogre::HardwarePixelBufferSharedPtr dbuffer = m_depthTexture->getBuffer();
    dbuffer->blitFromMemory(dpb);

    // Get the material
    Ogre::MaterialPtr matDepthPtr = Ogre::MaterialManager::getSingleton().getByName("Examples/OgreParade");

    ReplaceTexture(matDepthPtr, DepthTextureName);

    // create a standard plane entity
    Entity* depthEnt = mSceneMgr->createEntity("Plane_depth", SceneManager::PT_PLANE);

    // attach it to a node, scale it, and position appropriately
    SceneNode* depthNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    depthNode->setPosition(30.0, 0.0, 0.0);
    depthNode->setScale(0.25, 0.25, 0.25);
    depthNode->attachObject(depthEnt);

    depthEnt->setMaterial(matDepthPtr);  // give it the material we prepared

    mCamera->setPosition(0,0,125);
    mCamera->setDirection(0,0,-1);
}