jimanjr
04-07-2008 08:30:23
Hi!
I'm trying to use MOGRE with VB.net to make a little preview window in my editor.
The problem is I can't seem to be able to create a resizeable form.
Here's my code:
It crashes when I try to create a window:
If I use MyWindow = myRoot.Initialise(True, "Application") everything works, but the MOGRE window takes total control of my application and becomes the only window.
Can anyone give me a hand on this one?
P.S. I know I'm doing something wrong. I'm new to MOGRE, and I couldn't find an example with Forms for VB.NET, so bare with me
I'm trying to use MOGRE with VB.net to make a little preview window in my editor.
The problem is I can't seem to be able to create a resizeable form.
Here's my code:
Imports Mogre
Public Class Form2
Public myKeyboard As MOIS.Keyboard
Public myMouse As MOIS.Mouse
Public myCamera As Camera
Public MyWindow As RenderWindow
Public myTranslation As Vector3 = Vector3.ZERO
Public Quitting As Boolean = False
Public myRotating As Boolean = False
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myRoot As Root = New Root("Plugins.cfg", "ogre.cfg", "ogre.log")
'Show Ogre Rendering Subsystem setup dialog box
If Not myRoot.RestoreConfig Then
If Not myRoot.ShowConfigDialog Then
Exit Sub
End If
End If
'Create an Ogre render window
'MyWindow = myRoot.Initialise(True, "Application")
Dim misc As New NameValuePairList
misc("externalWindowHandle") = Me.Handle.ToString()
Dim const_list As Const_NameValuePairList = misc.ReadOnlyInstance
MyWindow = myRoot.CreateRenderWindow("Simple Mogre Form Window", 0, 0, False, const_list)
'AddHandler myRoot.FrameStarted, AddressOf FrameStarted
'Create Ogre SceneManager & Set AmbientLight to bright white
Dim mySceneManager As SceneManager = myRoot.CreateSceneManager(SceneType.ST_GENERIC)
mySceneManager.AmbientLight = New ColourValue(1, 1, 1)
'Read Resources
Dim cf As New ConfigFile
cf.Load("resources.cfg", vbTab + ":=", True)
Dim seci As ConfigFile.SectionIterator = cf.GetSectionIterator
Dim secName As String, typeName As String, archName As String
While (seci.MoveNext())
secName = seci.CurrentKey
Dim settings As ConfigFile.SettingsMultiMap = seci.Current
For Each pair As KeyValuePair(Of String, String) In settings
typeName = pair.Key
archName = pair.Value
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName)
Next
End While
ResourceGroupManager.Singleton.InitialiseAllResourceGroups()
'Create Camera
myCamera = mySceneManager.CreateCamera("Camera")
myCamera.SetPosition(0, 0, 500)
myCamera.LookAt(0, 0, 0)
myCamera.NearClipDistance = 5
myCamera.FarClipDistance = 5000
'Viewport
Dim myViewport As Viewport = MyWindow.AddViewport(myCamera)
'Keyboard
Dim windowHnd As Integer
MyWindow.GetCustomAttribute("WINDOW", windowHnd)
Dim myInputManager As MOIS.InputManager = MOIS.InputManager.CreateInputSystem(windowHnd)
myKeyboard = myInputManager.CreateInputObject(MOIS.Type.OISKeyboard, True)
'Mouse
myMouse = myInputManager.CreateInputObject(MOIS.Type.OISMouse, True)
'Start rendering
myRoot.StartRendering()
End Sub
End Class
It crashes when I try to create a window:
An unhandled exception of type 'System.AccessViolationException' occurred in Mogre.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If I use MyWindow = myRoot.Initialise(True, "Application") everything works, but the MOGRE window takes total control of my application and becomes the only window.
Can anyone give me a hand on this one?
P.S. I know I'm doing something wrong. I'm new to MOGRE, and I couldn't find an example with Forms for VB.NET, so bare with me