PLUGIN: SpriteVideo v0.9.4 (sprite and video render), based on Direct3D plugin

Started by Crimson Wizard, Fri 08/07/2022 19:34:30

Previous topic - Next topic

Crimson Wizard

This is an upgrade of the older "Direct3D" plugin by AJA, which was used to display Theora videos in AGS, and also freely display sprites with various transformations (without creating standard game objects).

WARNING: neither the original plugin nor this reimplementation play any sounds from videos, they only display video frames. Adding sound support might be a goal for the future versions, but it's not in the immediate plans.

The original plugin was a nice addition as it worked around some engine's limitations, such as being unable to display video non-blocking or while keeping some other objects on screen (like GUI or cursor); or randomly creating scaled and rotated sprites on any layer in game. Not much changed since, except maybe in AGS 3.6.0 Overlays now come close to this plugin's sprites abilities.
But the older plugin also had a significant limitation, as it was made for an older engine, it did not support anything besides Direct3D renderer on Windows.

This new upgraded version, called "SpriteVideo", now has following major improvements:
* OpenGL renderer support;
* May be built for Linux;
* Potentially maybe will work on Mac and Android, but not yet configured the project for that.

Another important part is that this plugin is purposely made 100% script compatible with the old plugin, which means that you may simply replace it in your game project and all the scripts will continue to work. In fact, you may even rename new plugin's dll into "ags_d3d.dll", replace it in the game folder, and it should hook up correctly.

Documentation:
https://github.com/ivan-mogilko/ags-spritevideo/wiki

The plugin is currently in the "test stage", and I will be interested to see how it works with existing games that used the original plugin. My primary goal at this point is to make it complete and stable substitute for "Direct3D" plugin.

Downloads:
Updated 24 April 2023
For Windows: https://github.com/ivan-mogilko/ags-spritevideo/releases/download/v0.9.4/win_ags_spritevideo.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-spritevideo/releases/download/v0.9.4/libags_spritevideo.tar.xz
Source code: https://github.com/ivan-mogilko/ags-spritevideo

TODO for v1.0:
* Testing in some real games.
* Bug fixing

Tarnos12

Thanks,

Just to add to that, the documentation for d3d is not complete afaik.
There are some properties and/or functions which don't have explanations.

Looking forward to android/osx support in the future and perhaps some new features.

Crimson Wizard

Updated to v0.9.1, now implements D3D.OpenSpriteFile() again.

For Windows: https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.1/win_ags_sprite3d.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.1/libags_sprite3d.tar.xz

I think this now covers all the functionality of the old plugin. What remains is mostly testing and writing a documentation.

Vincent

Thank you very much Crimson for working on this plugin, I really appreciate! 💖

AndreasBlack

Cool! Can't wait to try it out later! 8-0  (nod) Thanks like always. Too much summer activities as of lately so not much of game creation going on, on my end. Great to see others keeping the spirit up (laugh)

Jess McD

I tried to use this plug in on my test game, but received an error "undefined token 'video'".  I was attempting to play the video clip on room load before the fade in.  Is there anything I need to do beyond copying the plug-in file to the ags directory?

I'm running AGS Build 3.5.1.19


Crimson Wizard

Quote from: Jess McD on Thu 21/07/2022 04:43:37
I tried to use this plug in on my test game, but received an error "undefined token 'video'".  I was attempting to play the video clip on room load before the fade in.

Please post your script where you are using this plugin?

Quote from: Jess McD on Thu 21/07/2022 04:43:37
Is there anything I need to do beyond copying the plug-in file to the ags directory?

You also need to activate the plugin in the game's project tree.

Jess McD

The plugin is activated.  This is just a simple room where I would like it to play the video, then open a menu with a title screen and start button.  Everything works just fine, until I try to add the video.  The plug in instructions just had the code, but not a lot of explanation, so I'm sure I just missed something

The code is below.  -Thank you!

// room script file


function room_Load()
{
gIconbar.Visible = false;
gStatusline.Visible = false;
mouse.DisableMode(eModeWalkto);
mouse.DisableMode(eModeLookat);
mouse.DisableMode(eModeInteract);
mouse.DisableMode(eModeTalkto);
mouse.DisableMode(eModeUseinv);
mouse.DisableMode(eModePickup);
mouse.DisableMode(eModeUsermode1);
mouse.DisableMode(eModeUsermode2);
mouse.EnableMode(eModePointer);
mouse.Mode = eModePointer;

// Required for autoplay
    D3D.SetLoopsPerSecond( GetGameSpeed() );
   
    // Open video file
    video = D3D.OpenVideo( "G:\AGS_RPG_POC\Renders\MMI Intro.ogv" );
   
    if ( video )
    {
        // Use room coordinates
        video.relativeTo = eD3D_RelativeToRoom;
       
        // Anchor point to top left corner
        video.SetAnchor( -0.5, -0.5 );
       
        // Play!
        video.Autoplay();
    }
    else
    {
        Display( "Couldn't open video." );
        return;

aTitleMusic.Play();
}

function Startbutton_AnyClick()
{
cEgo.ChangeRoom (2);
}

function room_Leave()
{
// Free memory when leaving the room
    video = null;
}

Crimson Wizard

Quote from: Jess McD on Sat 23/07/2022 20:49:56Everything works just fine, until I try to add the video.  The plug in instructions just had the code, but not a lot of explanation, so I'm sure I just missed something

In your code you are using a variable called "video", but you have not declared it anywhere. Since you are using it in multiple functions, you need to declare a global variable, somewhere at the top of your script:
Code: ags

D3DVideo* video;


Jess McD

I placed:

Code: ags
// define video
D3DVideo* video;


at the top of the global script, but I still get the undefined token error on the "video = D3D.OpenVideo ....." line of my room1 script.


Thank you for your help so far, I appreciate it.

Crimson Wizard

Quote from: Jess McD on Sat 23/07/2022 21:46:38
I placed:

Code: ags
// define video
D3DVideo* video;


at the top of the global script, but I still get the undefined token error on the "video = D3D.OpenVideo ....." line of my room1 script.

If you are using this variable only in the room script, then you should declare it in the room script. Room script does not see variables declared inside the global script.

If you want to use this variable throughout the game, in global script and multiple rooms, then you need to place it in global script and import/export it.
Code: ags

// in GlobalScript.asc
D3DVideo* video;
export video;

// in GlobalScript.ash
import D3DVideo* video;


AGS manual has this article about sharing variables between scripts:
https://adventuregamestudio.github.io/ags-manual/ImportingFunctionsAndVariables.html

Jess McD

Thanks again for all your help!  I'll be using video in every room, so this sounds like a great solution.  I placed the code as instructed, lines 2&3 in the global script and line 6 in the global header.  I'm now getting the following error when I attempt to run the game.

Code: ags
Failed to save room room1.crm; details below
GlobalScript.ash(7): Error (line 7): expected variable or function after import, not 'D3DVideo'


Sorry for asking so many questions - this is the first time I've used a plug-in.  Getting the music to keep playing while a video plays is one the last obstacles to overcome for my little proof of concept game - then I can start developing the real thing!

Thanks again!

Crimson Wizard

Quote from: Jess McD on Mon 25/07/2022 01:22:54
Code: ags
Failed to save room room1.crm; details below
GlobalScript.ash(7): Error (line 7): expected variable or function after import, not 'D3DVideo'


Sorry for asking so many questions - this is the first time I've used a plug-in.

Sorry, I said it wrong, it's D3D_Video, not D3DVideo.
This is mentioned in the original plugin's documentation here: http://www.serpentpictures.net/ags_d3d/ where it sais "b) Playing a video over the background"


EDIT:
Quote from: Jess McD on Mon 25/07/2022 01:22:54Getting the music to keep playing while a video plays is one the last obstacles to overcome for my little proof of concept game - then I can start developing the real thing!

I was curious and found your previous posts about the game you're trying to make here: https://www.adventuregamestudio.co.uk/forums/index.php?topic=60020.0

I must mention that this plugin does not play any sound, it technically has no audio output, so it only displays video frames. I should have mentioned this in the description earlier.
Resolving the sound issue would require either to fix the engine and let it play video sounds simultaneously with the game sounds (that's perfectly possible to do), or extend the plugin to support audio output.

Jess McD

Thank you!  The video played, and my menu sprites were still displayed above the video, that's exactly what I wanted!  I experimented by playing an audio file immediately after the video started, and it played at the same time.  I'll continue experimenting with playing the audio exported from the original video files and see how close they sync up.

1 more question for you.  When the video ended it just froze on the last frame until I clicked.  Is there a way to make it go away without user input when the video ends? - Calculated video cycles then:

Code: ags
WaitMouseKey(640);

video = null;


Thanks again!  Getting the video to play over the sound was a huge step toward getting my crazy idea out of my head and onto a screen. You made my day!

Crimson Wizard

Updated to v0.9.2,

- Fixed D3D_Sprite's Tint properties not working in OpenGL mode.
- Fixed plugin crash when exiting game while video is playing.

For Windows: https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/win_ags_sprite3d.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-sprite3d/releases/download/v0.9.2/libags_sprite3d.tar.xz

Crimson Wizard

I decided to rename this plugin from "Sprite3D" to "SpriteVideo", that in my opinion better reflects what it does and is meant for.
All the script commands stay the same, of course, but if you used this plugin before in your game, you only need to disable old plugin with old name, and activate new plugin with the new name.

Also, updated to v0.9.3 with some minor fixes.

For Windows: https://github.com/ivan-mogilko/ags-spritevideo/releases/download/v0.9.3/win_ags_spritevideo.zip
For Linux (debian-based): https://github.com/ivan-mogilko/ags-spritevideo/releases/download/v0.9.3/libags_spritevideo.tar.xz

I think the plugin is fully working and ready to be released as a complete version 1.0, but I would like to hear from someone who used this in real games, especially with OpenGL renderer and on Linux.

grahfmusic

Excellent; I've been waiting for years for this plugin to be updated for me to get back into AGS again.  Unfortunately, it is using the Ogg Theora video, considering it has become an obsolete codec since VP8 and VP9.   Is it difficult to integrate more modern open-source codecs into AGS?

Crimson Wizard

Quote from: grahfmusic on Mon 03/10/2022 22:43:14Unfortunately, it is using the Ogg Theora video, considering it has become an obsolete codec since VP8 and VP9.   Is it difficult to integrate more modern open-source codecs into AGS?

The video playback is fully implemented inside the plugin, it's not using AGS own functionality to play them. So there are two separate questions:
* video support in this plugin,
* video support in AGS itself.

I guess it's easier to do in plugin first, since it already has a non-blocking playback. AGS would require to reimplement video controls, and add more sophisticated playback script API to support the same thing.

Unfortunately, I have no idea what codecs VP8 and VP9 are, what are they played with. I understand the principles of programming video, but do not know alot about formats and codecs.

Vincent

Hello, I tested this plugin on the new version of Ags. I think this has already been documented but it seems the plugin doesn't work if the game is compiled for android, can you guys confirm this? When I open the game on my phone I get this screen: (Sorry for the giant picture)



In addiction I'd like to say that this plugin is very important to me because I like making FMV games and I would like if one day it could also embed video sound instead of mute because sometimes syncing sound with video is difficult. Also it would be very helpful (for me) if we could have a way to pause the video.

Crimson Wizard

Quote from: Vincent on Mon 23/01/2023 11:26:42Hello, I tested this plugin on the new version of Ags. I think this has already been documented but it seems the plugin doesn't work if the game is compiled for android

Of course, you need to have this plugin compiled for Android too. Each plugin you are using has to be compiled separately for each platform you're building your game for.

I don't remember how do you add plugins for Android though, this has to be clarified. Probably, they are put somewhere inside the Android subfolder, inside the Editor program files.

SMF spam blocked by CleanTalk