Game Development Community

dev|Pro Game Development Curriculum

In-game Theora object for TGE 1.3

by David Barr · 11/15/2005 (2:49 pm) · 17 comments

Download Code File

The following resource relies on this one being implemented first -> www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8820

Here is a forum thread which gave rise to this post - there is a little video demo in there. (I have just thought - that forums for TSE so heres the video link if you cannot access that post - 13 MB example in mpeg encoding - video is a clip from megadeth (c) Capitol Records)

A quick way to get theora video files playing inside a game. This object is based heavily on Melv Mays fxRenderObject which is probably one of the most useful things on here for learning about TGE :)

1, Integrate the "1.4 Theora support in 1.3" resource above. NB I changed the file locations from that resource to keep their correct paths as they were under TGE 1.4. You may need to edit the includes in the 2 files for this resource if your paths differ.
2, Add the 2 files (fxvideorenderobject.h and fxvideorenderobject.cc) from this resource to your build and recompile (I placed them in /game/fx/)
3, Add the following functions to script (these are the instructions at the top of the cc file modified from the original fxRenderObject) :-

//------------------------------------------------------------------------------
//
//	Put the function in /example/common/editor/ObjectBuilderGui.gui [around line 458] ...

function ObjectBuilderGui::buildfxVideoRenderObject(%this)
{
	%this.className = "fxVideoRenderObject";
	%this.process();
}

//------------------------------------------------------------------------------
//
//	Put this in /example/common/editor/EditorGui.cs in [function Creator::init( %this )]

%Environment_Item[ 'next free entry' ] = "fxVideoRenderObject";  // 'next free entry' = the next number

//------------------------------------------------------------------------------


Add the following binds somewhere (I had them in client/scripts/default.bind.cs)

//moveMap.bindCmd(keyboard, "alt 0", "commandToServer('stopvideofile');", "");
//moveMap.bindCmd(keyboard, "alt 9", "commandToServer('playvideofile');", "");

Add the following 2 functions to script (I had them in server/scripts/commands.cs)

function serverCmdPlayVideoFile()
{
   %filename = "control/data/video/killtheking750.ogg"; //obviously change this name to a valid video and path :)
   VideoCon.setfile(%filename);
}

function serverCmdStopVideoFile()
{
   VideoCon.stop();
}

Start TGE, load up a mission, add an fxvideorenderobject, call the object VideoCon and set a valid background picture file. An example of what is added to the mission file is as follows :-
new fxVideoRenderObject(VideoCon) {
      position = "287.155 42.8313 241.882";
      rotation = "0.133388 0.133388 -0.982046 91.0378";
      scale = "1 1 1";
      QuadSize = "5";
      ScreenWidth = "40";
      ScreenHeight = "30";
      QuadRotateSpeed = "0";
      Texture = "~/data/video/vibackground.jpg"; //change this to a valid name and path to texture
      done = "0";
      stopOnSleep = "0";
      backgroundColor = "0 0 0 255";
   };

If you use that one you will need to position and size accordingly.

The screen can be resized but try and keep the proportions to 3 high to 4 wide (assuming your video is standard 4:3 stuff)

When the video is not playing, the object displays whatever texture file you specify (you must specify a texture file or the object will not render).

Alt 9 will play the file you specify in the function, Alt 0 will stop the playback.

The object is network aware so in a multiplayer game, video playback starts and stops for all players at once.

Known Issues :-
1, The Theoratexture sometimes does not report the correct sizes so the UV coords gets messed up.
2, Playing a file twice in a row results in unsynched sound.
3, Use the newest openal32.dll from creative labs (saves all sorts of nastiness)
4, Have fun with it - its only a demo object but isnt far off a useful game object with a few script changes.

#1
11/15/2005 (11:21 pm)
Very nice. I haven't tried this yet, but will start on it as soon as I send this message. Thanks for posting this as a resource.

Aaron E.
#2
11/15/2005 (11:46 pm)
I just tried to force this into 1.4. I knew it wouldn't work with my current code, but I had to try. Maybe later I'll figure out a way get it in.

Either way, this is a great resource.

[edit: typo]
#3
11/16/2005 (6:04 am)
Aaron

I got it working fine in 1.3 and 1.4 rc2 but I created a different object to handle this. It is a modified version of Melv's fxRenderObject. Great learning resource by the way. When I get a few minutes I'll try and put it together as a resource.
#4
11/16/2005 (7:20 am)
Jackie,

Sounds great. You've been helping me out a lot lately with your posts. I definitely appreciate it.

Thanks,

Aaron E.
#5
11/17/2005 (4:36 am)
This worked really good .
Thanks alot David !
#6
11/24/2005 (5:15 pm)
This is very cool. :)
#7
11/29/2005 (5:44 am)
I'm implemented this resource into my project based on TGE 1.4, works great. Almost.

When running a dedicated server, I am finding some bad behavior.

1) I have two clients, the first one connects and starts the video. Eveything is ok still. But when the second client connects, that second client freezes, no control, but I can hear the video playing in the background.

2) Once both my clients have connected, client 1 starts the video. Client 1 then stops the video. Client 2 now disconnects and reconnects. I get the same behavior. Second client freezes, no control, but I can hear the video playing in the background. (eh?? I had stopped it)


I have not stepped down into the core code yet to see whats the problem, was hopping someone here encountered it and fixed it, before I get down and dirty, code diving.
#8
05/13/2006 (6:52 am)
great resource!
can somebody tell how to implement this resource into TGE 1.4 for TGE newbie?

thanks in advance!!
#9
09/03/2007 (3:55 am)
It works nicely with TGE 1.5. Thanks for sharing!
#10
12/23/2007 (4:48 pm)
Is it possible to do the same thing displaying a LIVE webtv (this webtv is using the theora codec of course)
#11
04/10/2008 (8:48 am)
valie, there would have to be some kind of streaming support for the files, and as far as I have been able to find, theora expects the file to be fully there locally in order to play. It's a hot topic for me right now so I'll keep looking.
#12
04/11/2008 (6:03 pm)
Thank you for your interest Dave..
At this moment I use a Webtv based on the Windows Media Player codec 9 .... but I can change it for the Theora Codec..... if it's necessary...
Is 152 engine fonctionning only with the Theora Codec or there is an other solution ????
#13
02/11/2009 (12:09 pm)
I started playing with this resource and found a solution for Known Item #1.

It turns out the UV's are fine, but the object sometimes renders before the video is ready and in the code block after "//nope so get our static texture", it resets the UV's back to 1,1.

So what I did is I keep two sets of coordinates. One is for the background picture (always 1,1). The other is for the video (set in playFile). Then in the render I just use whichever set I need instead of overwriting one gobal set.
#14
02/11/2009 (12:39 pm)
The second thing I did was add a flag to TheoraTexture similar to mPlaying. The difference is that this flag is set once the first call to drawFrame has occurred. Thus after "/do we have a video playing?" checks to see if the video has started, I wait until the first frame has been drawn to avoid an unwanted flash of an empty texture.
#15
05/06/2010 (3:17 am)
does it work in T3D???
#16
05/17/2010 (6:47 pm)
HI,I wanna can it be 3D sound.That means I can't here the suond until I stand by the video player, and when I go far away from it,I hear that the sound become lower and lower???
#17
03/16/2013 (4:08 am)
wow~~