Commits

Anonymous committed 77f68f8

refactoring : OgreVideoCanvas as a staticlib

  • Participants
  • Parent commits 8ea9fa8

Comments (0)

Files changed (10)

File OgreVideoCanvas/include/OgreVideoCanvas.h

+#pragma once
+
+#include <Ogre.h>
+#include "OgreVideoTexture.h"
+
+using namespace Ogre;
+
+class OgreVideoCanvas
+{
+public:
+    OgreVideoCanvas(const String&, SceneManager*);
+    ~OgreVideoCanvas(void);
+
+    void buildCanvas(SceneNode*);
+    void nextFrame();
+
+protected:
+    void _initVideoTexture(){};
+
+protected:
+    SceneManager *mSceneMgr;
+    String mVideoFileName;
+    SceneNode *mCanvasNode;
+    ManualObject *mCanvas;
+    OgreVideoTexture *mVideoTexture;
+    int mWidth, mHeight, mTextureSize;
+
+};

File OgreVideoCanvas/include/OgreVideoTexture.h

+#pragma once
+
+
+#include <cv.h>
+#include <highgui.h>
+
+#include <Ogre.h>
+
+
+class OgreVideoTexture
+{
+public:
+    OgreVideoTexture(const Ogre::String);
+    ~OgreVideoTexture(void);
+    Ogre::String getMaterialName() const { return mVideoMaterial->getName();};
+    void nextFrame();
+
+protected:
+    void _init();
+    void _initCapture();
+    void _reinitCapture();
+    void _endCapture();
+    void _createTextureFromCapture(CvCapture*);
+    void _initTexture(Ogre::TexturePtr);
+    void _updateTextureFromImage(const IplImage*);
+    void _destroyTexture();
+
+   
+    inline void _copyImagePerLine(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
+    inline void _copyImagePerPixel(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
+    inline void _copyImagePerChannel(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
+
+protected:
+    Ogre::String mVideoFileName;
+    CvCapture *mCvCapture;
+    IplImage *mCurrentVideoFrame;
+    Ogre::TexturePtr mVideoTexture;
+    Ogre::MaterialPtr mVideoMaterial;
+    Ogre::String mTextureName, mMaterialName;
+    Ogre::Timer mTimeSinceLastUpdate;
+    int mFrameCount, mCurrentFrameIndex;
+    Ogre::Log *mLog;
+    Ogre::Timer mTimer;
+};

File OgreVideoCanvas/src/OgreVideoCanvas.cpp

+#include "OgreVideoCanvas.h"
+
+//------------------------------------------------------------------------------
+OgreVideoCanvas::OgreVideoCanvas(const String &_filename, SceneManager *_sceneMgr)
+    :mSceneMgr(_sceneMgr)
+    ,mVideoFileName(_filename)
+    ,mCanvas(NULL)
+    ,mVideoTexture(NULL)
+    ,mCanvasNode(NULL)
+    ,mWidth(640)
+    ,mHeight(480)
+    ,mTextureSize(1024)
+{
+}
+//------------------------------------------------------------------------------
+OgreVideoCanvas::~OgreVideoCanvas(void)
+{
+}
+//------------------------------------------------------------------------------
+void OgreVideoCanvas::buildCanvas(SceneNode *_parentNode)
+{
+    
+    float uMin = 0, vMin = 0;
+    float uMax = float(mWidth)  / mTextureSize;
+    float vMax = float(mHeight) / mTextureSize;
+
+    mCanvas = mSceneMgr->createManualObject("Video Canvas " + mVideoFileName);
+    mCanvas->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP);
+
+    mCanvas->position(-mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMin, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position( mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMax, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position(-mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMin, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position( mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMax, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+
+    mCanvas->end();
+
+    mCanvasNode = _parentNode->createChildSceneNode("Canvas Node " + mVideoFileName);
+    mCanvasNode ->attachObject(mCanvas);
+    mCanvasNode->yaw(Degree(180.0));
+    mCanvasNode->roll(Degree(180.0));
+
+    mVideoTexture = new OgreVideoTexture(mVideoFileName);
+    mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
+    
+}
+//--------------------------------------------------------------------------------
+void OgreVideoCanvas::nextFrame()
+{
+    mVideoTexture->nextFrame();
+}
+//--------------------------------------------------------------------------------

File OgreVideoCanvas/src/OgreVideoTexture.cpp

+#include "OgreVideoTexture.h"
+
+#include <boost/format.hpp>
+#include <cstring>
+
+//------------------------------------------------------------------------------
+OgreVideoTexture::OgreVideoTexture(const Ogre::String _filename)
+    :mVideoFileName(_filename)
+    ,mCvCapture(NULL)
+    ,mCurrentVideoFrame(NULL)
+    ,mCurrentFrameIndex(0)
+{
+    mLog = Ogre::LogManager::getSingletonPtr()->createLog("OgreVideoTexture_"+_filename+".log");
+    mMaterialName = "Video Material "+ mVideoFileName;
+    mTextureName = "Video Texture " + mVideoFileName;
+    _init();
+}
+//------------------------------------------------------------------------------
+OgreVideoTexture::~OgreVideoTexture(void)
+{
+    _endCapture();
+    _destroyTexture();
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_init()
+{
+    mLog->logMessage("init");
+    
+
+    _initCapture();
+    _createTextureFromCapture(mCvCapture);
+
+    // set first frame
+    mCurrentVideoFrame = cvQueryFrame(mCvCapture);
+    mCurrentFrameIndex++;
+
+    _updateTextureFromImage(mCurrentVideoFrame);
+
+
+    mTimeSinceLastUpdate.reset();
+
+     
+    mLog->logMessage("init done");
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_initCapture()
+{
+    Ogre::String fullName = Ogre::String("../media/videos/") + mVideoFileName;
+    mCvCapture = cvCreateFileCapture(fullName.c_str());
+    mFrameCount = cvGetCaptureProperty(mCvCapture, CV_CAP_PROP_FRAME_COUNT);
+
+    // skip first frame
+    cvGrabFrame(mCvCapture);
+    mCurrentFrameIndex++;
+
+    mLog->logMessage("openned " + fullName);
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_endCapture()
+{
+    cvReleaseCapture(&mCvCapture);
+    mCurrentFrameIndex = 0;
+    mCurrentVideoFrame = NULL;
+    mCvCapture = NULL;
+    mLog->logMessage("video file" + mVideoFileName + "ended");
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_reinitCapture()
+{
+    cvSetCaptureProperty(mCvCapture, CV_CAP_PROP_POS_MSEC, 0.0);
+    
+    cvGrabFrame(mCvCapture);
+    mCurrentFrameIndex = 1;
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::nextFrame()
+{
+    if (mCurrentFrameIndex < mFrameCount)
+    {
+        if (mTimeSinceLastUpdate.getMilliseconds() > 30)
+            
+        {
+            mCurrentVideoFrame = cvQueryFrame(mCvCapture);
+            _updateTextureFromImage(mCurrentVideoFrame);
+            mTimeSinceLastUpdate.reset();
+            mCurrentFrameIndex++;
+        }
+    }
+    else
+    {
+        // reinit
+        _reinitCapture();
+        //_endCapture();
+        //_initCapture();
+    }
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_createTextureFromCapture(CvCapture *_capture)
+{
+
+    int w, h;
+    w = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
+    h = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
+
+    Ogre::TextureManager *TM = Ogre::TextureManager::getSingletonPtr();
+
+    // Create the texture
+    mVideoTexture = Ogre::TextureManager::getSingleton().createManual(
+        mTextureName, // name
+        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
+        Ogre::TEX_TYPE_2D,      // type
+        1024, 1024,         // width & height
+        0,                // number of mipmaps
+        Ogre::PF_BYTE_BGR,
+        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
+
+    _initTexture(mVideoTexture);
+
+    // Create a material using the texture
+    mVideoMaterial = Ogre::MaterialManager::getSingleton().create(
+        mMaterialName, // name
+        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+
+    mVideoMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mTextureName);
+    //mVideoMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
+
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_destroyTexture()
+{
+    //TODO
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_initTexture(Ogre::TexturePtr _texture)
+{
+    // Get the pixel buffer
+    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = _texture->getBuffer();
+
+    // Lock the pixel buffer and get a pixel box
+    pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
+    const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
+
+    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
+
+    for (size_t j = 0; j < _texture->getHeight(); j++)
+        for(size_t i = 0; i < _texture->getWidth() ; i++)
+        {
+
+            if (j<480-5 && i<640-5)
+            {
+                *pDest++ = 255; // B
+                *pDest++ = 0; // G
+                *pDest++ = 255; // R
+            }
+            else
+            {
+                *pDest++ = 255; // B
+                *pDest++ = 0;   // G
+                *pDest++ = 0; // R
+            }
+
+        }
+ 
+        pixelBuffer->unlock();
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_updateTextureFromImage(const IplImage *_image)
+{
+    mTimer.reset();
+    // Get the pixel buffer
+    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mVideoTexture->getBuffer();
+
+    //_copyImagePerChannel(_image, pixelBuffer);
+    //_copyImagePerLine(_image, pixelBuffer);
+    _copyImagePerPixel(_image, pixelBuffer);
+
+
+    boost::format fmt("%1% (%2%) : %3% �s");
+    
+    fmt % "write to texture" 
+        % mCurrentFrameIndex
+        % mTimer.getMicroseconds();
+    
+    mLog->logMessage(fmt.str());
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_copyImagePerLine(const IplImage *_image
+                                        ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
+{
+
+    // Lock the pixel buffer and get a pixel box
+    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
+    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
+
+    //Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data);
+    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
+
+    for (size_t i = 0 ; i < _image->height ; i++)
+    {
+    memcpy(pDest + i*1024*4
+          , (_image->imageData) +   i*_image->width * 3
+          , _image->width * 3);
+    }
+
+    _pixelBuffer->unlock();
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_copyImagePerPixel(const IplImage *_image
+                                         ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
+{
+    // Lock the pixel buffer and get a pixel box
+    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
+    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
+
+    Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data);
+    
+    size_t w, h, widthStep;
+    w = _image->width;
+    h = _image->height;
+    widthStep = _image->widthStep;
+
+    Ogre::uint32 pixelBGRA;
+    for(size_t i=0 ; i < h ; i++)
+    {
+        size_t offset = i*widthStep;
+        for (size_t j=0 ; j < w ; j++)
+        {
+            memcpy(&pixelBGRA, _image->imageData + offset +j*3, sizeof(Ogre::uint32));            
+            pDest[i *1024 + j] = pixelBGRA;            
+        }
+    }
+   
+    _pixelBuffer->unlock();
+}
+//------------------------------------------------------------------------------
+void OgreVideoTexture::_copyImagePerChannel(const IplImage *_image
+                                         ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
+{
+
+    // Lock the pixel buffer and get a pixel box
+    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
+    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
+
+    
+    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
+
+
+    for (size_t j = 0; j < _image->height; j++)
+        for(size_t i = 0; i < _image->width ; i++)
+        {
+            char pixelR = CV_IMAGE_ELEM(_image, char, j, i*3+2 );
+            char pixelG = CV_IMAGE_ELEM(_image, char, j, i*3+1);
+            char pixelB = CV_IMAGE_ELEM(_image, char, j, i*3 );
+
+            int w = mVideoTexture->getWidth();
+
+            pDest[j*1024*4 + i*4]   = pixelB;
+            pDest[j*1024*4 + i*4+1] = pixelG;
+            pDest[j*1024*4 + i*4+2] = pixelR;
+            //pDest[j*w*4 + i*4+3] = 255;
+        }
+
+    _pixelBuffer->unlock();
+}

File ogre-movingcube.sln

 Microsoft Visual Studio Solution File, Format Version 10.00
 # Visual Studio 2008
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ogre-movingcube", "ogre-movingcube\ogre-movingcube.vcproj", "{66616D12-AD9C-42C9-8685-99CD59E7BEC3}"
+	ProjectSection(ProjectDependencies) = postProject
+		{6DC85AAB-1822-4031-BCD6-7F54ECAABC37} = {6DC85AAB-1822-4031-BCD6-7F54ECAABC37}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OgreVideoCanvas", "OgreVideoCanvas\OgreVideoCanvas.vcproj", "{6DC85AAB-1822-4031-BCD6-7F54ECAABC37}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		{66616D12-AD9C-42C9-8685-99CD59E7BEC3}.Debug|Win32.Build.0 = Debug|Win32
 		{66616D12-AD9C-42C9-8685-99CD59E7BEC3}.Release|Win32.ActiveCfg = Release|Win32
 		{66616D12-AD9C-42C9-8685-99CD59E7BEC3}.Release|Win32.Build.0 = Release|Win32
+		{6DC85AAB-1822-4031-BCD6-7F54ECAABC37}.Debug|Win32.ActiveCfg = Debug|Win32
+		{6DC85AAB-1822-4031-BCD6-7F54ECAABC37}.Debug|Win32.Build.0 = Debug|Win32
+		{6DC85AAB-1822-4031-BCD6-7F54ECAABC37}.Release|Win32.ActiveCfg = Release|Win32
+		{6DC85AAB-1822-4031-BCD6-7F54ECAABC37}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

File ogre-movingcube/OgreVideoCanvas.cpp

-#include "OgreVideoCanvas.h"
-
-//------------------------------------------------------------------------------
-OgreVideoCanvas::OgreVideoCanvas(const String &_filename, SceneManager *_sceneMgr)
-    :mSceneMgr(_sceneMgr)
-    ,mVideoFileName(_filename)
-    ,mCanvas(NULL)
-    ,mVideoTexture(NULL)
-    ,mCanvasNode(NULL)
-    ,mWidth(640)
-    ,mHeight(480)
-    ,mTextureSize(1024)
-{
-}
-//------------------------------------------------------------------------------
-OgreVideoCanvas::~OgreVideoCanvas(void)
-{
-}
-//------------------------------------------------------------------------------
-void OgreVideoCanvas::buildCanvas(SceneNode *_parentNode)
-{
-    
-    float uMin = 0, vMin = 0;
-    float uMax = float(mWidth)  / mTextureSize;
-    float vMax = float(mHeight) / mTextureSize;
-
-    mCanvas = mSceneMgr->createManualObject("Video Canvas " + mVideoFileName);
-    mCanvas->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP);
-
-    mCanvas->position(-mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMin, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-    mCanvas->position( mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMax, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-    mCanvas->position(-mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMin, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-    mCanvas->position( mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMax, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-
-    mCanvas->end();
-
-    mCanvasNode = _parentNode->createChildSceneNode("Canvas Node " + mVideoFileName);
-    mCanvasNode ->attachObject(mCanvas);
-    mCanvasNode->yaw(Degree(180.0));
-    mCanvasNode->roll(Degree(180.0));
-
-    mVideoTexture = new OgreVideoTexture(mVideoFileName);
-    mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
-    
-}
-//--------------------------------------------------------------------------------
-void OgreVideoCanvas::nextFrame()
-{
-    mVideoTexture->nextFrame();
-}
-//--------------------------------------------------------------------------------

File ogre-movingcube/OgreVideoCanvas.h

-#pragma once
-
-#include <Ogre.h>
-#include "OgreVideoTexture.h"
-
-using namespace Ogre;
-
-class OgreVideoCanvas
-{
-public:
-    OgreVideoCanvas(const String&, SceneManager*);
-    ~OgreVideoCanvas(void);
-
-    void buildCanvas(SceneNode*);
-    void nextFrame();
-
-protected:
-    void _initVideoTexture(){};
-
-protected:
-    SceneManager *mSceneMgr;
-    String mVideoFileName;
-    SceneNode *mCanvasNode;
-    ManualObject *mCanvas;
-    OgreVideoTexture *mVideoTexture;
-    int mWidth, mHeight, mTextureSize;
-
-};

File ogre-movingcube/OgreVideoTexture.cpp

-#include "OgreVideoTexture.h"
-
-#include <boost/format.hpp>
-#include <cstring>
-
-//------------------------------------------------------------------------------
-OgreVideoTexture::OgreVideoTexture(const Ogre::String _filename)
-    :mVideoFileName(_filename)
-    ,mCvCapture(NULL)
-    ,mCurrentVideoFrame(NULL)
-    ,mCurrentFrameIndex(0)
-{
-    mLog = Ogre::LogManager::getSingletonPtr()->createLog("OgreVideoTexture_"+_filename+".log");
-    mMaterialName = "Video Material "+ mVideoFileName;
-    mTextureName = "Video Texture " + mVideoFileName;
-    _init();
-}
-//------------------------------------------------------------------------------
-OgreVideoTexture::~OgreVideoTexture(void)
-{
-    _endCapture();
-    _destroyTexture();
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_init()
-{
-    mLog->logMessage("init");
-    
-
-    _initCapture();
-    _createTextureFromCapture(mCvCapture);
-
-    // set first frame
-    mCurrentVideoFrame = cvQueryFrame(mCvCapture);
-    mCurrentFrameIndex++;
-
-    _updateTextureFromImage(mCurrentVideoFrame);
-
-
-    mTimeSinceLastUpdate.reset();
-
-     
-    mLog->logMessage("init done");
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_initCapture()
-{
-    Ogre::String fullName = Ogre::String("../media/videos/") + mVideoFileName;
-    mCvCapture = cvCreateFileCapture(fullName.c_str());
-    mFrameCount = cvGetCaptureProperty(mCvCapture, CV_CAP_PROP_FRAME_COUNT);
-
-    // skip first frame
-    cvGrabFrame(mCvCapture);
-    mCurrentFrameIndex++;
-
-    mLog->logMessage("openned " + fullName);
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_endCapture()
-{
-    cvReleaseCapture(&mCvCapture);
-    mCurrentFrameIndex = 0;
-    mCurrentVideoFrame = NULL;
-    mCvCapture = NULL;
-    mLog->logMessage("video file" + mVideoFileName + "ended");
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_reinitCapture()
-{
-    cvSetCaptureProperty(mCvCapture, CV_CAP_PROP_POS_MSEC, 0.0);
-    
-    cvGrabFrame(mCvCapture);
-    mCurrentFrameIndex = 1;
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::nextFrame()
-{
-    if (mCurrentFrameIndex < mFrameCount)
-    {
-        if (mTimeSinceLastUpdate.getMilliseconds() > 30)
-            
-        {
-            mCurrentVideoFrame = cvQueryFrame(mCvCapture);
-            _updateTextureFromImage(mCurrentVideoFrame);
-            mTimeSinceLastUpdate.reset();
-            mCurrentFrameIndex++;
-        }
-    }
-    else
-    {
-        // reinit
-        _reinitCapture();
-        //_endCapture();
-        //_initCapture();
-    }
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_createTextureFromCapture(CvCapture *_capture)
-{
-
-    int w, h;
-    w = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
-    h = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
-
-    Ogre::TextureManager *TM = Ogre::TextureManager::getSingletonPtr();
-
-    // Create the texture
-    mVideoTexture = Ogre::TextureManager::getSingleton().createManual(
-        mTextureName, // name
-        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
-        Ogre::TEX_TYPE_2D,      // type
-        1024, 1024,         // width & height
-        0,                // number of mipmaps
-        Ogre::PF_BYTE_BGR,
-        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
-
-    _initTexture(mVideoTexture);
-
-    // Create a material using the texture
-    mVideoMaterial = Ogre::MaterialManager::getSingleton().create(
-        mMaterialName, // name
-        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
-
-    mVideoMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mTextureName);
-    //mVideoMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
-
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_destroyTexture()
-{
-    //TODO
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_initTexture(Ogre::TexturePtr _texture)
-{
-    // Get the pixel buffer
-    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = _texture->getBuffer();
-
-    // Lock the pixel buffer and get a pixel box
-    pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD!
-    const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
-
-    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
-
-    for (size_t j = 0; j < _texture->getHeight(); j++)
-        for(size_t i = 0; i < _texture->getWidth() ; i++)
-        {
-
-            if (j<480-5 && i<640-5)
-            {
-                *pDest++ = 255; // B
-                *pDest++ = 0; // G
-                *pDest++ = 255; // R
-            }
-            else
-            {
-                *pDest++ = 255; // B
-                *pDest++ = 0;   // G
-                *pDest++ = 0; // R
-            }
-
-        }
- 
-        pixelBuffer->unlock();
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_updateTextureFromImage(const IplImage *_image)
-{
-    mTimer.reset();
-    // Get the pixel buffer
-    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mVideoTexture->getBuffer();
-
-    //_copyImagePerChannel(_image, pixelBuffer);
-    //_copyImagePerLine(_image, pixelBuffer);
-    _copyImagePerPixel(_image, pixelBuffer);
-
-
-    boost::format fmt("%1% (%2%) : %3% �s");
-    
-    fmt % "write to texture" 
-        % mCurrentFrameIndex
-        % mTimer.getMicroseconds();
-    
-    mLog->logMessage(fmt.str());
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_copyImagePerLine(const IplImage *_image
-                                        ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
-{
-
-    // Lock the pixel buffer and get a pixel box
-    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
-    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
-
-    //Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data);
-    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
-
-    for (size_t i = 0 ; i < _image->height ; i++)
-    {
-    memcpy(pDest + i*1024*4
-          , (_image->imageData) +   i*_image->width * 3
-          , _image->width * 3);
-    }
-
-    _pixelBuffer->unlock();
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_copyImagePerPixel(const IplImage *_image
-                                         ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
-{
-    // Lock the pixel buffer and get a pixel box
-    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
-    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
-
-    Ogre::uint32* pDest = static_cast<Ogre::uint32*>(pixelBox.data);
-    
-    size_t w, h, widthStep;
-    w = _image->width;
-    h = _image->height;
-    widthStep = _image->widthStep;
-
-    Ogre::uint32 pixelBGRA;
-    for(size_t i=0 ; i < h ; i++)
-    {
-        size_t offset = i*widthStep;
-        for (size_t j=0 ; j < w ; j++)
-        {
-            memcpy(&pixelBGRA, _image->imageData + offset +j*3, sizeof(Ogre::uint32));            
-            pDest[i *1024 + j] = pixelBGRA;            
-        }
-    }
-   
-    _pixelBuffer->unlock();
-}
-//------------------------------------------------------------------------------
-void OgreVideoTexture::_copyImagePerChannel(const IplImage *_image
-                                         ,Ogre::HardwarePixelBufferSharedPtr _pixelBuffer)
-{
-
-    // Lock the pixel buffer and get a pixel box
-    _pixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); // for best performance use HBL_DISCARD!
-    const Ogre::PixelBox& pixelBox = _pixelBuffer->getCurrentLock();
-
-    
-    Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
-
-
-    for (size_t j = 0; j < _image->height; j++)
-        for(size_t i = 0; i < _image->width ; i++)
-        {
-            char pixelR = CV_IMAGE_ELEM(_image, char, j, i*3+2 );
-            char pixelG = CV_IMAGE_ELEM(_image, char, j, i*3+1);
-            char pixelB = CV_IMAGE_ELEM(_image, char, j, i*3 );
-
-            int w = mVideoTexture->getWidth();
-
-            pDest[j*1024*4 + i*4]   = pixelB;
-            pDest[j*1024*4 + i*4+1] = pixelG;
-            pDest[j*1024*4 + i*4+2] = pixelR;
-            //pDest[j*w*4 + i*4+3] = 255;
-        }
-
-    _pixelBuffer->unlock();
-}

File ogre-movingcube/OgreVideoTexture.h

-#pragma once
-
-
-#include <cv.h>
-#include <highgui.h>
-
-#include <Ogre.h>
-
-
-class OgreVideoTexture
-{
-public:
-    OgreVideoTexture(const Ogre::String);
-    ~OgreVideoTexture(void);
-    Ogre::String getMaterialName() const { return mVideoMaterial->getName();};
-    void nextFrame();
-
-protected:
-    void _init();
-    void _initCapture();
-    void _reinitCapture();
-    void _endCapture();
-    void _createTextureFromCapture(CvCapture*);
-    void _initTexture(Ogre::TexturePtr);
-    void _updateTextureFromImage(const IplImage*);
-    void _destroyTexture();
-
-   
-    inline void _copyImagePerLine(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
-    inline void _copyImagePerPixel(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
-    inline void _copyImagePerChannel(const IplImage*, Ogre::HardwarePixelBufferSharedPtr);
-
-protected:
-    Ogre::String mVideoFileName;
-    CvCapture *mCvCapture;
-    IplImage *mCurrentVideoFrame;
-    Ogre::TexturePtr mVideoTexture;
-    Ogre::MaterialPtr mVideoMaterial;
-    Ogre::String mTextureName, mMaterialName;
-    Ogre::Timer mTimeSinceLastUpdate;
-    int mFrameCount, mCurrentFrameIndex;
-    Ogre::Log *mLog;
-    Ogre::Timer mTimer;
-};

File ogre-movingcube/ogre-movingcube.vcproj

 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(BOOST_HOME)\&quot;;&quot;$(OGRE16_HOME)\OgreMain\include&quot;;&quot;$(OGRE16_HOME)\Dependencies\include&quot;;&quot;$(OGRE16_HOME)\Samples\Common\include&quot;;&quot;C:\libs\OpenCV-1.1\cvaux\include&quot;;&quot;C:\libs\OpenCV-1.1\cv\include&quot;;&quot;C:\libs\OpenCV-1.1\cxcore\include&quot;;&quot;C:\libs\OpenCV-1.1\otherlibs\highgui&quot;"
+				AdditionalIncludeDirectories="..\OgreVideoCanvas\include;&quot;$(BOOST_HOME)\&quot;;&quot;$(OGRE16_HOME)\OgreMain\include&quot;;&quot;$(OGRE16_HOME)\Dependencies\include&quot;;&quot;$(OGRE16_HOME)\Samples\Common\include&quot;;&quot;C:\libs\OpenCV-1.1\cvaux\include&quot;;&quot;C:\libs\OpenCV-1.1\cv\include&quot;;&quot;C:\libs\OpenCV-1.1\cxcore\include&quot;;&quot;C:\libs\OpenCV-1.1\otherlibs\highgui&quot;"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OgreMain_d.lib OIS_d.lib OgreGUIRenderer_d.lib cvd.lib cvauxd.lib cxcored.lib highguid.lib"
+				AdditionalDependencies="OgreMain_d.lib OIS_d.lib OgreGUIRenderer_d.lib cvd.lib cvauxd.lib cxcored.lib highguid.lib OgreVideoCanvas_d.lib"
 				LinkIncremental="2"
-				AdditionalLibraryDirectories="&quot;$(OGRE16_HOME)\lib&quot;;&quot;$(OGRE16_HOME)\Dependencies\lib\Debug&quot;;&quot;C:\libs\OpenCV-1.1\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE16_HOME)\lib&quot;;&quot;$(OGRE16_HOME)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;C:\libs\OpenCV-1.1\lib&quot;;..\OgreVideoCanvas\lib"
 				GenerateDebugInformation="true"
 				SubSystem="2"
 				TargetMachine="1"
 				Name="VCCLCompilerTool"
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
-				AdditionalIncludeDirectories="&quot;$(BOOST_HOME)\&quot;;&quot;$(OGRE16_HOME)\OgreMain\include&quot;;&quot;$(OGRE16_HOME)\Dependencies\include&quot;;&quot;$(OGRE16_HOME)\Samples\Common\include&quot;;&quot;C:\libs\OpenCV-1.1\cvaux\include&quot;;&quot;C:\libs\OpenCV-1.1\cv\include&quot;;&quot;C:\libs\OpenCV-1.1\cxcore\include&quot;;&quot;C:\libs\OpenCV-1.1\otherlibs\highgui&quot;"
+				AdditionalIncludeDirectories="..\OgreVideoCanvas\include;&quot;$(BOOST_HOME)\&quot;;&quot;$(OGRE16_HOME)\OgreMain\include&quot;;&quot;$(OGRE16_HOME)\Dependencies\include&quot;;&quot;$(OGRE16_HOME)\Samples\Common\include&quot;;&quot;C:\libs\OpenCV-1.1\cvaux\include&quot;;&quot;C:\libs\OpenCV-1.1\cv\include&quot;;&quot;C:\libs\OpenCV-1.1\cxcore\include&quot;;&quot;C:\libs\OpenCV-1.1\otherlibs\highgui&quot;"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OgreMain.lib OIS.lib OgreGUIRenderer.lib cv.lib cvaux.lib cxcore.lib highgui.lib"
+				AdditionalDependencies="OgreMain.lib OIS.lib OgreGUIRenderer.lib cv.lib cvaux.lib cxcore.lib highgui.lib OgreVideoCanvas.lib"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="&quot;$(OGRE16_HOME)\lib&quot;;&quot;$(OGRE16_HOME)\Dependencies\lib\Release&quot;;&quot;C:\libs\OpenCV-1.1\lib&quot;"
+				AdditionalLibraryDirectories="&quot;$(OGRE16_HOME)\lib&quot;;&quot;$(OGRE16_HOME)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;C:\libs\OpenCV-1.1\lib&quot;;..\OgreVideoCanvas\lib"
 				GenerateDebugInformation="true"
 				SubSystem="2"
 				OptimizeReferences="2"
 				RelativePath=".\ogre-movingcube.cpp"
 				>
 			</File>
-			<File
-				RelativePath=".\OgreVideoCanvas.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\OgreVideoTexture.cpp"
-				>
-			</File>
-			<Filter
-				Name="OgreDShow"
-				>
-				<File
-					RelativePath=".\OgreDShow\UtilsOgreDshow.cpp"
-					>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-				</File>
-			</Filter>
 		</Filter>
 		<Filter
 			Name="Header Files"
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
-			<File
-				RelativePath=".\OgreVideoCanvas.h"
-				>
-			</File>
-			<File
-				RelativePath=".\OgreVideoTexture.h"
-				>
-			</File>
-			<Filter
-				Name="OgreDShow"
-				>
-				<File
-					RelativePath=".\OgreDShow\UtilsOgreDshow.h"
-					>
-				</File>
-				<File
-					RelativePath=".\OgreDShow\UtilsOgreDshow_private.h"
-					>
-				</File>
-			</Filter>
 		</Filter>
 		<Filter
 			Name="Resource Files"