Results 1 to 14 of 14

Thread: MDX, SlimDX, SharpDX Tutorials, Sample Codes, Documentations and Links - for Newbies

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    12

    MDX, SlimDX, SharpDX Tutorials, Sample Codes, Documentations and Links - for Newbies

    Although years rolled by, there is still pretty much low support for beginners on this area, especially as for VB.NET, so I've decided to start a thread here and would like to ask everyone who has stuff to share in the topic to add it here. My initial contribution to the thread is a very simple and basic SharpDX VB.NET (VS 2010) keyboard reading example, here it is:

    vb Code:
    1. Imports SharpDX.DirectInput
    2. Imports System.Windows.Forms
    3.  
    4. Module Module1
    5.  
    6. Public ApplicationWindow As New Form1
    7. Public UserQuitted As Boolean
    8.  
    9. Sub Main()
    10.  
    11. Dim SharpDXDirectInput As New DirectInput
    12. Dim SharpDXKeyboard As Object
    13. Dim SharpDXKeyboardState As KeyboardState
    14.  
    15. Dim PreviousScrollLockStatePressed As Boolean = False
    16. Dim ScrollLockStatePressed As Boolean
    17.  
    18. ApplicationWindow.Show()
    19.  
    20. SharpDXKeyboard = New Keyboard(SharpDXDirectInput)
    21. With SharpDXKeyboard
    22.  
    23. .SetCooperativeLevel _
    24. (ApplicationWindow, _
    25.  CooperativeLevel.Background Or CooperativeLevel.NonExclusive)
    26.  
    27. .Acquire()
    28. End With
    29.  
    30. Console.WriteLine("Current State of the Scroll Lock key: Released")
    31. Console.Write(StrDup(46, "-") & vbCrLf & "Press 'Q' to quit.")
    32.  
    33. Do
    34. SharpDXKeyboardState = SharpDXKeyboard.GetCurrentState()
    35. ScrollLockStatePressed = SharpDXKeyboardState.IsPressed(Key.ScrollLock)
    36.  
    37. If ScrollLockStatePressed <> PreviousScrollLockStatePressed Then
    38. Console.SetCursorPosition(38, 0)
    39.  
    40. If ScrollLockStatePressed Then
    41. Console.Write("Pressed ")
    42.  
    43. Else
    44. Console.Write("Released")
    45. End If
    46.  
    47. PreviousScrollLockStatePressed = ScrollLockStatePressed
    48. End If
    49.  
    50. Application.DoEvents()
    51. Loop Until SharpDXKeyboardState.IsPressed(Key.Q) Or UserQuitted
    52.  
    53. ApplicationWindow.Close()
    54. SharpDXKeyboard.Unacquire()
    55. End Sub
    56. End Module

    You need to dl and extract SharpDX to a local folder and compile the code above as a Console Application (VS 2010) in order to run it.

    The following .NET references are required to be added to this project :

    SharpDX.dll (SharpDXInstallFolder\Bin\Standard-net40\SharpDX.dll)

    SharpDX.DirectInput.dll (SharpDXInstallFolder\Bin\Standard-net40\SharpDX.DirectInput.dll)

    System.Windows.Forms - can be added from .NET reference list

    Additionally, you need to add a Form named Form1 to the project with the following Form code:

    vb Code:
    1. Public Class Form1
    2.  
    3. Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    4. UserQuitted = True
    5. End Sub
    6. End Class

    This code demonstrates 3 things:

    1.) Receiving keyboard input using SharpDX

    2.) Using Console Applications for test purposes (coz this example could be written as a simple Windows Application, it intentionally isn't)

    3.) Don't be scared of this "VS 2010 is for object oriented coding" thing

    The code itself does only 2 things:

    1.) Detects the state of the ScrollLock key (pressed or released) and displays it on the Console.

    2.) Quits when the user closes the appwindow (not the Console window but the Form) or presses the Q key.

    To create this simple code, I used the following:

    - SharpDX C# sample codes (only Joystick DirectInput Sample is present in the currently distributed pack)

    - "Managed DirectX 9 Kick Start: Graphics and Game Programming" - a book by Tom Miller, also in C#

    - Visual Studio 2010 Objectbrowser

    Another Initial Contribution To The Topic

    There's a small but pretty much interesting 'lil sample set for SlimDX, downloadable from here :

    http://www.ventsim.com/files/samplesvb.zip

    P.s: I know about tutorials and samples available on the official sites of SlimDX and SharpDX.
    Last edited by Visualizer; Mar 7th, 2013 at 07:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width