GuiAviBitmapCtrl w/ DirectShow event support
by Todd D. Degani · 05/26/2005 (11:23 pm) · 39 comments
Download Code File
The code for the control is a modified version of the GuiAviBitmapCtrl code contributed by Tim Heldna. I believe Tim's changes were based on the changes to the control implemented by John Vanderbeck.
This code has been tested on a stock version 1.3 build of TGE on Windows.
This has not been tested on Linux or MacOS.
This control closes the playing AVI on mouse click, on key press, and when the movie has fully played.
To determine when a movie has finished playing works like this:
- DirectShow starts and begins sending event notifications to the game window
- The game window receives these messages, packs them into an event, and posts them to the game
- When the game receives these messages it looks to see if the EC_COMPLETE was reveived. If it was it calls movieClose on the control whose id corresponds to the id passed in from the event
Remember to backup your original files before proceeding!
Installation:
Engine:
To manually patch the engine check each of files included in the zip. My changes are clearly marked with "// TDD" before them and with "//---------------" afterwards.
Otherwise you can just unzip the .cc and .h files into your engine directory and recompile.
/engine/game:
demoGame.h
main.cc
/engine/platform:
event.h
gameInterface.cc
gameInterface.h
/engine/platformWin32:
winWindow.cc
Note: This file also contains the following excellent resources by Brandon Maness
Fix cursor disappearing on title bar
Fix Strange position on window focus
These two files for the actual control are based on Tim Heldna's revisions of the controls. I highly suggest simply overwriting your current version of these files unless you have made modifications to these files which you wish to keep. I'm sure it would be a pretty nasty merge.
/engine/gui:
guiAviBitmapCtrl.cc
guiAviBitmapCtrl.h
Scripts:
These scripts will play the avi from introMovie1, then the avi from introMovie2, then go to the main menu.
If you press a key or click the mouse you will skip past the currently playing movie. If you just let them play then the movies will play till completion then continue on.
MovieBackground.png is just a 1x1 black png that is stretched across the canvas so that if the video is smaller than the screen resolution something will be rendered in the "empty" area.
Again, remember to backup your original files before proceeding!
Copy these files to /starter.fps/client/ui:
introMovie1.cs
introMovie2.cs
StartupGui.gui
movieBackground.png
Now just change the paths to the avi files in introMovie1 & introMovie2 scripts to point to point to the movie(s) you want to display.
*** Changelist ***
Date: 5/12/2005 - Original Checkin
The code for the control is a modified version of the GuiAviBitmapCtrl code contributed by Tim Heldna. I believe Tim's changes were based on the changes to the control implemented by John Vanderbeck.
This code has been tested on a stock version 1.3 build of TGE on Windows.
This has not been tested on Linux or MacOS.
This control closes the playing AVI on mouse click, on key press, and when the movie has fully played.
To determine when a movie has finished playing works like this:
- DirectShow starts and begins sending event notifications to the game window
- The game window receives these messages, packs them into an event, and posts them to the game
- When the game receives these messages it looks to see if the EC_COMPLETE was reveived. If it was it calls movieClose on the control whose id corresponds to the id passed in from the event
Remember to backup your original files before proceeding!
Installation:
Engine:
To manually patch the engine check each of files included in the zip. My changes are clearly marked with "// TDD" before them and with "//---------------" afterwards.
Otherwise you can just unzip the .cc and .h files into your engine directory and recompile.
/engine/game:
demoGame.h
main.cc
/engine/platform:
event.h
gameInterface.cc
gameInterface.h
/engine/platformWin32:
winWindow.cc
Note: This file also contains the following excellent resources by Brandon Maness
Fix cursor disappearing on title bar
Fix Strange position on window focus
These two files for the actual control are based on Tim Heldna's revisions of the controls. I highly suggest simply overwriting your current version of these files unless you have made modifications to these files which you wish to keep. I'm sure it would be a pretty nasty merge.
/engine/gui:
guiAviBitmapCtrl.cc
guiAviBitmapCtrl.h
Scripts:
These scripts will play the avi from introMovie1, then the avi from introMovie2, then go to the main menu.
If you press a key or click the mouse you will skip past the currently playing movie. If you just let them play then the movies will play till completion then continue on.
MovieBackground.png is just a 1x1 black png that is stretched across the canvas so that if the video is smaller than the screen resolution something will be rendered in the "empty" area.
Again, remember to backup your original files before proceeding!
Copy these files to /starter.fps/client/ui:
introMovie1.cs
introMovie2.cs
StartupGui.gui
movieBackground.png
Now just change the paths to the avi files in introMovie1 & introMovie2 scripts to point to point to the movie(s) you want to display.
*** Changelist ***
Date: 5/12/2005 - Original Checkin
About the author
#2
Well done, and thanks for sharing.
06/01/2005 (5:28 am)
Todd, this is brilliant. Works perfectly and it worked first time. Well done, and thanks for sharing.
#3
06/01/2005 (5:55 am)
So useful for an intro, Thank you !!!
#4
06/01/2005 (8:04 am)
This is probably one of the most useful, and easy to do resources yet. Thanks!
#5
Just another piece of useless trivia brought to you by GTC.
06/01/2005 (4:23 pm)
If Todd had waited one more day to release it would have been exactly one year from the day John V. released his version, lol.Just another piece of useless trivia brought to you by GTC.
#6
Now does anybody know how to get it to automagically stretch the video to fit the canvas if necessary?
06/26/2005 (9:59 pm)
Love it. Worked beautifully the first time through without any headaches at all. Thanks a ton!Now does anybody know how to get it to automagically stretch the video to fit the canvas if necessary?
#7
You should be able to set the horizsizing and vertsizing to width and height and it should stretch to fit the screen
06/27/2005 (7:15 am)
@JonathanYou should be able to set the horizsizing and vertsizing to width and height and it should stretch to fit the screen
#8
06/27/2005 (8:16 am)
Is it really that simple? I was looking for some complex change somewhere in the engine's source files... Thanks for the quick help!
#9
I succesfully bridge your version onto T2D. Please give me permission to post?
06/28/2005 (8:37 pm)
@ToddI succesfully bridge your version onto T2D. Please give me permission to post?
#10
06/28/2005 (9:19 pm)
Thats great to hear Danny. Feel free to post a resource on it. Glad to see it getting some use.
#11
07/07/2005 (9:42 am)
Any plans to modify this to work with TSE? So far all my attempts to get the patch working in TSE have failed. I just spent a whole days worth of work trying to get it to work to no avail.
#12
07/07/2005 (5:56 pm)
I don't own TSE so someone other than myself would have to pick up the ball on that.
#14
Plays every format I've thrown at it. :)
Thank you.
Ari
11/07/2005 (8:32 pm)
Works great in TGE 1.3!Plays every format I've thrown at it. :)
Thank you.
Ari
#15
03/07/2006 (1:40 am)
I can't play video in windowed mode. The graph isn"t created in the Torque window. Has anyone a fix for that please ?
#16
03/17/2006 (7:51 am)
For some reason my .avi file isn't playing. Could it be because I have version 1.4 of Torque?
#17
f:\fowlplay\engine\game\main.cc(161) : error C3861: 'RegisterCoreTypes': identifier not found
f:\fowlplay\engine\game\main.cc(162) : error C3861: 'RegisterMathTypes': identifier not found
f:\fowlplay\engine\game\main.cc(163) : error C3861: 'RegisterGuiTypes': identifier not found
winWindow.cc
f:\fowlplay\engine\platformwin32\winwindow.cc(103) : error C2664: 'CreateMutexW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(119) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(126) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(133) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(773) : error C2440: '=' : cannot convert from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(780) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(814) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(828) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1210) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1219) : error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [256]' to 'LPWCH'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1300) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char [25]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1307) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [1]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1316) : error C2666: 'dStrstr' : 2 overloads have similar conversions
f:\fowlplay\engine\platform\platform.h(453): could be 'char *dStrstr(const char *,const char *)'
f:\fowlplay\engine\platform\platform.h(452): or 'char *dStrstr(char *,char *)'
while trying to match the argument list '(char [512], const char [5])'
f:\fowlplay\engine\platformwin32\winwindow.cc(1340) : error C2664: 'CreateProcessW' : cannot convert parameter 2 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1354) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1358) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1377) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1379) : error C2664: 'RegSetValueExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1399) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1403) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
guiAviBitmapCtrl.cc
f:\fowlplay\engine\gui\game\guiavibitmapctrl.cc(197) : error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [22]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
03/30/2006 (10:42 pm)
I can't even get it to compile with Torque 1.4. After fixing all the #include path errors (i.e. "#include gui/guiControl.h" needs to become "#include gui/core/guiControl.h"), I still get the following errors:f:\fowlplay\engine\game\main.cc(161) : error C3861: 'RegisterCoreTypes': identifier not found
f:\fowlplay\engine\game\main.cc(162) : error C3861: 'RegisterMathTypes': identifier not found
f:\fowlplay\engine\game\main.cc(163) : error C3861: 'RegisterGuiTypes': identifier not found
winWindow.cc
f:\fowlplay\engine\platformwin32\winwindow.cc(103) : error C2664: 'CreateMutexW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(119) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(126) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(133) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(773) : error C2440: '=' : cannot convert from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(780) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(814) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(828) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1210) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1219) : error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [256]' to 'LPWCH'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1300) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char [25]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1307) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [1]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1316) : error C2666: 'dStrstr' : 2 overloads have similar conversions
f:\fowlplay\engine\platform\platform.h(453): could be 'char *dStrstr(const char *,const char *)'
f:\fowlplay\engine\platform\platform.h(452): or 'char *dStrstr(char *,char *)'
while trying to match the argument list '(char [512], const char [5])'
f:\fowlplay\engine\platformwin32\winwindow.cc(1340) : error C2664: 'CreateProcessW' : cannot convert parameter 2 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1354) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1358) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1377) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1379) : error C2664: 'RegSetValueExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1399) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
f:\fowlplay\engine\platformwin32\winwindow.cc(1403) : error C2664: 'RegQueryValueExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
guiAviBitmapCtrl.cc
f:\fowlplay\engine\gui\game\guiavibitmapctrl.cc(197) : error C2664: 'FindWindowW' : cannot convert parameter 1 from 'const char [22]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
#18
11/24/2006 (4:27 pm)
I am currently unable to play the video file. My ConsoleMethod( GuiAviBitmapCtrl, play, ..... is not recognized in my script when i do introVideo.play() i look at the console output and it says "Unknown command play" any suggestions on what i might be doing wrong?
#19
Please check out our forum post if you have a moment and some experience with OpenGL or DirectX or even Windows programming... Or are just curious!
http://www.garagegames.com/mg/forums/result.thread.php?qt=54437#410324
11/29/2006 (10:13 am)
We are having a problem where when we play videos in fullscreen, our monitor stalls and flickers and changes focus to a window on our desktop at our native resolution. Then it won't go back to the main program unless we click on the Torque main game task in the task manager. We need some help.Please check out our forum post if you have a moment and some experience with OpenGL or DirectX or even Windows programming... Or are just curious!
http://www.garagegames.com/mg/forums/result.thread.php?qt=54437#410324
#20
02/08/2007 (1:56 pm)
Started looking at this great resource at approx 5pm today. Imported it into TGEA(TSE). Made a couple of tweaks to the code to get it to compile, and had to write my own gui to make it play without crashing. TGEA does not seem to like using the included gui with canvas.pushdialog. Time is now 10pm and my application checks the registry to see if it should play a video when starting up and the video plays happily in TGEA, even in windowed mode. I can post a resource if you'd like working videos in TGEA! 
Torque Owner Todd D. Degani