[Solved?] VB.NET Problems creating OgreCEGUIRenderer object

GregH

28-02-2006 10:05:39

Hi Folks,

Things are progressing well here...I've created a customised Config Dialogue (which still shows the unwanted DX7 - I'll get around to expelling that particular crash dummy one day).

My next area of focus is to get a mouse cursor on the screen, which leads me to CEGUI.

I understand that I have to instantiate CEGUI Renderer and CEGUI System objects...but I can't get past the CEGUI Renderer assignment (as I crash with the usual "Object reference not set..." error).

This is the scenario:

I've imported the necessary refs (I think)...



Imports CeguiDotNet
Imports OgreDotNet
Imports OgreDotNet.Cegui
Imports Math3D



I've then gone on to create all of the necessary objects to successfully create an animated OGRE scene. No problemo. Ok..now I need to add the CEGUI stuff.

So since then, I've added two new objects in the General Declarations section of the module (I've used the formal Namespace syntax for clarity here):



Private MyGUIRenderer As OgreDotNet.Cegui.OgreCEGUIRenderer
Private MyGUISystem As CeguiDotNet.GuiSystem

' ??? or is it ???

Private MyGUIRenderer As CeguiDotNet.Renderer
Private MyGUISystem As CeguiDotNet.GuiSystem

'??? or is it neither of these ???




NOTE: I'm not sure if I should be using OgreDotNet.Cegui or CeguiDotNet objects for the GUI stuff - please clarify ???


Then, during the initialisation process, and after I've created the render window and scenemanager (which has always resulted in perfect 3D rendering), I try to initialise the CEGUI Renderer and CEGUI System objects using either of the pairs of Private's above...




MyGUIRenderer = New OgreCEGUIRenderer(MyRenderWindow, RenderQueueGroupID.RENDER_QUEUE_OVERLAY, False, MakeUInt32(3000), MySceneManager)

MyGUISystem = New CeguiDotNet.GuiSystem(MyGUIRenderer)




Now this I know:

>MyRenderWindow renders perfectly if I don't try to use CEGUI, so it has initialised OK.

>RenderQueueGroupID.RENDER_QUEUE_OVERLAY has a value of 100.

>False is for post_queue (whatever that means).

>MakeUInt32(3000) is a custom function that works elsewhere without problems.

>MySceneManager has already successfully loaded a Terrain.cfg by this stage, and would render the scene if it weren't for the CEGUI calls. I have seen sample C++ code that uses the scenetype enumerator instead of the actual scenemanager, but either way it breaks.

Despite all of this, MyGUIRenderer assignment fails with the ubiquitous "Object reference not set..."

I note that the OgreCEGUIRenderer constructor has 7 overloads...and if I only pass the RenderWindow parameter I can initialise the MyGUIRenderer object...but then the MyGUISystem fails straight afterward with the same "Object reference blah blah blah error".

Has anybody managed to get CEGUI working with VB.Net code...I'd really appreciate some guidance in this regard.

Cheers,

GregH.

alberts

28-02-2006 10:26:16

Have you initialized your GUIRenderer? With C#:

mGuiRenderer = new OgreDotNet.Cegui.OgreCEGUIRenderer( mRenderWindow );
mGuiRenderer.Initialise();
mGuiSystem = new CeguiDotNet.GuiSystem(mGuiRenderer);

GregH

28-02-2006 11:00:38

Hi AlbertS,

It's great to hear from you, and even greater that you provided the solution to my problem.

Having said this, not one single document...notably the one found at

http://www.ogre3d.org/wiki/index.php/Pr ... tion_-_GUI

ever mentions having to use an Initialise method on the CEGUI Renderer. How did you discover this critical factoid?

I guess my psychic powers aren't what they used to be !!! By the way, any attempt to provide params beyond just the RenderWindow still causes a crash. I hope I don't really need them.

Thanks heaps for this quick response...

Cheers,

GregH. PS// [Edited]: and come to think of it, why on earth would you need to initialise something just after you've executed a Sub New on it with a bunch of parameters anyway???

EagleEye

28-02-2006 15:36:39

Here's mine:


Imports CeguiDotNet
Imports System
Imports System.Drawing
Imports OgreDotNet
Imports OgreDotNet.Cegui
Imports Math3D
Imports Tao.Ode
Imports VermundData.Vermund.Data
Imports VermundData.Vermund.Network
Imports Vector3 = Math3D.Vector3

Public Shutdown As Boolean = False
Public Root As New Root("plugins.cfg", "config.cfg", "vermund.log")
Public Window As RenderWindow
Public Scene As SceneManager = Nothing

Public GUI As OgreCEGUIRenderer
Public GUISys As GuiSystem
Public WithEvents Desktop As Window



This is my "sub new"


Initialiser.SetupResources("resources.cfg")
If Not Root.ShowConfigDialog Then
Return False
End If
Window = Root.Initialise(True, "Vermund : A Matter of Life and Death")
ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
'Logger.Instance.setLoggingLevel(LoggingLevel.Errors)
OEvents = New OgreDotNet.EventHandler(Root, Window)
OEvents.SubscribeEvents()
Scene = New SceneManager
Scene = Root.GetSceneManager(SceneType.ExteriorRealFar)
CreateCameras()
CreateViewports()
CreateGUI()
CreateScene()
Root.StartRendering()


Of course, I create my cameras and viewports... (there's only 1 of each now, but I have them split off for a reason.)

Then I create my GUI:

GUI = New OgreCEGUIRenderer(Window)
GUI.Initialise()
GUI.setTargetSceneManager(Scene)
GUISys = GuiSystem.CreateGuiSystemSpecial(GUI)
Logger.Instance.setLoggingLevel(LoggingLevel.Informative)
SchemeManager.Instance.LoadScheme("TaharezLook.scheme")
GUISys.SetDefaultMouseCursor("TaharezLook", "MouseArrow")
GUISys.DefaultFontName = "Tahoma-12"
Desktop = WindowManager.Instance.CreateWindow("DefaultWindow", "Desktop")
GUISys.GUISheet = Desktop


After that I create my other window instances. I don't recreate them every time they're shown... I just create them then show/hide them as necessary.

There ya go!

alberts

28-02-2006 21:01:12

Having said this, not one single document...notably the one found at

http://www.ogre3d.org/wiki/index.php/Pr ... tion_-_GUI

ever mentions having to use an Initialise method on the CEGUI Renderer. How did you discover this critical factoid?


I think it isn't documented because the method "Initialise" is only needed with OgreDotNet. I haven't discovered anything. I only use the code in the ODN - DemoCEGUI project :)

GregH. PS: and come to think of it, why on earth would you need to initialise something just after you've executed a Sub New on it with a bunch of parameters anyway???

Probably an inheritance problem related to the use of SWIG, because the "Initialise" method only call the same method of the base class. I'm not sure on this :?

GregH

28-02-2006 21:24:06

Thanks AlbertS and EagleEye,

Well, if you hadn't shared those particular pearls of wisdom, I think I'd be chipping away at ODN for the next decade without success.

One thing I have learnt: only use the C++ code samples/docs as a (very) rough guide, and assume that bits are missing/incorrect for DotNet programming - even if you were to translate them on a one-for-one basis. :!:

Also, thanks heaps for sharing your source code...it reveals a number of things about OGRE startup that have previously been vague or not discussed in other threads. I'll analyse your source more thoroughly tonight...particularly the use of various window refs, and of course the CEGUI content.

Cheers,

GregH.

EagleEye

28-02-2006 21:58:18

Here ya go, some more tidbits for you... :)

Public GUI As OgreCEGUIRenderer
Public GUISys As GuiSystem
Public WithEvents Desktop As Window
Public WithEvents WelcomeWindow As WelcomeWindow
Public WithEvents OptionsWindow As OptionsWindow
Public WithEvents GuildWindow As GuildWindow
Public WithEvents SkillsWindow As SkillsWindow
Public QuitQueryWindow As CloseQueryWindow
Public CharactersWindow As CharacterWindow
Public PAWindow As PAWindow
Public WithEvents ChatTarget As StaticText
Public WithEvents ChatInput As Editbox
Public StartPosition As Single = 0.05


GUI = New OgreCEGUIRenderer(Window)
GUI.Initialise()
GUI.setTargetSceneManager(Scene)
GUISys = GuiSystem.CreateGuiSystemSpecial(GUI)
Logger.Instance.setLoggingLevel(LoggingLevel.Informative)
SchemeManager.Instance.LoadScheme("TaharezLook.scheme")
GUISys.SetDefaultMouseCursor("TaharezLook", "MouseArrow")
GUISys.DefaultFontName = "Tahoma-12"
Desktop = WindowManager.Instance.CreateWindow("DefaultWindow", "Desktop")
GUISys.GUISheet = Desktop

QuitQueryWindow = New CloseQueryWindow
QuitQueryWindow.MyWindow.Text = "Quit?"
QuitQueryWindow.txtMsg.Text = "Are you sure you want to quit?"
QuitQueryWindow.MyWindow.hide()
Desktop.AddChildWindow(QuitQueryWindow.MyWindow)

WelcomeWindow = New WelcomeWindow
Desktop.AddChildWindow(WelcomeWindow.MyWindow)

CharactersWindow = New CharacterWindow
Desktop.AddChildWindow(CharactersWindow.MyWindow)

OptionsWindow = New OptionsWindow(StartPosition)
Desktop.AddChildWindow(OptionsWindow.MyWindow)
UpdateStartPosition()

ChatTarget = WindowManager.Instance.CreateStaticText(StaticTxt, "ChatTarget")
ChatTarget.SetSize(MetricsMode.Relative, New CeguiDotNet.Size(0.7, 0.2))
ChatTarget.SetPosition(MetricsMode.Relative, New CeguiDotNet.Vector2(0, 0.8))
ChatTarget.setAlpha(0.4)
ChatTarget.setAlwaysOnTop(True)
ChatTarget.setVerticalScrollbarEnabled(True)
ChatTarget.setHorizontalScrollbarEnabled(False)
ChatTarget.setFormatting(StaticText.HorzFormatting.WordWrapLeftAligned, StaticText.VertFormatting.BottomAligned)
ChatTarget.SubscribeEvents()
ChatTarget.hide()
Desktop.AddChildWindow(ChatTarget)

ChatInput = WindowManager.Instance.CreateEditbox(Editbox, "ChatInput")
ChatInput.SetSize(MetricsMode.Relative, New CeguiDotNet.Size(0.7, 0.05))
ChatInput.SetPosition(MetricsMode.Relative, New CeguiDotNet.Vector2(0, 0.75))
ChatInput.setAlpha(0.4)
ChatInput.setAlwaysOnTop(True)
ChatInput.SubscribeEvents()
ChatInput.deactivate()
ChatInput.hide()
Desktop.AddChildWindow(ChatInput)

GuildWindow = New GuildWindow(StartPosition)
Desktop.AddChildWindow(GuildWindow.MyWindow)
UpdateStartPosition()

SkillsWindow = New SkillsWindow(StartPosition)
Desktop.AddChildWindow(SkillsWindow.MyWindow)
UpdateStartPosition()

GregH

01-03-2006 10:16:12

Hi EagleEye,

Once again you've shared your hard work...this stuff is incredibly useful, and for once I don't have to speak multiple languages to come up with a solution :!:

I'll try to digest your code, and come up with some meaningful questions (if necessary).

Cheers, :lol:

GregH.

EagleEye

01-03-2006 17:46:32

I think I'll put this in to a WIKI page...