Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Help with Intializing Direct3d device
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

brase
Neophyte

Australia
1 Posts

Posted - Jan 16 2006 :  2:03:42 PM  Show Profile  Visit brase's Homepage  Reply with Quote
I am trying to initialize Direct 3d with this code:
Imports Microsoft.DirectX  
Imports Microsoft.DirectX.Direct3D  
  
Public Class Form1  
    Dim device As Device  
    Public Sub New()  
  
        ' This call is required by the Windows Form Designer.  
        InitializeComponent()  
  
        ' Add any initialization after the InitializeComponent() call.  
  
    End Sub
    Public Function init3d()  
        Try
            Dim pparams As New PresentParameters  
            pparams.Windowed = True
            pparams.SwapEffect = SwapEffect.Discard  
            device = New Device(0, DeviceType.Software, Me, CreateFlags.SoftwareVertexProcessing, pparams)  
            Return True
        Catch ex As DirectXException  
            Return False
        End Try
    End Function
    Private Sub render()  
        Me.device.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)  
        Me.device.BeginScene()  
        Me.device.EndScene()  
        Me.device.Present()  
    End Sub
  
    Sub main()  
        If init3d() = False Then
            MsgBox("Couldn't initialize graphics", MsgBoxStyle.OkCancel, "Error")  
        End If
    End Sub
  
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)  
        Me.render()  
    End Sub
End Class  

when i try to debug i get this error:
quote:
Me.device.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)  

Object reference not set to an instance of an object.


All help is greatly appreciated.

VBBR
Moderator

Brazil
617 Posts

Posted - Jan 17 2006 :  08:35:30 AM  Show Profile  Reply with Quote
From what I remember you presumably had to do more stuf than that to init D3D... Are you sure you can init the device using "New Device" instead of creating it from the DX root class or whatever? I'm not good with DX9 so thta's only a guess.


Whatever. Who knows...
Go to Top of Page

Lachlan87
Moderator

USA
160 Posts

Posted - Jan 22 2006 :  09:24:15 AM  Show Profile  Reply with Quote
Surely that isn't the code you're using? I can't figure how you get as far as you do if it is. If you are using VB.NET 2002/2003, it should error out before it ever gets to that point. Sub Main must be declared as "Shared Sub Main" in order to work. Even if you make it shared, you still have the problem that you can't refer to init3d() without refering to a specific instance of Form1. And here I'm confused again, because if you are starting from sub main, you never make any instances of form1. And if you are not starting from sub Main, then sub main is never called, and therefore you haven't set device to equal a new device yet.

But frankly, I can't get your code to even go far enough to get the error you do. Are you sure this is a Copy and paste of the code your using?
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jan 23 2006 :  08:33:43 AM  Show Profile  Reply with Quote
He is probably starting in the form, hence main() is NEVER called and thus the device is not setup.

Call main in the form constructor and see what happens.

Whatever. Who knows...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.17 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.