Game Development Community

[Solved]Layering a video file.

by Vlad I · in Torque Game Builder · 09/03/2012 (8:08 am) · 11 replies

Ok, I got some progress on playing video files in my game, in my level, NOT between levels as intro.
I also made it possible to change it's size and position.
I used attachGui for this.

But now I'm stuck with a layer problem.
I want to have some objects displayed above my video.

Here is the code (I started a fresh clean project)
This is my ogg.cs:
function ogg::onLevelLoaded(%this, %scenegraph)
{
	%this.enableUpdateCallback();
	%guiContent = new GuiTheoraCtrl(MyVideo) {
          profile = "GuiDefaultProfile";    
          horizSizing = "right";    
          vertSizing = "bottom";    
          position = "0 0";    
          extent = "400 400";    
          minExtent = "8 2";    
          visible = "1";    
          done = "0";    
          stopOnSleep = "1";    
          backgroundColor = "0 0 0 255";    
       };    
		//Canvas.addGuiControl(MyVideo);
 
 //Canvas.PushDialog(MyVideo, 1);   
 Test.attachGui(MyVideo, sceneWindow2D); 

//MyVideo.PushToBack(sceneWindow2d,9);
  
   MyVideo.setFile("game/data/video/4.ogv");
}
In TGB I created a static sprite and named it Test. Now the video plays above that sprite: I could change the position and size, which is good. But how do I change it's layer?
Changing the layer of the sprite it's attached to doesn't affect it.

How do I PushToBack or PushToFront?
Any thoughts?

P.S what's with the quots?

#1
09/03/2012 (12:24 pm)
I'm getting closer.
I made the animation play beneath all my objects, by adding a new t2dSceneWindow. But how do I make my background image beneath all of it e.g beneath the video and my other objects.

Here is the code:
in my mainScreen.gui I have this
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(mainScreenGui) {
   canSaveDynamicFields = "0";
   Profile = "GuiBlackContentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 8";
   canSave = "1";
   Visible = "1";
   useVariable = "0";

   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
 
  new t2dSceneWindow(TestGui) {
      canSaveDynamicFields = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "1";
   };
};
//--- OBJECT WRITE END ---

in my ogg.cs I have this
function ogg::onMouseDown(%this, %scenegraph)
{
	%this.enableUpdateCallback();
	%guiContent = new GuiTheoraCtrl(MyVideo) {
          profile = "GuiDefaultProfile";    
          horizSizing = "right";    
          vertSizing = "bottom";    
          position = "0 0";    
          extent = "400 400";    
          minExtent = "8 2";    
          visible = "1";    
          done = "0";    
          stopOnSleep = "1";    
          backgroundColor = "0 0 0 255";    
       };    
		//Canvas.addGuiControl(MyVideo);
 
 Canvas.PushDialog(sceneWindow2D, 2);   
 Test.attachGui(MyVideo, TestGui); 

//MyVideo.PushToBack(sceneWindow2d,9);
  
   MyVideo.setFile("game/data/video/4.ogv");
}
//ogg.attachGui(MyVideo, SceneWindow2D);

and iin my game.cs I did this
function startGame(%level)
{
exec("./ogg.cs");
   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);
   

   new ActionMap(moveMap);   
   moveMap.push();
   
   $enableDirectInput = true;
   activateDirectInput();
   enableJoystick();
   
   sceneWindow2D.loadLevel(%level);
   TestGui.loadLevel(%level);
}
At this moment the video looks like it is pushed beneath the objects t2dSceneWindow.
So, all what is needed now is to have my background beneath it all.
How do I do that?
#2
09/04/2012 (4:32 am)
Ok, getting really close now :)
I made my background appear beneath all my objects and my video.
So the current order of layers is :
1. Some sprites objects.
2. Video.
3. Background image.

However I noticed that after I stop my video using MyVideo.stop();
video leaves black space on the Background image which is beneath the video. At the moment it is a big black square the size of the video window.

How to fight this kind of thing?

Any help at all?
Thanks
#3
09/04/2012 (10:08 am)
Now anybody can get rid of that annoying background rectangle:
In guiTheoraCtrl.h-
/// Our background color.
ColorI mBackgroundColor;
bool mShowBackground;      //<- Add this line after the bg variable
In guiTheoraCtrl.cc-
mBackgroundColor.set(0,0,0);
mShowBackground = true;  //<= Add this line after the bg color set in the constructor function
}
Two functions down-
addField("backgroundColor", TypeColorI,Offset(mBackgroundColor,   GuiTheoraCtrl));
addField("showBackground", TypeBool,Offset(mShowBackground,   GuiTheoraCtrl)); //<- Add this line in the addfield area
In the "onRender" function-
//Add this if statement.
if(mShowBackground)
{
	dglDrawRectFill(rect, mBackgroundColor); // black rect
}
There, now when you create your new control you can have the variable showBackground equal to false and no more rectangle.

BTW
For you vlad there SHOULD be an else keyword before the new if statement. Everybody else (excluding me also) shouldn't have an else keyword. Also something that only affects you vlad-
mFilenameLoop = szFilename;
mTheoraTexture.setFile(szFilename,true); //<- change 2nd parameter to true

#4
09/04/2012 (10:44 am)
Just one thing, what is :
In the "onRender" function-

The forum seems to be messing up letters.
#5
09/04/2012 (11:56 am)
The onRender function titled-

void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect)
{
#6
09/04/2012 (12:48 pm)
Thanks Alpha !
This is great stuff!

Regarding me this is already set to true unless I'm missing smth
void GuiTheoraCtrl::setFile(const char* szFilename,const bool loop)
{
mLoop = loop;
mDone = false;
if(szFilename && szFilename[0])
{
mFilenameLoop = szFilename;
mTheoraTexture.setFile(szFilename, true); //- change 2nd parameter to true
}
} /

and for
void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect)
{ ...

    //Add this if statement.  
  else if(mShowBackground)  
    {  
        dglDrawRectFill(rect, mBackgroundColor); // black rect  
    }  
renderChildControls(offset, updateRect);
}

Is the above correct? I just simply added it at the bottom.


#7
09/04/2012 (1:55 pm)
Since you added my looping code the ENTIRE onRender funciton should be:

void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect)
{
   const RectI rect(offset, mBounds.extent);

	if(mTheoraTexture.isReady() && mTheoraTexture.isPlaying())
	{
		mTheoraTexture.refresh();
		dglClearBitmapModulation();
		dglDrawBitmapStretch(mTheoraTexture, rect);
	}
	else
	{
		if(mTheoraTexture.isReady())
			mDone = true;

        //This checks if looping is turned on and there is more video to play
		if(mLoop == true && mTheoraTexture.isReady() && mFilenameLoop)
		{
			mTheoraTexture.setFile(mFilenameLoop, mLoop);
		}
		else if(mShowBackground)//Video is done playing so we check if we are allowed to draw the background
		{
			dglDrawRectFill(rect, mBackgroundColor); // Whatever Color...
		}
	}

	renderChildControls(offset, updateRect);
}
#8
09/04/2012 (2:17 pm)
Brilliant!!! it all works !!!
Sorry to bother you with he previous post, I forgot to add the variable showBackground = 0; to my GuiTheoraCtrl :)

Thanks again, I'm sure lots of people will appreciate it.
#9
09/04/2012 (8:26 pm)
Very nice to hear you figured out how to get videos working properly! I'm sure this will come in handy in the future for lots of people :)
#10
09/04/2012 (8:43 pm)
I have added looping and an option about removing the rectangle. I just might add a resource about upgrading the video features when I fix/add a couple more things.
#11
09/18/2012 (5:15 pm)
Alpha -- nice work.

Any improvements to the video playing capabilities of T2D are surely welcome.