C# code for Overlays

pin

30-03-2007 18:18:20

Does anyone know C# code that shows how Overlays are supposed to be used? I have some C++ snippets but that'll take a time to figure out and translate to NET code.

Eldritch

30-03-2007 19:38:54

OverlayManager.Singleton.GetByName("name of overlay").Show();

The "name of overlay" parameter must match any given overlay name defined in an overlay file.

pin

30-03-2007 21:55:25

Hey Eldritch thanks for replying

I was looking for a more comprehensive solution =]. Anyways porting the C++ snippet for Overlays wasn't that hard after all. Here's what I've got:


//Overlay
OverlayManager overlayManager = OverlayManager.Singleton;
// Create a panel
OverlayContainer panel = (OverlayContainer)overlayManager.CreateOverlayElement("Panel", "PanelName");
panel.MetricsMode = GuiMetricsMode.GMM_PIXELS;
panel.SetPosition(10,10);
panel.SetDimensions(100,100);
//panel.MaterialName = "MaterialName"; // Optional background material

// Create a text area
TextAreaOverlayElement textArea = (TextAreaOverlayElement)overlayManager.CreateOverlayElement("TextArea", "TextAreaName");
textArea.MetricsMode = GuiMetricsMode.GMM_PIXELS;
textArea.SetPosition(0,0);
textArea.SetDimensions(100,100);
textArea.Caption = "Hello World";
textArea.CharHeight = 16;
textArea.FontName = "TrebuchetMSBold";
textArea.ColourBottom = new ColourValue(0.3f,0.5f,0.3f);
textArea.ColourTop = new ColourValue(0.5f, 0.7f, 0.5f);

// Create an overlay, and add the panel
Overlay overlay = overlayManager.Create("OverlayName");

overlay.Add2D(panel);
// Add the text area to the panel
panel.AddChild(textArea);

// Show the overlay
overlay.Show();


I am getting an error though when I try to run the program:

OGRE EXCEPTION(5:ItemIdentityException): Could not find font
TrebuchetMSBold in TextAreaOverlayElement:setFontName at
...\src\OgreTextAreaOveralyElement.cpp (line 360)

Any idea what might cause that?

Eldritch

30-03-2007 21:58:07

It cannot locate TrebuchetMSBold.. do you have that font? Try changing that to some font you know you have.

pin

30-03-2007 22:13:36

I changed it with a font I have in my OgreSDK/media/fonts directory but I'm still getting the error. The resource.cfg seems to reflect the paths correctly.

Eldritch

30-03-2007 22:14:48

Change it to "BlueHighway" and it should work, does for me.

pin

30-03-2007 22:18:00

That does work, strangely I don't have it in my fonts folder though.

Eldritch

30-03-2007 22:19:28

No, it is in the gui folder.

pin

30-03-2007 22:36:48

Ok, I trying to use the code above to also get my cursor displayed.

I've uncommented

panel.MaterialName = "MaterialName";

and replaced MaterialName with "dirt.jpg" from
Media\materials\textures folder. (tried both "Dirt" and "Dirt.jpg" )

For some reason I'm getting an error similar with the first one when I try to run that.

Eldritch

30-03-2007 22:39:13

That is not a material. Materials can be located in the files in materials/scripts. You set a material, which in turn contains one or more textures.

pin

30-03-2007 22:46:35

thx, but the ones in the scripts folder don't work either (tried a few)

Eldritch

30-03-2007 22:50:06

Try Core/StatsBlockCenter

pin

30-03-2007 22:55:50

Are you looking into a magic globe other there?
Anyways is there a way to display an image with an alpha channel using materials? I'm trying to display a cursor.

Hey Eldritch thanks a bunch for your help.

Eldritch

30-03-2007 22:59:57

No magic globe, did this stuff earlier today just to try it out, though I used overlay files instead of creating one by code.

I don't know about transparency.. might be possible.. someone else might be able to shed some light on that.

Bekas

31-03-2007 10:51:06

thx, but the ones in the scripts folder don't work either (tried a few)
Did you used the filename (like "Example.material") ? This is not how materials are loaded, if you open Example.material you will see several declarations of materials (like "material Examples/EnvMappedRustySteel"), you use the declaration to set materials (i.e "Examples/EnvMappedRustySteel").

is there a way to display an image with an alpha channel using materials? I'm trying to display a cursor.
You need to read the Ogre manual to learn more about material scripting.

pin

31-03-2007 12:18:25

Thanks for pointing that.