michel-pi / gameoverlay.net Goto Github PK
View Code? Open in Web Editor NEWDraw hardware accelerated graphics using our Direct2D1 renderer and create transparent click-through windows.
License: MIT License
Draw hardware accelerated graphics using our Direct2D1 renderer and create transparent click-through windows.
License: MIT License
this lib seems to get the target window size automatically (OverlayCreationOptions) even if u dont specify x, y, height & width which is pretty cool cause then i dont have to make extra calls myself to get the window rect which are useless anyway cause the window size can change aswell as the position but.....
x, y, height, width & targetwindowhandle are never set when i try to call them with the Direct2DRenderer (gfx from ur example) is this intended?
kinda sucks to make extra calls in the drawing loop to get them
When I draw a image, with DrawImage the background never is transparent no matter what I do, I tried it with CreateImage from a path and from a MemoryStream, didn't try from Resources as it won't work for what I am using this
Even with your removed precompiled binaries ...
Variant with
MoveWindow(Handle, X, Y, Width, Height, false); (when moving window)
and (after creating window)
const int COLOR_MENU = 4;
int bgColor = GetSysColor(COLOR_MENU);
SetLayeredWindowAttributes(Handle, (uint)bgColor, 255, 1 | 2);
work ok, any suggestions ?
P.S. Change window class to "#32770", with your window class is impossible to fetch overlay position and dimensions ...
Ported to VS 2010 and SharpDX-SDK-2.6.3
src.zip
With the update to v4 there seem to be two option of creating the overlay:
OverlayWindow
which requires a while (true)
loop to continuously renderGraphicsWindow
which provides a DrawGraphics
event, but requires a parent window to stick toIn previous versions (3.7.8 for example), I used a FrameTimer
to set the FPS and use the event for an OverlayWindow
. Is this option (or something similar) still available in the latest version?
I would like to have an overlay over the whole desktop while being able to run other code.
There is any kind of Async, Mutlithread Drawing .?
Something like drawing in parallel
The current implementation is not very customizable and lacks the ability to scale which is required when using the same brush to draw different shapes
Is there a possibility to get clicks in the overlay area? At the moment the overlay is click trough, however if i want to implement interactions with the overlay I have to listen for clicks to change visuals, etc.
Is there a possibility to do so? I did not found anything in the documentation/example.
Hey!!
all in the title im basicly trying to create a virtual camera that i can move. but i don't know how to do this.
can someone help me please ?N
thanks
Hello,
i just wanted to use your library but i have the problem that the overlay will never be drawn above the Stronghold Crusader HD Game from firefly. Its a old Game maybe that's why.
Here my Setup, copied the example Code, for Notepad it works:
private void CreateWindow()
{
var gfx = new Graphics()
{
MeasureFPS = true,
PerPrimitiveAntiAliasing = true,
TextAntiAliasing = true,
WindowHandle = ParentWindow,
VSync = true,
};
_window = new GraphicsWindow(0, 0, 800, 600, gfx)
{
FPS = 60,
IsTopmost = true,
IsVisible = false
};
_window.SetupGraphics += _window_SetupGraphics;
_window.DestroyGraphics += _window_DestroyGraphics;
_window.DrawGraphics += _window_DrawGraphics;
_window.VisibilityChanged += Test;
_window.Create();
}
I used the WindowHandle i get from:
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public void Dummy(){
_overlay.ParentWindow = FindWindow(null, "Crusader");
}
Also i don't know how to get the Class Name for the Window initialization.
The WPF windows seem to be hidden, how do i bring them back? Thanks in advance!
Hi bro, its seems that the overlay won't work on 64bits binary. its gives a error createwindows: System.Exception: 'CreateWindowEx failed with error code: 127'
There is a weird issue related to https://github.com/michel-pi/GameOverlay.Net/blob/master/source/Drawing/Graphics.cs#L163 which is initializing SharpDX's WindowRenderTarget.
Some people may discover crashes here because we do not provide a (for their system) compatible PixelFormat.
Initially i changed the code to provide two of the (in my experience) mostly common and best supported PixelFornats for this particular use case in this library (drawing on transparent background).
One of my main problems now is that i did not hear anything from my customer after he complained about this issue. So this might be something like a Graphics Driver or a not up 2 date machine issue.
This is probably not going to be fixed before i get some information from my customer or other people with the same issue.
(There may is the possibility that i stumble across some kind of documentation of those PixelFormat's and i am going to fix this)
Hi, so I have a problem. I am writing code that makes a box appear over something, however when the object moves the box lags behind. I know this is because of the FPS but when I try changing it, it just says that its read only.
Hi,
Your Renderer and Overlay is really nice, but how to close the Overlay Window properly?
I also tried to use a normal WinForms Form and pass the Handle into the Renderer's Constructor.. that however worked pretty well. I open the Form with Show() instead of ShowDialog() and make a while loop until form.IsDisposed is called. But that however crashs with a NullReferenceException when the Renderer wants to call Finalize... There is no proper way to close right now is there?
Edit: I made a change to the Renderer... I removed the destructor, implemented IDisposable, moved the stuff that was in the destructor into Dispose() method and checking the stuff that was moved for null reference.
Now if I close the form, it calls dispose and disposes all objects as expected without crash.
There seems to be a typo at Font.WordWeapping property.
Font.WordWeapping -> Font.WordWrapping
Hi Michel. Thanks a lot for your work on this library. I really like it and it has been very helpful in different projects.
I was wondering if you'd consider the following enhancement to the library (or if you have some pointers how to accomplish this in its current state):
Extend the Graphics class with a DrawShader function that applies a custom HLSL PixelShader to the whole Screen (think ReShade) or within a specified rectangle only. This would allow to render arbitrary Shader output in the overlay or distort / adjust what you see on the screen (for example making in grayscale or inverting colors).
Here is a little mockup of the effects I'd like to achieve with the overlay
In the examples could you add an example in multithreading?
Hi,
the OverlayWindow.Dispose() never returns, which cause my application to hang before exiting. I had to implement a timeout system for it.
Either instantly or within a minute or two, my application crashes. Im using the sticky window. It only happens in release mode though, so i cant debug it.
DrawText not working
MultiThread Rendring so flashy.
i used same as here [ #48 ]
when i use normal way, no flashy and work good !!
The overlay engine generally works very well but on some specific computers, the overlay will not show over some games when the game is in full-screen mode.
It will show over the same game on most other computers and will show over the game if it is in windowed mode.
I can reproduce this issue consistently using the Lenovo Flex 2 - 15 laptop on Windows 10 running Rocket League from Steam and the sample project.
The title says all, sad its not working. Waiting for some update, this library rocks.
How can I exit and return focus back to my calling form?
Hello - the random class name generation in this class is causing ban waves.
According to the developers of various anti-cheat software this is uncommon in legitimate applications.
Hello,
I am using your nuGet package since its really easy and very cool, thanks for that.
But because I would like to use and show the overlay in a video, I would like to select the window of the overlay in the recording software, the problem is that the background is black, and because of that you can't see the game in the "back". Is there a way to make it transparent or at least green/blue screen?
https://i.imgur.com/DOHJUxU.png
https://i.imgur.com/DOHJUxU.png
Thanks for replay and maybe a good answer!
Have a good day
I am seeing Example.cs
The function SetupInstance is defining width, height, position x, position y of "overlay window".
I want to automatic find position of "MyGame.exe" to show "overlay window". Is this possible?
Thank you.
Hello,
The position of the text is incorrect when using D2Device.DrawText
.
D2Device.DrawTextWithBackground
works.
Reproduce the problem:
Set a value of X > Width / 2 or Y > Height / 2.
In Exemple.cs, add device.DrawText("FPS: " + device.FramesPerSecond, device.Width * 2 / 3, device.Height * 2 / 3, _font, _redBrush);
after device.DrawTextWithBackground("FPS: " + device.FramesPerSecond, 10, 10, _font, _redBrush, _blackBrush);
Hello,
Thanks for the great library but I have a problem using it.
I would like to capturing screenshot of the screen continuously without overlay in it But no matter what, I could not.
I tired to Clear the scene then take the shot and then draw the overlay for each frame, but overlay still shows.
Is there a way to achieve this? Can you add this functionality to this package?
By using GlyphRun
we could implement all kind of crazy text rendering stuff like mentioned in the title.
But as always the documentation on this topic is terrible and it would be great if someone actually knows a c# implementation using GlyphRun
Graphics
has a property MeasureFPS
that is set to true
in the examples. I don't really understand what this does however.
In my application scenario, I don't care about knowing the actual FPS of the Overlay, but in order to reduce the required graphics power, I would like to limit the FPS (to maybe 30).
Do I need to set it to true
or is it enough to set FPS
on the GraphicsWindow
?
What new in 4.1.0 .?
The ImageBrush
is able to be draw any kind of image (or just a part of it? and maybe scaled?) into any shape you chose.
Example: Render an image in the shape of a circle and cut of everything thats outside of it.
Am I missing something or is it not possible to set the Text alignment? it's always bound to left for me.
Thanks in advance
I originally switched to creating a new TextLayout
every time in the text rendering methods because their was a little bug (either in mine or SharpDX code) which let the renderer not draw or crash when using the DrawText method instead of the DrawTextLayout method.
I think this is no more an issue and can be changed if this provides better performance for text rendering.
Disclaimer: I assume that Direct2D just creates a TextLayout for you if you use the simpler methods.
Add to Direct2DRenderer.cs:
public void DrawBitmap(string file,float x, float y, float width, float height, float opacity)
{
_device.DrawBitmap(LoadFromFile(_device, file), new RawRectangleF(x, y, x + width, y + height), opacity, BitmapInterpolationMode.Linear);
}
public static Bitmap LoadFromFile(RenderTarget renderTarget, string file)
{
using (var bitmap = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(file))
{
var sourceArea = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
var bitmapProperties = new BitmapProperties(new SharpDX.Direct2D1.PixelFormat(Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
var size = new Size2(bitmap.Width, bitmap.Height);
int stride = bitmap.Width * sizeof(int);
using (var tempStream = new DataStream(bitmap.Height * stride, true, true))
{
var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
for (int y = 0; y < bitmap.Height; y++)
{
int offset = bitmapData.Stride * y;
for (int x = 0; x < bitmap.Width; x++)
{
byte B = Marshal.ReadByte(bitmapData.Scan0, offset++);
byte G = Marshal.ReadByte(bitmapData.Scan0, offset++);
byte R = Marshal.ReadByte(bitmapData.Scan0, offset++);
byte A = Marshal.ReadByte(bitmapData.Scan0, offset++);
int rgba = R | (G << 8) | (B << 16) | (A << 24);
tempStream.Write(rgba);
}
}
bitmap.UnlockBits(bitmapData);
tempStream.Position = 0;
return new Bitmap(renderTarget, size, tempStream, stride, bitmapProperties);
}
}
}
Usage:
Overlay.Graphics.DrawBitmap(ImagePath, X, Y, Width, Height, Opacity);
Enjoy it ;)
UPD: Sorry, confused tab
My problem is the opacity of the 2DBox
that's who i expect i will get a box with 75% opacity (I mean i can see what is behind that color with 25%)
i use something like that
// drawer is Gfx
// DraculaOrchid75 = gfx.CreateSolidBrush(System.Drawing.Color.FromArgb(255 / 100 * 75, 45, 52, 54).ToOverlayColor());
drawer.DrawBox2D(
GuiCode.DrawUtils.Electromagnetic,
GuiCode.DrawUtils.DraculaOrchid75,
Rectangle.Create(titleRect.Left, titleRect.Top, titleRect.Width, titleRect.Height - 4f),
1f);
public static GameOverlay.Drawing.Color ToOverlayColor(this System.Drawing.Color color)
{
return new GameOverlay.Drawing.Color(color.R, color.G, color.B, color.A);
}
But what i get is just the color changed, i mean it's just go darker or lighter.
i Expect some thing like black color with some opacity, to see what behind.
Does it work in Games being in full screen? .
I have tried it in a few games, and it seems that the overlay crash after sometime in game. The last 'overlay' that was draw its keeped on screen. I wish i could post any erros here, but on visual studios shows no erros, and even when i try to attach a debugger point on it, it nevers hits. Its seems like the loop inside of it its 'dead' or i don't know.
creating new ClassName() and floats int etc. inside functions which can be called in loops is forbidden to not cause memory leakage
usage of Simple DrawText in for loop 50 times using that in draw stickwindow causes 1 GB of memory usage after liek 2 minutes
GameOverlay.Drawing.Graphics.DrawText() is a function used in that example
public void DrawText(Font font, float fontSize, IBrush brush, float x, float y, string text)
{
if (!this.IsDrawing)
{
throw ThrowHelper.UseBeginScene();
}
if (text == null)
{
throw new ArgumentNullException("text");
}
if (text.Length == 0)
{
return;
}
float num = (x < 0f) ? ((float)this.Width + x) : ((float)this.Width - x);// Memory leak
float num2 = (y < 0f) ? ((float)this.Height + y) : ((float)this.Height - y);// Memory leak
if (num <= fontSize)
{
num = (float)this.Width;
}
if (num2 <= fontSize)
{
num2 = (float)this.Height;
}
TextLayout textLayout = new TextLayout(this._fontFactory, text, font.TextFormat, num, num2);// Memory leak
if (fontSize != font.FontSize)
{
textLayout.SetFontSize(fontSize, new TextRange(0, text.Length));// Memory leak
}
this._device.DrawTextLayout(new RawVector2(x, y), textLayout, brush.Brush, 2); // Memory leak
textLayout.Dispose();
}
Hi, is it possible to support Vulkan? Would it be entirely feasible? I hope so... Mabye I can help you anyway.
The sticky window example just sits there for 2 seconds and then closes the application.
Getting a System.InvalidOperationException: 'Use BeginScene before drawing anything' error.
I am trying to use multi threaded rendering.
This is my code:
Private Sub ThreadWork(ByVal gfx As Graphics)
gfx.BeginScene()
gfx.DrawText(_fonts("arial"), _brushes("red"), New Point(10, 10), "FPS: " & gfx.FPS)
gfx.EndScene()
End Sub
Private Sub _window_DrawGraphics(ByVal sender As Object, ByVal e As DrawGraphicsEventArgs)
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ThreadWork), e.Graphics)
End Sub
Am I doing something wrong or is it a bug?
Thanks for this great tool. I'm using it for a research project and I like how easy it is to create a nice overlay on my desktop.
For the next step in my project, I would like to create overlays over multiple screens (physical monitors), but I struggling to achieve that. Considering I have a main screen in the middle and one more on either side.
How would I set up the coordinates of the OverlayWindow
or should I use multiple windows?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.