• 0

[C#] DirectX\SlimDX - Creating an overlay?


Question

I've been using Xfire for awhile, And found its overlays for FPS and clock useful. Now i want more information that can be displayed like that, Meaning drawing something that can be ontop of the screen always - even in fullscreen applications and games.

I've been looking at some Managed DirectX and SlimDX samples, But i'm not sure how to approach this as i have minimal graphics experience in software development.

Does anyone have any tips regarding achieving that effect?

Link to comment
https://www.neowin.net/forum/topic/642023-c-directxslimdx-creating-an-overlay/
Share on other sites

5 answers to this question

Recommended Posts

  • 0
  chaosblade said:
I've been using Xfire for awhile, And found its overlays for FPS and clock useful. Now i want more information that can be displayed like that, Meaning drawing something that can be ontop of the screen always - even in fullscreen applications and games.

I've been looking at some Managed DirectX and SlimDX samples, But i'm not sure how to approach this as i have minimal graphics experience in software development.

Does anyone have any tips regarding achieving that effect?

We're you able to find anything? I'm looking to do something similar and I cant find a whole lot.

  • 0

Bumb for great justice; So far I've tried using GDI+ (only paints on the current hdc and gets flushed each frame update making it kinda useless as it flickers), MDX and SlimDX I cant even get to create the device properly as it just spazzes with InvalidCallException.

Anyone?

  • 0

I apparently cant edit my posts so... yeah heres a post with the code im trying to use

Private Shared Sub SlimDX_DrawOverlay(ByVal OverlayString As String, ByVal DrawProcess As Process)

Dim drawHandle As System.IntPtr = Main.Handle

Dim presentParms As New SlimDX.Direct3D9.PresentParameters

presentParms.Windowed = True

presentParms.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard

presentParms.BackBufferFormat = SlimDX.Direct3D9.Format.Yuy2

Dim deviceContext As New SlimDX.Direct3D9.Device(0, SlimDX.Direct3D9.DeviceType.Hardware, drawHandle, SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, presentParms)

deviceContext.Clear(SlimDX.Direct3D9.ClearFlags.Target And SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.Transparent, 1, 0)

deviceContext.Present()

Dim OverlayBox As New Rectangle(40, 40, 300, 40)

Dim OverlayBG As New Bitmap(OverlayBox.Width, OverlayBox.Height)

For x = 0 To OverlayBG.Width - 1

For y = 0 To OverlayBG.Height - 1

OverlayBG.SetPixel(x, y, Color.Black)

Next

Next

Dim OverlayStream As IO.Stream = Nothing

OverlayBG.Save(OverlayStream, Imaging.ImageFormat.Bmp)

Dim OverlayTexture As SlimDX.Direct3D9.Texture = SlimDX.Direct3D9.Texture.FromStream(deviceContext, OverlayStream)

deviceContext.BeginScene()

' Draw here

deviceContext.EndScene()

End Sub

I realize the rest may not be right yet but it dies at Dim deviceContext so thats my concern atm. Any ideas? Also tried using Me.Handle incase it was a permission issues but same thing happens to me.

D3DERR_INVALIDCALL: Invalid call (-2005530516)

Edited by FuhrerDarqueSyde
  • 0

ok, in the end this is the code I am using

	Public drawHandle As System.IntPtr = Me.Handle
	Public presentParms As SlimDX.Direct3D9.PresentParameters
	Public deviceContext As SlimDX.Direct3D9.Device
	Dim OverlayStream As IO.Stream = IO.Stream.Null
	Public OverlayTexture As SlimDX.Direct3D9.Texture

	Public Sub InitDX()
		presentParms = New SlimDX.Direct3D9.PresentParameters
		deviceContext = New SlimDX.Direct3D9.Device(0, SlimDX.Direct3D9.DeviceType.Hardware, drawHandle, SlimDX.Direct3D9.CreateFlags.HardwareVertexProcessing, presentParms)
		presentParms.BackBufferCount = 1
		presentParms.BackBufferFormat = SlimDX.Direct3D9.Format.Unknown
		presentParms.BackBufferHeight = My.Computer.Screen.Bounds.Height
		presentParms.BackBufferWidth = My.Computer.Screen.Bounds.Width
		presentParms.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard
		presentParms.Windowed = True
		Dim OverlayBox As New Rectangle(0, 0, 300, 40)
		Dim OverlayBG As New Bitmap(OverlayBox.Width, OverlayBox.Height)
		For x = 0 To OverlayBG.Width - 1
			For y = 0 To OverlayBG.Height - 1
				OverlayBG.SetPixel(x, y, Color.Black)
			Next
		Next
		Dim byteBMP As Byte() = BitmapToStream(OverlayBG)
		OverlayStream.Read(byteBMP, 0, byteBMP.Length)
		OverlayTexture = SlimDX.Direct3D9.Texture.FromStream(deviceContext, OverlayStream)
	End Sub

	Public Sub SlimDX_DrawOverlay(ByVal OverlayString As String, ByVal DrawProcess As Process)
		deviceContext.Clear(SlimDX.Direct3D9.ClearFlags.Target And SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.Transparent, 1.0, 0)
		deviceContext.Present()
		deviceContext.BeginScene()
		deviceContext.SetTexture(0, OverlayTexture)
		deviceContext.EndScene()
		deviceContext.Present()
	End Sub

Used to draw stuff but would error out, dunno what I did but now it doesnt draw anything and throws out a...

System.IndexOutOfRangeException occurred

Message="Index was outside the bounds of the array."

Source="SlimDX"

StackTrace:

at SlimDX.Direct3D9.Texture.FromMemory(Device device, Byte[] memory, Int32 width, Int32 height, Int32 levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, Int32 colorKey) at SlimDX.Direct3D9.Texture.FromStream(Device device, Stream stream) at NTechMediaOverlay.Main.InitDX() in C:\Users\Travis\Documents\Visual Studio 2008\Projects\NTechMediaOverlay\NTechMediaOverlay\Main.vb:line 105

InnerException:

at OverlayTexture = SlimDX.Direct3D9.Texture.FromStream(deviceContext, OverlayStream)

Ideas?

Edited by FuhrerDarqueSyde
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.