DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
Go Back  Xtreme Visual Basic Talk > > > > DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET


Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2004, 08:10 PM
MobySlick MobySlick is offline
Newcomer
 
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 23
Default DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET


Hi folks, new member here and also new to DirectX programming, but I am an experienced programmer. I have only done a couple apps in VB.NET so I'm thinking I might be missing something simple. I can't believe the SDK only provides C# examples, poo on MS :P

Anyway I am trying to get the included "Tutorial 1" working which just creates a Direct3D Device filling the form client area and clears it to blue color. It works fine in C#, but when I try to mimic the code in a VB.NET program I just get a blank form. No errors, but no blueness either If someone can give me a tip, I'd appreciate it. Source code follows. It's really not that long (3 subs), take a look. Thanks

----

Public Class Form1
Inherits System.Windows.Forms.Form

Private D As Microsoft.DirectX.Direct3D.Device

#Region " Windows Form Designer generated code "
// nut'n worth listing in here
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not InitGFX() Then
MessageBox.Show("Could not initialize Direct3D")
End
End If
End Sub

Private Function InitGFX() As Boolean
Dim pp As New Microsoft.DirectX.Direct3D.PresentParameters

Try
pp.Windowed = True
pp.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard
D = New Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me, Microsoft.DirectX.Direct3D.CreateFlags.HardwareVertexProcessing, pp)
InitGFX = True
Catch ex As Microsoft.DirectX.DirectXException
InitGFX = False
End Try
End Function

Private Sub Form1_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.VisibleChanged
D.Clear(Microsoft.DirectX.Direct3D.ClearFlags.Target, System.Drawing.Color.Blue, 1, 0)
D.BeginScene()
D.EndScene()
D.Present()
End Sub
End Class

-----

Answers to things you might be wondering:
Yes, I did include project references to Microsoft.DirectX and Microsoft.DirectX.Direct3D.
Yes, the VisibleChanged event is firing.
Reply With Quote
  #2  
Old 08-11-2004, 08:54 PM
MobySlick MobySlick is offline
Newcomer
 
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 23
Default

Well it turns out I can answer my own question, but I don't know the reasons behind it. If I change the project startup to Sub Main instead of the form, and move things around so that Main creates an instance of the form and calls the other two subs, it works. Can anyone explain why?
Reply With Quote
  #3  
Old 08-30-2004, 11:42 AM
Knight Chat X Knight Chat X is offline
Freshman
 
Join Date: Oct 2003
Posts: 41
Cool

The code should work in either Main or Sub Main startup mode depending on how you have your form setup.

Try putting your scene render code block in the form's paint event, that way it remains updated, see if that fixes it:

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

D.Clear(Microsoft.DirectX.Direct3D.ClearFlags.Target, System.Drawing.Color.Blue, 1, 0)
D.BeginScene()
D.EndScene()
D.Present()

End Sub
Reply With Quote
  #4  
Old 03-17-2005, 01:14 PM
NGN_VBdotNET NGN_VBdotNET is offline
Newcomer
 
Join Date: Mar 2005
Posts: 6
Default Little late? Maybe?

I will try to change the following code from:
"D = New Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me, Microsoft.DirectX.Direct3D.CreateFlags.HardwareVertexProcessing, pp)
"
to:
"D = New Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me.Handle, Microsoft.DirectX.Direct3D.CreateFlags.HardwareVertexProcessing, pp)
"

Try that.

Good Luck!

NGN
Sweden
Reply With Quote
  #5  
Old 03-18-2005, 01:08 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Quote:
Originally Posted by MobySlick
Hi folks, new member here and also new to DirectX programming, but I am an experienced programmer. I have only done a couple apps in VB.NET so I'm thinking I might be missing something simple. I can't believe the SDK only provides C# examples, poo on MS :P

Anyway I am trying to get the included "Tutorial 1" working which just creates a Direct3D Device filling the form client area and clears it to blue color. It works fine in C#, but when I try to mimic the code in a VB.NET program I just get a blank form. No errors, but no blueness either If someone can give me a tip, I'd appreciate it. Source code follows. It's really not that long (3 subs), take a look. Thanks

----

Public Class Form1
Inherits System.Windows.Forms.Form

Private D As Microsoft.DirectX.Direct3D.Device

#Region " Windows Form Designer generated code "
// nut'n worth listing in here
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not InitGFX() Then
MessageBox.Show("Could not initialize Direct3D")
End
End If
End Sub

Private Function InitGFX() As Boolean
Dim pp As New Microsoft.DirectX.Direct3D.PresentParameters

Try
pp.Windowed = True
pp.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard
D = New Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me, Microsoft.DirectX.Direct3D.CreateFlags.HardwareVertexProcessing, pp)
InitGFX = True
Catch ex As Microsoft.DirectX.DirectXException
InitGFX = False
End Try
End Function

Private Sub Form1_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.VisibleChanged
D.Clear(Microsoft.DirectX.Direct3D.ClearFlags.Target, System.Drawing.Color.Blue, 1, 0)
D.BeginScene()
D.EndScene()
D.Present()
End Sub
End Class

-----

Answers to things you might be wondering:
Yes, I did include project references to Microsoft.DirectX and Microsoft.DirectX.Direct3D.
Yes, the VisibleChanged event is firing.
Ok, two things that I've noticed that are wrong. Firstly, in your Form1_Load procedure, you need to do Me.Show before you initialise any DirectX stuff. Also, the second is, in your VisibleChanged procedure you need to include Application.DoEvents and this will then work. If you need an example of a simple D3D Windowed mode DX9 VB.NET source code, get back to me and I'll be happy to mail it across.
__________________
Cheers
Reply With Quote
  #6  
Old 03-18-2005, 06:51 AM
NGN_VBdotNET NGN_VBdotNET is offline
Newcomer
 
Join Date: Mar 2005
Posts: 6
Default

I have a question, at the end.

Here is My proposal in the issue "smallest code":

---------------------------------------------------
Imports Microsoft.directx.Direct3D
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
// nut'n worth listing in here
#End Region
Private D As Device
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pp As New PresentParameters
Try
pp.Windowed = True
pp.SwapEffect = SwapEffect.Discard
D = New Device(0, DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, pp)
Catch ex As Microsoft.directx.DirectXException
MsgBox("Could not initialize Direct3D")
End
End Try
Me.Show()
D.Clear(ClearFlags.Target, Color.Blue, 1, 0)
D.BeginScene()
D.EndScene()
D.Present()
Application.DoEvents()
End Sub
End Class
---------------------------------------------------


Of course You can skip the 'Try...Catch...End Try' and the code between 'Catch' and 'End Try'. But there is always nice to catch the errors.


The 'New Device' defenitions. There is two to choose beteween, in this case:

1)
New Device(
adapter As Integer,
deviceType As Microsoft.DirectX.Direct3D.DiveceType,
renderWindowHandle As System.IntPtr,
behaviorFlags As Microsoft.DirectX.Direct3D.CreateFlags,
ParamArray presentationParameters() As Microsoft.DirectX.Direct3D.PresentParameters
)

2)
New Device(
adapter As Integer,
deviceType As Microsoft.DirectX.Direct3D.DiveceType,
renderWindo As System.Windows.Forms.Control
behaviorFlags As Microsoft.DirectX.Direct3D.CreateFlags,
ParamArray presentationParameters() As Microsoft.DirectX.Direct3D.PresentParameters
)

Can someone explain the differnce? And which to preffer? I allways pic 1), but I don't know why? Apart from this "smallest code" proposal.

NGN
Sweden
Reply With Quote
  #7  
Old 05-10-2005, 03:02 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default Graphics Adapter Information

Hey all you seem to know what your all on about concerning DirectX9

Can you tell me how to gather data regarding Graphics Card E.G.

Manufacturer
Model
ram
etc..

thanks

James Bowtell
Reply With Quote
  #8  
Old 05-10-2005, 04:15 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

That depends if you are using Managed Code?

If you are then use the Manager properties to get the necessary information. If you need code let us know.
__________________
Cheers
Reply With Quote
  #9  
Old 05-10-2005, 04:23 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

Quote:
Originally Posted by ardman
That depends if you are using Managed Code?

If you are then use the Manager properties to get the necessary information. If you need code let us know.
At the moment i have a class that collects all the system information e.g.

Computer Name As String
Manufacturer As String
Model
OS Name
OS Version
SystemType As String
Total Physical Memory
Windows Dir

using the 'System.Management'

But trying to extract the Graphics card details i'm stuck any chance you can help?
Reply With Quote
  #10  
Old 05-10-2005, 04:26 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default Graphics Card Details!!!

At the moment i have a class that collects all the system information e.g.

Computer Name
Manufacturer
Model
OS Name
OS Version
System Type
Total Physical Memory
Windows Dir

using the 'System.Management'

But trying to extract the Graphics card details i'm stuck any chance you can help?

Details such as

Manufacturer
Model
ram
etc..

Thanks

James Bowtell
Reply With Quote
  #11  
Old 05-10-2005, 04:35 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Here's my enumeration:
Code:
            Dim Caps As Direct3D.Caps
            m_LynxD3D.Log("ADAPTERINFO: (")
            Caps = Direct3D.Manager.GetDeviceCaps(0, Direct3D.DeviceType.Hardware)
            ' Check for Hardware Transform and Light support
            If pCaps.SupportsHardwareTransformAndLight Then
                m_LynxD3D.Log("   adapter features Hardware TnL")
                cboDeviceType.Items.Add("Hardware Acceleration (HAL)")
                cboDeviceType.Items.Add("Software Rasterizer (REF)")
                cboDeviceType.SelectedIndex = 0
                ' Check for Pure Device capability
                If pCaps.SupportsPureDevice Then
                    m_LynxD3D.Log("   (pure device possible)")
                Else
                    m_LynxD3D.Log("   (pure device not possible)")
                End If
            End If
            If Err.Number = 0 Then
                m_LynxD3D.Log("   adapter features Hardware Rasterization")
                cboDeviceType.Items.Add("Hardware Acceleration (HAL)")
                cboDeviceType.Items.Add("Reference Rasterizer (REF)")
                cboDeviceType.SelectedIndex = 0
            Else
                m_LynxD3D.Log("(  Adapter only features Software TnL")
                cboDeviceType.Items.Add("Reference Rasterizer (REF)")
                cboDeviceType.SelectedIndex = 0
            End If
            ' Vertex shader version
            If (Caps.VertexShaderVersion.Major & "." & Caps.VertexShaderVersion.Minor) <= "1.1" Then
                m_LynxD3D.Log("   Vertex Shader Version 1.0")
            ElseIf (Caps.VertexShaderVersion.Major & "." & Caps.VertexShaderVersion.Minor) <= "2.0" Then
                m_LynxD3D.Log("   Vertex Shader Version 1.1")
            Else
                m_LynxD3D.Log("   Vertex Shader Version 2.0 or better")
            End If
            ' Pixel shader version
            If (Caps.PixelShaderVersion.Major & "." & Caps.PixelShaderVersion.Minor) <= "1.1" Then
                m_LynxD3D.Log("   Pixel Shader Version 1.0 ")
            ElseIf (Caps.PixelShaderVersion.Major & "." & Caps.PixelShaderVersion.Minor) <= "1.2" Then
                m_LynxD3D.Log("   Pixel Shader Version 1.1")
            ElseIf (Caps.PixelShaderVersion.Major & "." & Caps.PixelShaderVersion.Minor) <= "1.3" Then
                m_LynxD3D.Log("   Pixel Shader Version 1.2")
            ElseIf (Caps.PixelShaderVersion.Major & "." & Caps.PixelShaderVersion.Minor) <= "1.4" Then
                m_LynxD3D.Log("   Pixel Shader Version 1.3")
            ElseIf (Caps.PixelShaderVersion.Major & "." & Caps.PixelShaderVersion.Minor) <= "2.0" Then
                m_LynxD3D.Log("   Pixel Shader Version 1.4")
            Else
                m_LynxD3D.Log("   Pixel Shader Version 2.0 or better")
            End If
            m_LynxD3D.Log("   )   ENDINFO")
m_lynxd3d is my main dll but everything else should be ok. I can extend into Screen resolutions if needed?
__________________
Cheers
Reply With Quote
  #12  
Old 05-10-2005, 05:16 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

WoW what the hell....lol

Looking at that code just shocks me!! can you explain it to me for better understanding? but for some reason i don't think it extract what i need!
Reply With Quote
  #13  
Old 05-10-2005, 05:19 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Ok, I've stripped a lot of stuff out of the code to make it easier:
Code:
Dim Caps As Direct3D.Caps
            ' Get the device capabilities
            Caps = Direct3D.Manager.GetDeviceCaps(0, Direct3D.DeviceType.Hardware)
            If Err.Number = 0 Then
                cboDeviceType.Items.Add("Hardware Acceleration (HAL)")
                cboDeviceType.Items.Add("Reference Rasterizer (REF)")
                cboDeviceType.SelectedIndex = 0
            Else
                cboDeviceType.Items.Add("Reference Rasterizer (REF)")
                cboDeviceType.SelectedIndex = 0
            End If
The cboDeviceType is a combo box on the form I have. Just lets me select whether to use hardware or software rendering. Is this clearer?
__________________
Cheers
Reply With Quote
  #14  
Old 05-10-2005, 05:42 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

Yes much clear thanks.... but doesn't really help with what i need.

What i'm looking for is somthing to extract information related to a graphics card such as

Manufacturer
Model
Memory
etc

i heard you can do this with DirectX

thanks
Reply With Quote
  #15  
Old 05-10-2005, 05:45 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

No problems:

Code:
            Dim adapter As Direct3D.AdapterInformation = Direct3D.Manager.Adapters(0)
            Dim resolution As Direct3D.DisplayModeEnumerator
            Dim mode As Direct3D.DisplayMode
            ' HERE IS THE GRAPHICS CARD NAME
            cboAdapter.Items.Add(adapter.Information.Description)
            ' Set the resolutions
            resolution = adapter.SupportedDisplayModes()
            ' Display the supported resolutions
            Dim i As Integer
            For i = 0 To resolution.Count
                resolution.MoveNext()
                mode = resolution.Current
                cboModes.Items.Add(mode.Width & "x" & mode.Height & " FMT: " & mode.Format)
            Next
__________________
Cheers
Reply With Quote
  #16  
Old 05-10-2005, 05:56 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

Quote:
Originally Posted by ardman
No problems:

Code:
            Dim adapter As Direct3D.AdapterInformation = Direct3D.Manager.Adapters(0)
            Dim resolution As Direct3D.DisplayModeEnumerator
            Dim mode As Direct3D.DisplayMode
            ' HERE IS THE GRAPHICS CARD NAME
            cboAdapter.Items.Add(adapter.Information.Description)
            ' Set the resolutions
            resolution = adapter.SupportedDisplayModes()
            ' Display the supported resolutions
            Dim i As Integer
            For i = 0 To resolution.Count
                resolution.MoveNext()
                mode = resolution.Current
                cboModes.Items.Add(mode.Width & "x" & mode.Height & " FMT: " & mode.Format)
            Next

do i have to import anything like

Imports Microsoft.DirectX.Management.Adapters
Reply With Quote
  #17  
Old 05-10-2005, 05:56 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

You might want to import:

Imports Microsoft.DirectX.Direct3D

Its part of that.
__________________
Cheers
Reply With Quote
  #18  
Old 05-10-2005, 06:01 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

Quote:
Originally Posted by ardman
You might want to import:

Imports Microsoft.DirectX.Direct3D

Its part of that.
Cool.....thanks for the quick replys

What about

RAM
Manufacturer

is there a procedure to gather the above

oh yeah can you post a link to where i could download DirectX 9 SDK

THANKS
Reply With Quote
  #19  
Old 05-10-2005, 06:06 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

You can get the SDK from the Microsoft site. www.microsoft.com/directx

As for the other parts of the card, just use the manager to get them.
__________________
Cheers
Reply With Quote
  #20  
Old 05-10-2005, 06:15 AM
JamesBowtell JamesBowtell is offline
Newcomer
 
Join Date: May 2005
Posts: 19
Default

Quote:
Originally Posted by ardman
You can get the SDK from the Microsoft site. www.microsoft.com/directx

As for the other parts of the card, just use the manager to get them.
cool thanks very much......

James Bowtell
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
 
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
DirectX 9 SDK Tutorials: works in C#.NET, having trouble in VB.NET
 
-->