Comments (10)
If you want to use 3D geometry you could disable depth test, draw a screen-aligned rectangle and provide the coords in device coordinates.
If you want to do this using images, you can draw a sprite.
from direct3dhook.
Thanks! Could you maybe provide some existing code in your library or perhaps a link on the web somewhere that unpacks what you said, as Im not versed in this world?
from direct3dhook.
Yeah I'll try to dig some things up for you
from direct3dhook.
For the sprite using something like (just make sure you don't instantiate the sprite and texture every frame or you will suffer some crap performance):
//use relative path
string dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filename = dir + @"\image.bmp";
// Get image dimensions
using (var img = Image.FromFile(filename))
{
imageSize = img.Size;
}
imageWidth = imageSize.Width;
var _mytext = SharpDX.Direct3D9.Texture.FromFile(device, filename);
var _sprite = new SharpDX.Direct3D9.Sprite(device);
float alertPosLeft = (device.Viewport.Width - imageSize.Width) / 2;
float alertPosTop = (device.Viewport.Height - imageSize.Height) / 2;
var pos = new SharpDX.Vector3(alertPosLeft, alertPosTop, 0);
var color = new SharpDX.ColorBGRA(0xffffffff);
_sprite.Begin(SharpDX.Direct3D9.SpriteFlags.AlphaBlend);
_sprite.Draw(_myText, color, null, null, pos);
_sprite.End();
from direct3dhook.
Great stuff! It works mostly, except the image is not in the center vertically - see attached screenshot where the device resolution is 2160x1440 and the image resolution is 1024x768. There seems to be some stretching or squeezing involved because the non-square source image looks like a square to me on the screenshot?
from direct3dhook.
You can control the scale/rotation of the sprite by setting the sprite's transform.
// set scale of 0.5
sprite.Transform = SharpDX.Matrix.AffineTransformation2D(0.5f, 0f, SharpDX.Vector2.Zero);
from direct3dhook.
the problem is not scaling as such but the observation that the image is stretched vertically. i have now attached the source image as well, which is width 1024 and height 768 i.e. it is not a square, it is not 1024x1024 and it is not 768x768. but if you look at the screenshot on my previous post here, you can see the image is a square i.e. it has been stretched downwards (and as a result is not in the centre of the screen as it should be)
i did some logging and i also used photoshop to measure the top and left positions, and they themselves are correct:
DXHookD3D9: Left 568 top 336 image width 1024 height 768 device width 2160 height 1440
so indeed the image get stretched vertically for some reason with your code?
This is the (non-stretched) source image:
from direct3dhook.
The texture is likely loading as a Square / pow2 (or both):
You can transform the width/height to get the correct aspect ratio as follows:
var transform = SharpDX.Matrix.AffineTransformation2D(1f, 0f, Vector2.Zero);
// Calculate width scale
if (imageSize.Width <= 128)
{
transform.M11 = (float)imageSize.Width / 128f; // scale x
}
else if (imageSize.Width <= 256)
{
transform.M11 = (float)imageSize.Width / 256f; // scale x
}
else if (imageSize.Width <= 512)
{
transform.M11 = (float)imageSize.Width / 512f; // scale x
}
else if (imageSize.Width <= 1024)
{
transform.M11 = (float)imageSize.Width / 1024f; // scale x
}
// Calculate height scale
if (imageSize.Height <= 128)
{
transform.M22 = (float)imageSize.Height / 128f; // scale y
}
else if (imageSize.Height <= 256)
{
transform.M22 = (float)imageSize.Height / 256f; // scale y
}
else if (imageSize.Height <= 512)
{
transform.M22 = (float)imageSize.Height / 512f; // scale y
}
else if (imageSize.Height <= 1024)
{
transform.M22 = (float)imageSize.Height / 1024f; // scale y
}
_sprite.Transform = transform;
from direct3dhook.
Another option, if the device capabilities support it, is to provide the size of the texture when you load it, e.g.
var _myText = SharpDX.Direct3D9.Texture.FromFile(device, filename, imageSize.Width, imageSize.Height, 0, Usage.None, Format.A8B8G8R8, Pool.Default, Filter.Default, Filter.Default, 0);
from direct3dhook.
i tried the second option on one device and it worked perfekto. not sure what device capabilities are needed, but hoping this approach would work on most devices.
thanks again!
from direct3dhook.
Related Issues (20)
- Attempt to update image element every frame in d3d11? HOT 4
- Memory leak in hooked application HOT 7
- Question: Interactive UI Overlay HOT 2
- Strange exception HOT 1
- Failed injection in League of Legends HOT 9
- Error in InitialiseHook: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. HOT 1
- can I use this for simulate dirext input for games?
- Сhange of path *.dll
- cann't inject wow,error code:93913088 HOT 1
- Screenshot background window HOT 3
- Black screen when capturing from multiple clients HOT 8
- Captures Complete but Do Not Display, Overlay Does Not Display
- Region settings not correct. HOT 1
- Memory leak on screenshot HOT 5
- Memory leak on image draw HOT 2
- I need some help HOT 31
- Memory leak after unreasonable ammount of DrawOverlayInGame calls and large ImageElement HOT 7
- When creating an ImageElement with the "Bitmap bitmap" override, DXHookD3D11 throws an exception HOT 1
- What is CaptureInterface.StartRecording()? HOT 1
- Memory leakage HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from direct3dhook.