Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: **Aincrad** en 3 Octubre 2018, 17:18 pm



Título: [Ayuda] Agrego el paquete NuGet "SharpDX" pero me da error.
Publicado por: **Aincrad** en 3 Octubre 2018, 17:18 pm
En internet encontré  el sig código : 


Clase : "SharpDXRenderer"

Código
  1. Imports System
  2. Imports System.Windows.Forms
  3. Imports SharpDX
  4. Imports SharpDX.DXGI
  5. Imports SharpDX.Direct3D
  6. Imports SharpDX.Direct3D11
  7. Imports SharpDX.Direct2D1
  8. Imports SharpDX.Windows
  9. Imports SharpDX.Mathematics
  10. Imports Device = SharpDX.Direct3D11.Device
  11. Imports FactoryD2D = SharpDX.Direct2D1.Factory
  12. Imports FactoryDXGI = SharpDX.DXGI.Factory1
  13.  
  14.  
  15. Public Class SharpDXRenderer
  16.  
  17. #Region "Properties"
  18.  
  19. Private _showFPS As Boolean = False
  20. Public Property ShowFPS() As Boolean
  21. Get
  22. Return _showFPS
  23. End Get
  24. Set(ByVal value As Boolean)
  25. _showFPS = value
  26. End Set
  27. End Property
  28.  
  29. Private _renderWindow As New RenderForm
  30. Public Property RenderWindow As RenderForm
  31. Get
  32. Return _renderWindow
  33. End Get
  34. Set(value As RenderForm)
  35. _renderWindow = value
  36. End Set
  37. End Property
  38.  
  39. Private _renderWindowTitle As String = ""
  40. Public Property RenderWindowTitle As Integer
  41. Get
  42. Return Nothing
  43. End Get
  44. Set(value As Integer)
  45. End Set
  46. End Property
  47.  
  48. Private _renderWindowWidth As Integer = 800
  49. Public Property RenderWindowWidth() As String
  50. Get
  51. Return _renderWindowWidth
  52. End Get
  53. Set(ByVal value As String)
  54. _renderWindowWidth = value
  55. End Set
  56. End Property
  57.  
  58. Private _renderWindowHeight As Integer = 600
  59. Public Property RenderWindowHeight() As Integer
  60. Get
  61. Return _renderWindowHeight
  62. End Get
  63. Set(ByVal value As Integer)
  64. _renderWindowHeight = value
  65. End Set
  66. End Property
  67.  
  68. Private _isWindowed As Boolean = True
  69. Public Property IsWindowed() As Boolean
  70. Get
  71. Return _isWindowed
  72. End Get
  73. Set(ByVal value As Boolean)
  74. _isWindowed = value
  75. End Set
  76. End Property
  77.  
  78. Private _refreshRate As Integer = 60
  79. Public Property RefreshRate() As Integer
  80. Get
  81. Return _refreshRate
  82. End Get
  83. Set(ByVal value As Integer)
  84. _refreshRate = value
  85. End Set
  86. End Property
  87.  
  88. #End Region
  89.  
  90. ' **** Operational class level vars
  91. Dim device As Device
  92. Dim swapChain As SwapChain
  93. Dim renderTarget As RenderTarget
  94.  
  95.  
  96. Public Sub New()
  97.  
  98. 'nuttin atm
  99.  
  100. End Sub
  101.  
  102. Public Sub Initialize()
  103.  
  104. ' Create render target window
  105. _renderWindow.Text = _renderWindowTitle
  106.  
  107. ' Create swap chain description
  108. Dim swapChainDesc = New SwapChainDescription() With {
  109. .BufferCount = 2,
  110. .Usage = Usage.RenderTargetOutput,
  111. .OutputHandle = _renderWindow.Handle,
  112. .IsWindowed = _isWindowed,
  113. .ModeDescription = New ModeDescription(0, 0, New Rational(_refreshRate, 1), Format.R8G8B8A8_UNorm),
  114. .SampleDescription = New SampleDescription(1, 0),
  115. .Flags = SwapChainFlags.AllowModeSwitch,
  116. .SwapEffect = SwapEffect.Discard
  117. }
  118.  
  119. ' Create swap chain And Direct3D device
  120. ' The BgraSupport flag Is needed for Direct2D compatibility otherwise RenderTarget.FromDXGI will fail!
  121. Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, device, swapChain)
  122.  
  123. ' Get back buffer in a Direct2D-compatible format (DXGI surface)
  124. Dim backBuffer As Surface = Surface.FromSwapChain(swapChain, 0)
  125.  
  126. 'Create Direct2D factory
  127. Using factory = New FactoryD2D()
  128. 'Get desktop DPI
  129. Dim dpi = factory.DesktopDpi
  130. 'Create bitmap render target from DXGI surface
  131. renderTarget = New RenderTarget(factory, backBuffer, New RenderTargetProperties() With {
  132. .DpiX = dpi.Width,
  133. .DpiY = dpi.Height,
  134. .MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT,
  135. .PixelFormat = New PixelFormat(Format.Unknown, Direct2D1.AlphaMode.Ignore),
  136. .Type = RenderTargetType.[Default],
  137. .Usage = RenderTargetUsage.None
  138. })
  139. End Using
  140.  
  141. 'Disable automatic ALT+Enter processing because it doesn't work properly with WinForms
  142. Using factory = swapChain.GetParent(Of FactoryDXGI)()
  143. factory.MakeWindowAssociation(_renderWindow.Handle, WindowAssociationFlags.IgnoreAltEnter)
  144. End Using
  145.  
  146. ' Add event handler for ALT+Enter
  147. AddHandler _renderWindow.KeyDown, Sub(o, e)
  148.  If e.Alt AndAlso e.KeyCode = Keys.Enter Then
  149.  swapChain.IsFullScreen = Not swapChain.IsFullScreen
  150.  End If
  151.  End Sub
  152.  
  153. ' Set window size
  154. _renderWindow.Size = New System.Drawing.Size(_renderWindowWidth, _renderWindowHeight)
  155.  
  156. ' Prevent window from being re-sized
  157. _renderWindow.AutoSizeMode = AutoSizeMode.GrowAndShrink
  158.  
  159. End Sub
  160.  
  161. Public Sub RunRenderLoop()
  162.  
  163. Dim clock = New System.Diagnostics.Stopwatch()
  164. Dim clockFrequency = CDbl(System.Diagnostics.Stopwatch.Frequency)
  165. clock.Start()
  166. Dim deltaTime = 0.0
  167. Dim fpsTimer = New System.Diagnostics.Stopwatch()
  168. fpsTimer.Start()
  169. Dim fps = 0.0
  170. Dim fpsFrames As Integer = 0
  171.  
  172. RenderLoop.Run(_renderWindow, Function()
  173.  renderTarget.BeginDraw()
  174.  renderTarget.Transform = Matrix3x2.Identity
  175.  renderTarget.Clear(Color.DarkBlue)
  176.  
  177.  ' FPS display
  178.  Dim totalSeconds = clock.ElapsedTicks / clockFrequency
  179.  fpsFrames += 1
  180.  If fpsTimer.ElapsedMilliseconds > 1000 Then
  181.  fps = 1000 * fpsFrames / fpsTimer.ElapsedMilliseconds
  182.  If _showFPS Then
  183.  ' Update window title with FPS once every second
  184.  _renderWindow.Text = String.Format("D3DRendering D3D11.1 - FPS: {0:F2} ({1:F2}ms/frame)", fps, CSng(fpsTimer.ElapsedMilliseconds) / fpsFrames)
  185.  End If
  186.  ' Restart the FPS counter
  187.  fpsTimer.Reset()
  188.  fpsTimer.Start()
  189.  fpsFrames = 0
  190.  End If
  191.  
  192.  'Draw the frame
  193.  DrawFrame(renderTarget)
  194.  
  195.  renderTarget.EndDraw()
  196.  
  197.  swapChain.Present(0, PresentFlags.None)
  198.  
  199.  ' Determine the time it took to render the frame
  200.  deltaTime = (clock.ElapsedTicks / clockFrequency) - totalSeconds
  201.  
  202.  End Function)
  203.  
  204. renderTarget.Dispose()
  205. swapChain.Dispose()
  206. device.Dispose()
  207.  
  208. End Sub
  209.  
  210. Private Function DrawFrame(renderTarget As RenderTarget) As RenderTarget
  211.  
  212. renderTarget.DrawRectangle(New RectangleF(renderTarget.Size.Width / 2 - (Form1.WidthTB.Value / 2),
  213.  renderTarget.Size.Height / 2 - (Form1.HeightTB.Value / 2),
  214.  Form1.WidthTB.Value,
  215.  Form1.HeightTB.Value), New SolidColorBrush(renderTarget, Color.CornflowerBlue))
  216.  
  217. Return renderTarget
  218.  
  219. End Function
  220.  
  221. End Class



Bueno entonces abro mi VS he instalo la referencia de SharpDX . pero como verán me sale esto:

(https://image.ibb.co/naQyMz/781fe2601d6b6f4d385a3d44f4a4fdf3_icon.png)

Entonces intento buscar por ejemplo la referencia que me sale que no tengo , por ejemplo : "SharpDX.Direct2D1" y me dice que ya tengo esa referencia en SharpDX que agregue, pero entonce por que me sale como si no la tuviera?

(https://image.ibb.co/iE041p/781fe2601d6b6f4d385a3d44f4a4fdf3_icon.png)


Gracias de Antemano!




Título: Re: [Ayuda] Agrego el paquete NuGet "SharpDX" pero me da error.
Publicado por: Eleкtro en 3 Octubre 2018, 21:41 pm
Veo dos problemas en las imágenes que has mostrado. No se si has utilizado el comando Install-Package en la consola NuGet para instalar una versión específica de SharpDX, puesto que no te has instalado la versión más reciente de las librerías de SharpDx, ese sería el primer problema, y, aparte de esto, también te has instalado la librería "Cauldron.SharpDx", la cual no forma parte de SharpDx y no la necesitas para nada.

La razón para el problema relacionado con las dependencias podría ser debido a:

  • https://stackoverflow.com/questions/25725545/nuget-x-already-has-a-dependency-defined-for-y

Cita de: https://stackoverflow.com/a/47871096/1248295
Root reason for the error in this and similar situations is in dependencies of the package you try to install, which are not compatible with .NET version available in your project.

Universal solution is not obligatory update of Visual Studio or .NET but in installation of older NuGet versions of the same package compatible with your system.

It is not possible to tell for sure, which of earlier versions will work.

Creo que ya te comenté en una ocasión que quedarse desfasado en la versión de la IDE, o en la versión disponible de .NET Framework solo es algo que a la larga causará problemas sobre todo siendo programador de .NET. Las librerías más actuales de SharpDX requieren de .NET Framework 4.0+.



Las siguientes imágenes son de Visual Studio 2017, desinstala todos los paquetes NuGet que hayas instalado y vuelve a realizar el procedimiento desde cero...

(https://i.imgur.com/GyZ6lOe.png)

Teniendo en cuenta los namespaces importados en el código fuente que has mostrado, estos son los nombres de las librerías que debes instalar:

(https://i.imgur.com/JSi3wTh.png)

Saludos


Título: Re: [Ayuda] Agrego el paquete NuGet "SharpDX" pero me da error.
Publicado por: **Aincrad** en 3 Octubre 2018, 22:05 pm
Tengo VS 2012 ya q mi pc es kk

me voy a :


(https://image.ibb.co/fJoKTe/DF5.png)

Y solo tengo instalado el paquete SharpDX la mas nueva versión.


(https://image.ibb.co/i2kNgz/781fe2601d6b6f4d385a3d44f4a4fdf3_icon.png)

Ya verifique y si lo tengo instalado, bueno voy hacer todos desde 0 con un nuevo proyecto y te aviso.


Título: Re: [Ayuda] Agrego el paquete NuGet "SharpDX" pero me da error.
Publicado por: **Aincrad** en 3 Octubre 2018, 22:19 pm
Instale por medio de la consola en una nueva solucion . me agarro el paquete "SharpDX" , "SharpDX.Mathematics" y "SharpDX.Desktop" pero con los demás paquetes me sale lo mismo:

(https://image.ibb.co/dM1QZK/DF5.png)

Alguna Idea? Gracias de antemano