Ok, I actually found out why this plugin scaling broke after 3.4.0. It happened after following engine change:
https://github.com/adventuregamestudio/ags/commit/e1cc278aa38cf66de38cb2bda2e45267e0391fc4Or more precisely, Orthographic projection has changed from
(2.0 / (float)_mode.Width), 0.0, 0.0, 0.0,
0.0, (2.0 / (float)_mode.Height), 0.0, 0.0,
to
(2.0 / (float)_srcRect.GetWidth()), 0.0, 0.0, 0.0,
0.0, (2.0 / (float)_srcRect.GetHeight()), 0.0, 0.0,
Which means projection is no longer in full window resolution, but in native game resolution.
Which is questionable, considering we might want to render something outside game's frame and this projection makes that inconvenient probably (not impossible), but this was convenient for rendering at native pixel resolution mode afaik. Anyway this is what we have currently, unless this changes in the future once more...
If hardcoded fix is acceptable, all you have to do is to fix the scaling for post-3.4.0 engine is these 2 lines in D3DObject.cpp:
float screenScaleX = static_cast<float>(screen->backBufferWidth) / screen->width;
float screenScaleY = static_cast<float>(screen->backBufferHeight) / screen->height;
they should be just
float screenScaleX = 1.0;
float screenScaleY = 1.0;
because, if I understand correctly, plugin assumes it has to rescale object from native resolution to projection (which was correct with the old engine), but since now projection equals native resolution, no scale is necessary.
For non-hardcoded fix, I've been doing an experiment with passing engine matrixes into the plugin.
Unfortunately, passing through event hook arguments appeared to be too complicated as multiple changes need to be done in the engine to pass these through.
So I favor another approach: introduce new engine interface function which looks roughly like:
AGSIFUNC(void) GetRenderStageDesc(AGSRenderStageDesc* desc);
where AGSRenderStageDesc is an extendable struct which may contain all 3 engine matrixes for the current render stage (screen, room, gui, etc):
struct AGSRenderStageDesc {
// Which version of plugin the struct corresponds to;
// this field must be filled by plugin before passing the struct into engine!
int Version;
BITMAP *StageSurface;
float ProjectionMatrix[16];
float WorldMatrix[16];
float ViewMatrix[16];
};
These matrixes would be filled by each gfx renderer in their format (Direct3D and OpenGL), and thus could be used by any existing renderer and any renderer AGS might have in the future, in theory.
I'd like to try adding this new function into 3.5.1, only need to test more if it's viable to read necessary screen scaling from project matrix in the plugin itself, and if these matrixes actually let to work with custom room viewports.