Coder Social home page Coder Social logo

michel-pi / gameoverlay.net Goto Github PK

View Code? Open in Web Editor NEW
420.0 22.0 83.0 6.04 MB

Draw hardware accelerated graphics using our Direct2D1 renderer and create transparent click-through windows.

License: MIT License

C# 99.98% Batchfile 0.02%
sharpdx csharp graphics direct2d1-drawing-library transparent-windows direct2d1 overlay overlay-window

gameoverlay.net's People

Contributors

aliakbo avatar hirse avatar michel-pi avatar mrvarens avatar yatodev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gameoverlay.net's Issues

Anti-aliasing

Hi,

Is the "anti-aliasing" option really working ?
I'm drawing players bones and, it doesn't seems to be "corrected".

this.Device           = new D2DDevice(new DeviceOptions()
{
	AntiAliasing  = true,
	Hwnd          = this.Window.WindowHandle,
	MeasureFps    = true,
	MultiThreaded = false,
	VSync         = false
});

image

variables not beeing set

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

DrawImage Transparency Problem

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

Not work on win 7 x64 ...

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

OverlayWindow without infinite loop in v4

With the update to v4 there seem to be two option of creating the overlay:

  1. The OverlayWindow which requires a while (true) loop to continuously render
  2. The GraphicsWindow which provides a DrawGraphics event, but requires a parent window to stick to

In 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.

AsyncDrawing

There is any kind of Async, Mutlithread Drawing .?

Something like drawing in parallel

Listen for clicks

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.

Camera rotation ?

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

Overlay dont work with Game Stronghold Crusader

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.

Picture not ingame:
image

Ingame:
image

Not working on 64bits binary!

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'

Initializing the Graphics renderer PixelFormat on weird machines

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)

Set FPS

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.

How to close properly

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.

Applying custom HLSL PixelShaders

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

overlay_shaders

  • red rectangle: Invert the colors of what's seen below the overlay
  • blue rectangle: adjust the colors of what's seen below the overlay to grayscale
  • green rectangle: render some pixel shader (example taken from https://www.shadertoy.com/view/MdSXzz) and do some kind of alpha blending with what's seen below the overlay

Multithreading

In the examples could you add an example in multithreading?

OverlayWindow thread issue

Hi,

the OverlayWindow.Dispose() never returns, which cause my application to hang before exiting. I had to implement a timeout system for it.

Does not work on release mode.

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.

Overlay will not show over some full-screen games on specific computers

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.

Make Overlay transparent? Or Greenscreen

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

How to attach overlay into game screen?

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.

Bad position of text using D2Device.DrawText

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);

Excepted result:
drawtext bug

Taking screenshot without overlay.

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?

Understanding Graphics.MeasureFPS

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?

Adding the Direct2D ImageBrush

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.

Drawing Image Make it looks darker

Drawing Image Make it looks darker
That's image, when i try to draw it, is's go darker!

So what the problem !!

drawer.CreateImage("Path to image");

Helmet-lvl-3

Text rendering performance

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.

[Suggestion] DrawBitmap

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);

Screenshots

Enjoy it ;)

UPD: Sorry, confused tab

Draw Opacity Problem

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.

Overlay crash /stop?

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.

Huge Memory Leakage

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();
}

Vulkan support

Hi, is it possible to support Vulkan? Would it be entirely feasible? I hope so... Mabye I can help you anyway.

Use BeginScene before drawing anything

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?

Multi-Screen setup

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.