Playing movie in texture

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Guest

Post by Guest »

I think this should be moved to the FAQ folder.
Despite the current Windows only limitation it's good stuff.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i will.

thanks
hybrid

Post by hybrid »

Emil_halim wrote:if someone here consider himself a Linux guru, and know how the movie in linux can be played as a stream , so he could implement the movie player easly.

that is all, so it will be very easy if we could get a frame by frame in linux. is there a library
could make that in linux ?
There might be a lot of libraries to do as such, but avifile could be most prominent. So here are the main parts of my implementation. There are still some parts to work on, but documentation is virtually not available. I build this prototype from some ancient code I found when googling for some avifile commands. Complete code can be downloaded here
http://parsys.informatik.uni-oldenburg. ... exture.cpp including the examplary main function from Emil_halim.

Code: Select all

class TMovie
{
        avm::IReadFile* MediaFile;
        avm::IReadStream*       MediaStream;
        avm::StreamInfo*        MediaStreamInfo;
        avm::CImage*    pSurface;
        ITimer*         timer;
        double          timePerFrame;
        u32             oldtime;

     public:
        TMovie(ITimer* timer):MediaFile(NULL),MediaStream(NULL),timer(timer),timePerFrame(40),oldtime(0) {}

        ~TMovie()
        {
                delete MediaStream;
                delete MediaFile;
        }

        void LoadMovie(char* filename)
        {
                MediaFile=avm::CreateReadFile(filename);
                MediaStream=MediaFile->GetStream(0,avm::IReadStream::Video);
                MediaStream->SetDirection(true);
                MediaStream->StartStreaming();
                MediaStream->Seek(1);
                pSurface=MediaStream->GetFrame(true);
                MediaStreamInfo=MediaStream->GetStreamInfo();
        }

        bool NextMovieFrame()
        {
                if(timer->getTime()-oldtime < timePerFrame)
                {
                        return false;
                }
                oldtime = timer->getTime();
                pSurface=MediaStream->GetFrame(true);
                return true;
        }

        u32 getMovieWidth() { return (MediaStreamInfo->GetVideoWidth());}

       u32 getMovieHeight() { return (MediaStreamInfo->GetVideoHeight());}

           void DrawMovie(int x,int y,ITexture* texture)
           {
                u32 pitch = texture->getPitch();
                u8* pTex = (u8*)texture->lock()+(y*pitch);
                CImage *image;
                u8 bpp;

                // Create image of correct depth from movie frame
                if (texture->getColorFormat()==ECF_A1R5G5B5)
                {
                        image = new avm::CImage(pSurface, 15);
                        bpp=2;
                }
                else
                {
                        image = new avm::CImage(pSurface, 32);
                        bpp=4;
                }

                uint8_t* pPixel=image->At(0,0);
                // Check for area to be drawn. Avoid access out of bound.
                u32 minWidth=(pitch<image->Bpl())?pitch:image->Bpl();
                u32 minHeight=(image->Height()<texture->getSize().Height)?image->Height():texture->getSize().Height;

                // copy movie frame to texture
                for(int h=0; h<minHeight; ++h)
                {
                        memcpy(pTex+x*bpp,pPixel,minWidth);
                        // jump to next scanline
                        pTex+=pitch;
                        pPixel+=image->Bpl();
                }

                delete image;
                texture->unlock();
          }
};
There is a very inefficient double copy in this code. One creating a new Image with correct depth, and one copies to the texture buffer.
Additionally memory freeing might be problematic, and loading the correct frame are to be checked.
Please note that I had some problems with linking to libaviplay from some Linux distros. Thus, I downloaded the latest version from SourceForge, which is working yet.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

hybrid:

it is really good work,so thank you for your efforts.

i have a suggestion for you .

instead of creating an other Image for correcting movie dipth, we can create a texture
that hold the movie with the same color depth of the movie.this will save some times.so what do you think?

sorry i have no linux to check out the code.
hybrid

Post by hybrid »

avifile offers a large variety of output formats from which most are natively supported by the decoders. Thus it should be efficiently possible as soon as I find a dscription of hw to set properties of the decoders.
But I'm still thinking of a nice architecture which includes the Texture Animation Scene Node and this video texture implementation. And based on that it migh be the case that the texture already exists. Anyway, in its curren state its merely a poof of concept. But it's really nice to add such special FX to a scene 8)
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i am thinking the same,so i have an idea.

i will keep the TMovie class as it is,suppos the user create a cube or an shape and has
it's own texture,then he can draw the movie in any texture he wants.

and creating VideoTexture class that drived from TMovie & ISceneNode. and
ofcaurse we must implement intreface class,so it could be like this.

class IMovie : public IUnkbown
{
interface stuff function

}

class VideoTextureLinux :public ISceneNode :public Tmovie :public IMovie
{
........
Linux stuff
........

}

class VideoTextureWin32 :public ISceneNode :public Tmovie :public IMovie
{
........
Win32 stuff
........

}
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

hybrid: what do you think about this

Code: Select all




#include <dshow.h>
#include <mmstream.h>
#include <amstream.h> 
#include <ddstream.h>


static GUID MY_CLSID_AMMultiMediaStream={0x49C47CE5,0x9BA4,0x11D0,0x82,0x12,0x00,0xC0,0x4F,0xC3,0x2C,0x45};
static GUID MY_IID_IAMMultiMediaStream={0xBEBE595C,0x9A6F,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_MSPID_PrimaryVideo={0xA35FF56A,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_IID_IDirectDrawMediaStream={0xF4104FCE,0x9A70,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D};  
static GUID MY_MSPID_PrimaryAudio={0xA35FF56B,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D};


class TMovie 
 {
         IAMMultiMediaStream*     pAMStream;
         IMediaStream*            pPrimaryVidStream;
         IDirectDrawMediaStream*  pDDStream;
         IDirectDrawStreamSample* pSample;
         IDirectDrawSurface*      pSurface;
         RECT                     Movie_rect;
         LONG                     MoviePitch;
         void*                    MovieBuffer;
         DWORD                    time;
         DWORD                    oldtick;
         BOOL                     flg; 
     
     public:    
           TMovie()
            {
               CoInitialize(0);
               pAMStream         = 0;
               pPrimaryVidStream = 0;  
               pDDStream         = 0;    
               pSample           = 0;
               pSurface          = 0;
               time              = 0;
            }
                
           ~TMovie()
            {
                pPrimaryVidStream->Release();
                pDDStream->Release();
                pSample->Release();
                pSurface->Release();
                pAMStream->Release();
                CoUninitialize();
            }
            
           virtual void LoadMovie(char* filename)
            {
                WCHAR buf[512];
                MultiByteToWideChar(CP_ACP,0,filename,-1,buf,512); 
                CoCreateInstance(MY_CLSID_AMMultiMediaStream,0,1,MY_IID_IAMMultiMediaStream,(void**)&pAMStream);
                pAMStream->Initialize((STREAM_TYPE) 0, 0, NULL);
                pAMStream->AddMediaStream( 0, &MY_MSPID_PrimaryVideo, 0, NULL); 
               // pAMStream->AddMediaStream( 0, &MY_MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL); 
                pAMStream->OpenFile(buf,4); //AMMSF_RENDERTOEXISTING); // 
                pAMStream->GetMediaStream( MY_MSPID_PrimaryVideo, &pPrimaryVidStream);
                pPrimaryVidStream->QueryInterface(MY_IID_IDirectDrawMediaStream,(void**)&pDDStream);
                pDDStream->CreateSample(0,0,0,&pSample);
                pSample->GetSurface(&pSurface,&Movie_rect);
                pAMStream->SetState((STREAM_STATE)1);
            }
           
           void NextMovieFrame()
            {
               if(GetTickCount()-oldtick < time){flg = false ;return;}
               oldtick = GetTickCount(); 
               flg = true;
               pSample->Update( 0, NULL, NULL, 0);
            }
            
           int MovieWidth() { return (Movie_rect.right - Movie_rect.left);}
           
           int MovieHeight() { return (Movie_rect.bottom - Movie_rect.top);}  
           
           void DrawMovie(int x,int y,ITexture* Buf)
            {   
                void* pBits = Buf->lock();
                LONG  Pitch = Buf->getPitch();  
                DDSURFACEDESC  ddsd; 
                ddsd.dwSize=sizeof(DDSURFACEDESC);
                pSurface->Lock( NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT , NULL); 
                int wmin=(Pitch<ddsd.lPitch)?Pitch:ddsd.lPitch;
                for(int h=0; h<ddsd.dwHeight; h++) 
                     memcpy((BYTE*)pBits+((y+h)*Pitch)+x*4,(BYTE*)ddsd.lpSurface+h*ddsd.lPitch,wmin);
                pSurface->Unlock(NULL);
                Buf->unlock();
           }  
            
          void SetMovieFPS(int fps)
           {
                time = 1000.0/fps;
           }
          
          void Stop()
           {
              pAMStream->SetState(STREAMSTATE_STOP);      
           }
          
          void Run()
           {
               pAMStream->SetState(STREAMSTATE_RUN);
           }
                
          void MovieLock()
           {
                DDSURFACEDESC  ddsd;
                ddsd.dwSize=sizeof(DDSURFACEDESC);
                pSurface->Lock( NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
                MoviePitch  = ddsd.lPitch; 
                MovieBuffer = ddsd.lpSurface;
           }  
            
          void MovieUnlock() 
           {  
                pSurface->Unlock( NULL);
           }             
            
          void Gray(int x1,int y1,int x2,int y2) 
           {
               if(!flg) return;
               DWORD  clr;
               LPBYTE buff;
               for (int h=y1; h<y2; h++)    
                   for (int w=x1; w<x2; w++)
                    { 
                       buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch; 
                       clr = (buff[0] + buff[1] + buff[2]) /3;
                       *(DWORD*)buff = RGB((BYTE)clr,(BYTE)clr,(BYTE)clr);
                    }   
           }
                
          void Negative(int x1,int y1,int x2,int y2)
           {
               if(!flg) return;
               DWORD  clr;
               LPBYTE buff;
               for (int h=y1; h<y2; h++)    
                   for (int w=x1; w<x2; w++)
                    { 
                       buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch;  
                       *(DWORD*)buff = RGB((BYTE)255-buff[0],(BYTE)255-buff[1],(BYTE)255-buff[2]);
                    }   
           }  
           
          void Intensity(float intnsty,int x1,int y1,int x2,int y2)
           {
               if(!flg) return;
               DWORD  clr;
               LPBYTE buff;
               for (int h=y1; h<y2; h++)    
                   for (int w=x1; w<x2; w++)
                    { 
                       buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch;  
                       *(DWORD*)buff = RGB((BYTE)buff[0]/intnsty,(BYTE)buff[1]/intnsty,(BYTE)buff[2]/intnsty);
                    }
           }          
 };   
 

class VideoTextureWin32 : public ISceneNode , public TMovie
 {
     aabbox3d<f32> Box;
     S3DVertex Vertices[4];
     SMaterial Material;
     
     
     public: 
       VideoTextureWin32(ISceneNode* parent, ISceneManager* mgr, s32 id): ISceneNode(parent, mgr, id) , TMovie()
        {  
            Material.Wireframe = false;
            Material.Lighting = false; 
        }
      
      virtual void LoadMovie(char* filename)
        {
           TMovie::LoadMovie(filename);
           float u = (float)MovieWidth()/512.0;
           float v = (float)MovieHeight()/512.0;
           Vertices[0] = S3DVertex(-10,-10,0, 0,0,0,SColor(255,255,255,255),0,v);
           Vertices[1] = S3DVertex( 10,-10,0, 0,0,0,SColor(255,255,255,255),u,v); 
           Vertices[2] = S3DVertex( 10, 10,0, 0,0,0,SColor(255,255,255,255),u,0);
           Vertices[3] = S3DVertex(-10, 10,0, 0,0,0,SColor(255,255,255,255),0,0);
            
           Box.reset(Vertices[0].Pos);
           for (s32 i=1; i<4; ++i)  Box.addInternalPoint(Vertices[i].Pos);
           
           IVideoDriver* driver = SceneManager->getVideoDriver(); 
           driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT , TRUE);
           driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, FALSE);
           Material.Texture1 = driver->addTexture(dimension2d<s32>(512,512),"imovie");
        }
         
      virtual void OnPreRender()
       { 
           if (IsVisible)    SceneManager->registerNodeForRendering(this);
           ISceneNode::OnPreRender();
       }
       
      virtual void render()
       {   
           DrawMovie(0,0,Material.Texture1);
           u16 indices[] = { 0,1,3, 3,1,2, 1,0,2, 2,0,3 };
           IVideoDriver* driver = SceneManager->getVideoDriver();
           driver->setMaterial(Material);
           driver->setTransform(ETS_WORLD, AbsoluteTransformation);
           driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
       }
 
      virtual const aabbox3d<f32>& getBoundingBox() const 
       { 
           return Box; 
       }
  
      virtual s32 getMaterialCount()
       {
           return 1;
       }
  
      virtual SMaterial& getMaterial(s32 i)
       {
           return Material;
       } 
     
 };         
Note: not tested yet.
Guest

Post by Guest »

Emil_halim what compiler are you using to compile this code?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i am using Dev-C++ for all my work.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i am using Dev-C++ for all my work.

you could see this for a full class and working demo
http://www.irrforge.org/index.php/Playi ... in_texture
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi all,

First I have a tutorial addition for using DirectShow with DevCpp. Secondly a question.


1.Tutorial
To resolve a couple of compiler errors you need to make the following changes:

In strmif.h (located in ../DXSDK/Include), you get the following error: typedef VMRGUID error.
Change the code to this (add scope operator :: )

Code: Select all

typedef struct tagVMRGUID
    {
    ::GUID *pGUID;
    ::GUID GUID;
    }   VMRGUID;
Also in strmif.h there is an error about EXTERN_GUID definition. To resolve, add EXTERN_GUID definition just before first EXTERN_GUID():

Code: Select all

#ifndef EXTERN_GUID
#define EXTERN_GUID(g,l1,s1,s2,c1,c2,c3,c4,c5,c6,c7,c8) DEFINE_GUID(g,l1,s1,s2,c1,c2,c3,c4,c5,c6,c7,c8)
#endif
You also need to have the Microsft DirectX-SDK installed + the latest update (currently August 2005)
Get it here: http://www.microsoft.com/downloads/sear ... tegoryid=2
It is probably a good idea to download the DevC DirectX update (Menu: help / about / check for updates)
I am not sure if it nescessary, since I already had it installed.


Then you have to add the following files/paths in project options:
../../DevCPP/lib/libole32.a (or wherever you installed DevCpp)
C:\Program Files\DXSDK\Lib (or wherever you installed Microsft DX SDK)
C:\Program Files\DXSDK\Include (or wherever you installed Microsft DX SDK)


I didn't invent these thing myself. For more infomation see the following links:
http://home.clara.net/raoulgough/vidmodem/dshow.html
http://step.polymtl.ca/~guardia/programming.php
http://www.gamedev.net/reference/articl ... le2067.asp
http://www.gamedev.net/reference/articl ... le1345.asp




2. Question
I copied the code in the tutorial of emil_halim from the wiki.
You can find it in this thread or here: http://www.irrforge.org/index.php/Playi ... in_texture

Then I:
- Removed the code for demo 1
- Added the irrlicht header/namespace declarations
- corrected the inconsistent use of variable irrDevice
- Added the path+name of an .mpg file

The code compiles and loads fine. Except that only the first frame of the movie is shown, no further images. Also the colors are off.
I have checked that the mpeg file is ok. It plays in mediaplayer and in the direct show sample players.
I am using Win-XP, DevC 4.9.9.2, DX 9.0c + august update.

Anybody an idea what the problem could be ?
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

So. Anybody got the demo working at all :?:
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

Hi evo

there is thing you must check it.

NextMovieFrame function that updates our movie,does it actually update
our movie correctly, check the return value of pSample->Update function.
and make sure that you set the FPS of the movie.

if this does not help you , you could post some code to see the problem.
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi emil,

I have tried out your suggestions. The FPS rate is being set (variable 'time'). Return value from pSample->Update function is always False.

This is the code I use. It is basically the same as in the wiki. Just the demo 1 code removed and the name of movie file and texture file changed.

Do you agree with the changes in 'strmif.h' file ?

Your help is very much appreciated.

Code: Select all

#include <dshow.h> 
#include <mmstream.h> 
#include <amstream.h> 
#include <ddstream.h> 

#include "irrlicht.h" 
// Irrlicht Namespaces 
using namespace irr; 
using namespace core; 
using namespace scene; 
using namespace video; 
using namespace io; 
using namespace gui; 

static GUID MY_CLSID_AMMultiMediaStream   = {0x49C47CE5,0x9BA4,0x11D0,0x82,0x12,0x00,0xC0,0x4F,0xC3,0x2C,0x45};
static GUID MY_IID_IAMMultiMediaStream    = {0xBEBE595C,0x9A6F,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_MSPID_PrimaryVideo         = {0xA35FF56A,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_IID_IDirectDrawMediaStream = {0xF4104FCE,0x9A70,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_MSPID_PrimaryAudio         = {0xA35FF56B,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D}; 

class TMovie 
{
        IAMMultiMediaStream*     pAMStream;
        IMediaStream*            pPrimaryVidStream;
        IDirectDrawMediaStream*  pDDStream;
        IDirectDrawStreamSample* pSample;
        IDirectDrawSurface*      pSurface;
        RECT                     Movie_rect;
        LONG                     MoviePitch;
        void*                    MovieBuffer;
        DWORD                    time;
        DWORD                    oldtick;
        BOOL                     flg; 
    
    public:    
          TMovie()
           {
              CoInitialize(0);
              pAMStream         = 0;
              pPrimaryVidStream = 0;  
              pDDStream         = 0;    
              pSample           = 0;
              pSurface          = 0;
              time              = 0;
           }
               
          ~TMovie()
           {
               pPrimaryVidStream->Release();
               pDDStream->Release();
               pSample->Release();
               pSurface->Release();
               pAMStream->Release();
               CoUninitialize();
           }
           
          virtual void LoadMovie(char* filename)
           {
               WCHAR buf[512];
               MultiByteToWideChar(CP_ACP,0,filename,-1,buf,512); 
               CoCreateInstance(MY_CLSID_AMMultiMediaStream,0,1,MY_IID_IAMMultiMediaStream,(void**)&pAMStream);
               pAMStream->Initialize((STREAM_TYPE) 0, 0, NULL);
               pAMStream->AddMediaStream( 0, &MY_MSPID_PrimaryVideo, 0, NULL);  
               pAMStream->OpenFile(buf,4); 
               pAMStream->GetMediaStream( MY_MSPID_PrimaryVideo, &pPrimaryVidStream);
               pPrimaryVidStream->QueryInterface(MY_IID_IDirectDrawMediaStream,(void**)&pDDStream);
               pDDStream->CreateSample(0,0,0,&pSample);
               pSample->GetSurface(&pSurface,&Movie_rect);
               pAMStream->SetState((STREAM_STATE)1);
           }
          
          void NextMovieFrame()
           {
              if(GetTickCount()-oldtick < time){flg = false ;return;}
              oldtick = GetTickCount(); 
              flg = true;
              bool test = pSample->Update( 0, NULL, NULL, 0);
              printf("Time=%d Return=%s\n", time, (test ? "True" : "False" ));		// Added by Evo
           }
           
          int MovieWidth() { return (Movie_rect.right - Movie_rect.left);}
          
          int MovieHeight() { return (Movie_rect.bottom - Movie_rect.top);}  
          
          void DrawMovie(int x,int y,ITexture* Buf)
           {   
               void* pBits = Buf->lock();
               LONG  Pitch = Buf->getPitch();  
               DDSURFACEDESC  ddsd; 
               ddsd.dwSize=sizeof(DDSURFACEDESC);
               pSurface->Lock( NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT , NULL); 
               int wmin=(Pitch<ddsd.lPitch)?Pitch:ddsd.lPitch;
               for(int h=0; h<ddsd.dwHeight; h++) 
                    memcpy((BYTE*)pBits+((y+h)*Pitch)+x*4,(BYTE*)ddsd.lpSurface+h*ddsd.lPitch,wmin);
               pSurface->Unlock(NULL);
               Buf->unlock();
          }  
           
         void SetMovieFPS(int fps)
          {
               time = (DWORD)(1000.0/fps);
          }
         
         void Stop()
          {
             pAMStream->SetState(STREAMSTATE_STOP);      
          }
         
         void Run()
          {
              pAMStream->SetState(STREAMSTATE_RUN);
          }
               
         void MovieLock()
          {
               DDSURFACEDESC  ddsd;
               ddsd.dwSize=sizeof(DDSURFACEDESC);
               pSurface->Lock( NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
               MoviePitch  = ddsd.lPitch; 
               MovieBuffer = ddsd.lpSurface;
          }  
           
         void MovieUnlock() 
          {  
               pSurface->Unlock( NULL);
          }             
           
         void Gray(int x1,int y1,int x2,int y2) 
          {
              if(!flg) return;
              DWORD  clr;
              LPBYTE buff;
              for (int h=y1; h<y2; h++)    
                  for (int w=x1; w<x2; w++)
                   { 
                      buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch; 
                      clr = (buff[0] + buff[1] + buff[2]) /3;
                      *(DWORD*)buff = RGB((BYTE)clr,(BYTE)clr,(BYTE)clr);
                   }   
          }
               
         void Negative(int x1,int y1,int x2,int y2)
          {
              if(!flg) return;
              DWORD  clr;
              LPBYTE buff;
              for (int h=y1; h<y2; h++)    
                  for (int w=x1; w<x2; w++)
                   { 
                      buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch;  
                      *(DWORD*)buff = RGB((BYTE)255-buff[0],(BYTE)255-buff[1],(BYTE)255-buff[2]);
                   }   
          }  
          
         void Intensity(float intnsty,int x1,int y1,int x2,int y2)
          {
              if(!flg) return;
              DWORD  clr;
              LPBYTE buff;
              for (int h=y1; h<y2; h++)    
                  for (int w=x1; w<x2; w++)
                   { 
                      buff = (LPBYTE)MovieBuffer + w*4 + h*MoviePitch;  
                      *(DWORD*)buff = RGB((BYTE)buff[0]/intnsty,(BYTE)buff[1]/intnsty,(BYTE)buff[2]/intnsty);
                   }
          }          
};   
//--------------------------------------------------------------------------------

class CSampleSceneNode : public ISceneNode 
{ 
      aabbox3d<f32> Box;
      S3DVertex Vertices[4];
      SMaterial Material;
      
   public: 
      CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id): ISceneNode(parent, mgr, id)
       {  
           float u = 320.0/512.0;
           float v = 240.0/512.0;
           Material.Wireframe = false;
           Material.Lighting = false;
           Vertices[0] = S3DVertex(-10,-10,0, 0,0,0,SColor(255,0,0,255),0,v);
           Vertices[1] = S3DVertex( 10,-10,0, 0,0,0,SColor(255,0,255,0),u,v); 
           Vertices[2] = S3DVertex( 10, 10,0, 0,0,0,SColor(255,255,0,0),u,0);
           Vertices[3] = S3DVertex(-10, 10,0, 0,0,0,SColor(255,255,255,255),0,0);
           
           Box.reset(Vertices[0].Pos);
           for (s32 i=1; i<4; ++i)  Box.addInternalPoint(Vertices[i].Pos);
       }
     
     virtual void OnPreRender()
      { 
          if (IsVisible)    SceneManager->registerNodeForRendering(this);
          ISceneNode::OnPreRender();
      }
      
     virtual void render()
      {  
          u16 indices[] = { 0,1,3, 3,1,2, 1,0,2, 2,0,3 };
          IVideoDriver* driver = SceneManager->getVideoDriver();
          driver->setMaterial(Material);
          driver->setTransform(ETS_WORLD, AbsoluteTransformation);
          driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
      }

     virtual const aabbox3d<f32>& getBoundingBox() const 
      { 
          return Box; 
      }
 
     virtual s32 getMaterialCount()
      {
          return 1;
      }
 
     virtual SMaterial& getMaterial(s32 i)
      {
          return Material;
      } 
};

//--------------------------------------------------------------------------------
int main() 
{ 
   IrrlichtDevice* irrDevice   = createDevice(EDT_OPENGL,dimension2d<s32>(640,480),32,false,false,false,0);
   IVideoDriver*   irrVideo    = irrDevice->getVideoDriver();
   ISceneManager*  irrSceneMgr = irrDevice->getSceneManager();
   TMovie* movie = new TMovie;
   movie->LoadMovie("HPIM0236.MPG");
   movie->SetMovieFPS(25);
   irrVideo->setTextureCreationFlag(ETCF_ALWAYS_32_BIT , TRUE);
   irrVideo->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, FALSE);
   ITexture* movTxtr = irrVideo->addTexture(dimension2d<s32>(320,240),"grid.jpg"); 
   irrSceneMgr->addCameraSceneNode(0, vector3df(0,0,-20), vector3df(0,0,0));
   CSampleSceneNode* myNode = new CSampleSceneNode(irrSceneMgr->getRootSceneNode(), irrSceneMgr, 666);
   myNode->setMaterialTexture( 0, movTxtr);
   myNode->drop();
//   ISceneNodeAnimator* anim = irrSceneMgr->createRotationAnimator(vector3df(0,0.1f,0));
//   myNode->addAnimator(anim);
//   anim->drop(); 

   while(irrDevice->run())
	{
		irrVideo->beginScene(true, true, SColor(0,200,200,200));
		movie->NextMovieFrame();
		movie->DrawMovie(0,0,movTxtr);
		irrSceneMgr->drawAll();
		irrVideo->endScene();
	}
	irrDevice->drop();
	return 0;
}
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i have no idea what could be the problem,but i have one comment on your
code

Code: Select all

   this code

 ITexture* movTxtr = irrVideo->addTexture(dimension2d<s32>(320,240),"grid.jpg"); 

 must be just like this

  ITexture* movTxtr = irrVideo->addTexture(dimension2d<s32>(512,512),"grid.jpg");
 
this will display all the rectangle of movie .
Post Reply