• 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.
  • Posts

    • LibreOffice narrows gap with Microsoft Office in 25.8 Beta 1 by David Uzondu The Document Foundation has released LibreOffice 25.8 Beta 1 for public testing on Linux, macOS, and Windows. This is the second pre-release for the 25.8 cycle and the foundation says that the final, stable version of LibreOffice 25.8 is expected to land at the end of August 2025. Starting off with Writer, LibreOffice's Word, the developers have finally addressed some long-standing annoyances, including a new command to easily insert a paragraph break right before a table. This beta also introduces a useful privacy feature in its Auto-Redact tool, letting you strip all images from a document with a single option. To use it, go to Tools and select the Auto-Redact option: The application has improved its ability to handle different languages for punctuation, preventing mix-ups in multilingual documents. Other notable improvements have also been made. A new hyphenation rule lets you choose to prevent a word from splitting at the end of a page, moving the whole line to the next page instead. Microsoft Word has had this feature for years now. The Navigator now displays a handy tooltip with word and character counts for headings and their sub-outlines. Scrolling behavior when selecting text has been improved, making it less erratic. A new command with a keyboard shortcut was added for converting fields into plain text. Calc gets a lot of new functions that bring it closer to its competitors like Excel, including TEXTSPLIT, VSTACK, and WRAPROWS. Impress now properly supports embedded fonts in PPTX files, which should reduce headaches when sharing presentations with PowerPoint users. Alongside these additions, the project is also cleaning house; support for Windows 7, 8, and 8.1 has been completely dropped. There are also smaller UI tweaks across the suite, like allowing a single click to enter rotation mode for objects in Writer and Calc. macOS users get better integration, with proper support for native full screen mode and new window management features from the Sequoia update. In terms of performance, the team has optimized everything from loading huge DOC files and XLSX spreadsheets with tons of conditional formatting to simply switching between sheets in Calc. These improvements should be noticeable, especially when working with complex documents. A new application-wide "Viewer mode" has also been implemented, which opens all files in a read-only state for quick, safe viewing. On a related note, The Document Foundation has joined efforts by the likes of KDE to encourage Windows 10 users to switch to Linux. Also, you might have heard that Denmark, in a bid to lessen its reliance on Microsoft, has decided to make a full switch to LibreOffice, with plans to begin phasing out Office 365 in certain ministries as early as next month. If you're interested in this release, you can read the full release notes and download the binaries for your platform: Windows, macOS (Intel | Apple Silicon), or Linux (DEB | RPM). You can also get the latest stable version from our software stories page.
    • Until it can be used 100% offline (ie: PST file support or equiv) not even considering it. I'll jump to Thunderbird first which has gotten a LOT better since the last time I looked at it.
  • Recent Achievements

    • Explorer
      Case_f went up a rank
      Explorer
    • Conversation Starter
      Jamie Smith earned a badge
      Conversation Starter
    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      547
    2. 2
      ATLien_0
      230
    3. 3
      +FloatingFatMan
      158
    4. 4
      Michael Scrip
      114
    5. 5
      +Edouard
      111
  • Tell a friend

    Love Neowin? Tell a friend!