This plugin allows you to harness some of the power Direct3D offers in your AGS games. Currently it is possible to render sprites (AGS sprites as well as external image files) and Theora video files. Both can be arbitrarily rotated, scaled and placed where ever they are needed.
Games using this plugin have to use 32bit colours and can only be run with the Direct3D driver.
In order to prevent players from viewing Theora video files outside the game, a Simple OGG Obfuscator (soggo.exe) is included with the plugin. Drag'n'dropping a Theora video file onto the exe obfuscates the video by rewriting a tiny bit of the file header. So far I've tested VLC and Media Player Classic and neither plays the obfuscated file. Unobfuscating is relatively easy if you know your way 'round a hex editor but it should be enough for most players. Run soggo.exe from the command line to unobfuscate files.
Thank you for your interest!
- AJA
Date Description
-----------------------------------------------------------------
1.0.2 2017-01-17 Fixed video file not found crash.
Fixed alignment issue and video not scaling correctly with screen size.
1.0.1 2017-01-14 Fixed bit depth check for AGS 3.4.0 and later
1.0 2012-02-07 Initial release.
Sprites and videos will be held in memory until all pointers that are pointing to them are lost. That means in order to free a sprite from memory, simply set the sprite pointer to null:
D3D_Sprite* sprite = D3D.OpenSprite( 0 ); // Sprite is created sprite = null; // Sprite is destroyed
bool useAGSSprite = true; D3D_Sprite* sprite; function room_Load() { if ( sprite == null ) { if ( useAGSSprite ) { // Sprite from slot 2000 sprite = D3D.OpenSprite( 2000 ); } else { // External file with sharp filtering sprite = D3D.OpenSpriteFile( "MyImage.png", eD3D_FilterNearest ); } if ( sprite == null ) { Display( "Couldn't open sprite." ); return; } // Draw over cursor sprite.renderStage = eD3D_StageScreen; // Use screen coordinates sprite.relativeTo = eD3D_RelativeToScreen; // Show only in this room sprite.room = 1; } } function repeatedly_execute_always() { if ( sprite ) { // Follow mouse sprite.SetPosition( mouse.x, mouse.y ); } }
D3D_Video* video; function room_Load() { // Required for autoplay D3D.SetLoopsPerSecond( GetGameSpeed() ); // Open video file video = D3D.OpenVideo( "TheoraVideo.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; } } function room_Leave() { // Free memory when leaving the room video = null; }
/** * D3D * * D3D is contains all the methods required to open sprites and * video files and set general settings. */ struct D3D { /** * Tells the plugin how many game loops pass in one second. * * The most frequent use case is: * D3D.SetLoopsPerSecond( GetGameSpeed() ); * * The plugin needs to know the game speed for example * when autoplaying video clips. */ import static void SetLoopsPerSecond( int loops ); /** * Opens a Theora video file from the compiled game * directory. * * The video may be obfuscated with Simple OGG Obfuscator * (soggo.exe, provided with this plugin). * * Returns: Null on failure, a pointer to the video * on success. */ import static D3D_Video* OpenVideo( String filename ); /** * Opens an AGS sprite, identified by its graphic slot. * * Note: Currently AGS sprites always use linear filtering. * * Returns: Null on failure, a pointer to the sprite * on success. */ import static D3D_Sprite* OpenSprite( int graphic ); /** * Opens a sprite from the compiled game directory. * * Supported file formats are: BMP, JPG, TGA, PNG, * DDS, PPM, DIB, HDR, and PFM. * * Filtering specifies how the sprite should be filtered * when rendered to the screen. * * Returns: Null on failure, a poitner to the sprite * on success. */ import static D3D_Sprite* OpenSpriteFile( String filename, D3D_Filtering filtering ); }; /** * D3D_Sprite * * D3D_Sprite represents a texture that can be drawn * onto the screen. Attributes and methods relating to * updating (isEnabled, isAutoUpdated, Update()) the sprite * are not relevant for D3D_Sprite but are used in some * classes that inherit these attributes and methods from * D3D_Sprite (eg. D3D_Video). */ managed struct D3D_Sprite { /** * Can the sprite be automatically updated. * * Note: has no effect on D3D_Sprites. * * Default: true */ import attribute bool isEnabled; /** * Can the sprite be automatically rendered. * * Default: true */ import attribute bool isVisible; /** * X position. * * Note: The sprite's anchor point will be * placed at this coordinate. * * Default: 0 */ import attribute int x; /** * Y position. * * Note: The sprite's anchor point will be * placed at this coordinate. * * Default: 0 */ import attribute int y; /** * Width. * * Result: Sprite width or 0 if AGS has not yet * passed the Direct3D device to the plugin, * ie. the texture hasn't been created yet. */ writeprotected import attribute int width; /** * Height. * * Result: Sprite height or 0 if AGS has not yet * passed the Direct3D device to the plugin, * ie. the texture hasn't been created yet. */ writeprotected import attribute int height; /** * Anchor point X, relative to the size of the sprite. * * Note: Anchor point (0, 0) is the center of * the sprite. The bottom right corner is * the point (0.5, 0.5). * * Default: 0.0 */ import attribute float anchorX; /** * Anchor point Y, relative to the size of the sprite. * * Note: Anchor point (0, 0) is the center of * the sprite. The bottom right corner is * the point (0.5, 0.5). * * Default: 0.0 */ import attribute float anchorY; /** * Rotation in degrees around the anchor point. * * Default: 0.0 */ import attribute float rotation; /** * Scaling. * * Default: 1.0 */ import attribute float scaling; /** * Will the sprite be automatically updated every frame. * * Note: has no effect on D3D_Sprites. * * Default: true */ import attribute bool isAutoUpdated; /** * Will the sprite be automatically rendered every frame. * * Default: true */ import attribute bool isAutoRendered; /** * At which stage will the sprite be rendered. * * Default: eD3D_StageBackground */ import attribute D3D_RenderStage renderStage; /** * What is the object position related to. * * Default: eD3D_RelativeToRoom */ import attribute D3D_RelativeTo relativeTo; /** * Which room will the object be active (enabled and visible) in. * * A negative value means the sprite is active in all rooms * * Default: -1 */ import attribute int room; /** * Shortcut to set X and Y position. */ import void SetPosition( int x, int y ); /** * Sets the anchor point. * * Note: Anchor point (0, 0) is the center of * the sprite. The bottom right corner is * the point (0.5, 0.5). */ import void SetAnchor( float x, float y ); /** * Manually updates the sprite. * * Note: doesn't need to be called for D3D_Sprites. */ import void Update(); /** * Manually renders the sprite to the screen. */ import void Render(); }; /** * D3D_Video * * D3D_Video represents a Theora video clip. Audio is not * supported. D3D_Video inherits all the attributes and methods * from D3D_Sprite and provides a few extra ones that concern * video playback. */ managed struct D3D_Video { /* Inherited attributes and methods from D3D_Sprite */ /** * Will the video replay immediately after it has ended. * * Default: false */ import attribute bool isLooping; /** * Playback framerate when autoplaying. * * Default: Video file's framerate */ import attribute float fps; /** * Advances into the next frame of the video. * * Returns: Did the video end (false) or not (true) */ import bool NextFrame(); /** * Plays the video automatically. * * If the isAutoUpdated attribute is true, the video will * advance at the specified framerate automatically. * * Note: if the game speed is not the default (40), * you must set the correct speed by calling * D3D.SetLoopsPerSecond( GetGameSpeed() ); * Otherwise the video won't know how much time * passes each game loop. */ import void Autoplay(); /** * Is the video playing automatically. */ import bool IsAutoplaying(); /** * Stops autoplaying, pauses the video. */ import void StopAutoplay(); }; /** * D3D_Filtering * * D3D_Filtering specifies the texture filtering * method used for rendering a D3D_Sprite. Use * FilterLinear for smooth filtering and FilterNearest * if you want the texture to look sharp. */ enum D3D_Filtering { eD3D_FilterNearest, eD3D_FilterLinear }; /** * D3D_RenderStage * * D3D_RenderStage specifies the stage at which the * object should be rendered: * - StageBackground: Rendered over the background. * - StageScene: Rendered over characters and objects. * - StageGUI: Rendered over overlays and GUIs. * - StageScreen: Rendered over the mouse cursor. */ enum D3D_RenderStage { eD3D_StageBackground, eD3D_StageScene, eD3D_StageGUI, eD3D_StageScreen, }; /** * D3D_RelativeTo * * D3D_RelativeTo specifies how the coordinates of * the objects should be interpreted, as relative * to the room or to the screen. */ enum D3D_RelativeTo { eD3D_RelativeToRoom, eD3D_RelativeToScreen };
Direct3D Plugin copyright © 2012 Aki Ahonen
Contact: akiahonen [at] gmail.com, or AJA on the AGS Forums
Uses libTheoraPlayer: http://libtheoraplayer.sourceforge.net
This plugin may be used, free of charge, for any purpose, including commercial uses, provided that the following licenses are distributed with the plugin:
libOgg
------
Copyright (c) 2002, Xiph.org Foundation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
libVorbis
---------
Copyright (c) 2002-2008 Xiph.org Foundation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
libTheora
---------
Copyright (C) 2002-2009 Xiph.org Foundation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
libTheoraPlayer
---------------
Copyright (c) 2008-2010, Kresimir Spes (kreso@cateia.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.