How can I make my program fullscreen with C# code ?

CareEX

14-01-2008 12:28:54

I wrote my program Mogre+C# . But it runs in a general window not a fullscreen window. How can I make it running in a fullscreen window?

My code like this:


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using MogreFramework;
using Mogre;
namespace OgreTest
{
static class Program
{
[STAThread]
static void Main()
{
try
{
TestWin win = new TestWin();
new SceneCreator(win);
win.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription, "An Ogre exception has occurred!");
else
throw;
}

}
}

class TestWin : OgreWindow
{
protected override void CreateCamera()
{
Camera = this.SceneManager.CreateCamera("PlayerCam");


Camera.Position = new Vector3(0, 10, 100);
Camera.LookAt(Vector3.ZERO);


Camera.NearClipDistance = 1;
}


protected override void CreateViewport()
{
Viewport = this.RenderWindow.AddViewport(Camera);

Viewport.BackgroundColour = ColourValue.Red;
Camera.AspectRatio = (float)Viewport.ActualWidth / Viewport.ActualHeight;

}
}

class SceneCreator
{
public SceneCreator(OgreWindow win)
{
win.SceneCreating += new OgreWindow.SceneEventHandler(SceneCreating);
}

void SceneCreating(OgreWindow win)
{
// Set the ambient light and shadow technique
SceneManager mgr = win.SceneManager;
mgr.SetShadowUseInfiniteFarPlane(false);
mgr.AmbientLight = ColourValue.White;
mgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;

// Create a ninja
Entity ent = mgr.CreateEntity("jaiqua", "jaiqua.mesh");
ent.CastShadows = true;
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

// Define a ground plane
Plane plane = new Plane(Vector3.UNIT_Y, 0);
MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
plane, 1500, 1500, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z);

// Create a ground plane
ent = mgr.CreateEntity("GroundEntity", "ground");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);

ent.SetMaterialName("Examples/Rockwall");
ent.CastShadows = false;


// Create the first light
Light light;
light = mgr.CreateLight("Light1");
light.Type = Light.LightTypes.LT_POINT;
light.Position = new Vector3(0, 150, 250);
light.DiffuseColour = ColourValue.Red;
light.SpecularColour = ColourValue.Red;

// Create the second light
light = mgr.CreateLight("Light2");
light.Type = Light.LightTypes.LT_DIRECTIONAL;
light.DiffuseColour = new ColourValue(.25f, .25f, 0);
light.SpecularColour = new ColourValue(.25f, .25f, 0);
light.Direction = new Vector3(0, -1, -1);

// Create the third light
light = mgr.CreateLight("Light3");
light.Type = Light.LightTypes.LT_SPOTLIGHT;
light.DiffuseColour = ColourValue.Blue;
light.SpecularColour = ColourValue.Blue;
light.Direction = new Vector3(-1, -1, 0);
light.Position = new Vector3(300, 300, 0);
light.SetSpotlightRange(new Degree(35), new Degree(50));
}
}
}

dodongoxp

15-01-2008 00:36:26

i see your using the mogre framework... that makes use of a preset window config and state ..

to have more control over your window states,screen resolutions and ogre start up sequence you would need to write your own initializing code or modify the mogre framework code to be able to set the option of running your app full screen

you can get the mogreframework code from svn

http://www.idleengineer.net/tutorials/M ... eFramework

i think thats the svn checkout url of mogreframework

hope this helps abit 8)

CareEX

15-01-2008 03:35:33

Thanks a lot . And I found a simple way to make it looks like fullscreen.
Just put the code before "win.go".

win.FormBorderStyle = FormBorderStyle.None;
win.WindowState = FormWindowState.Maximized;


But please note,that's a fake one.The program does not really run in fullscreen.It still runs in the window mode.It only looks like fullscreen.

smernesto

15-01-2008 06:39:28

Well is not the better way to get fullscreen maybe you can try:


Ogre::RenderWindow::setFullscreen ( bool fullScreen,
unsigned int width,
unsigned int height
)


In Mogre mmm something like:


//You need to have a render window.
myRenderWindow.SetFullscreen(true, 800, 600); //well the resolution that you want.

pin

15-01-2008 09:30:31

I personally don't use MogreFramework. You can use this tutorial as your starting point in building MogreApps. It will give you a nice dialog box with settings for resolution and fullscreen/window mode.

CareEX

15-01-2008 11:06:44

I got it.Only one line code can make it.


win.RenderWindow.SetFullscreen(true,1024,768);


Put this code at the end of "SceneCreating".Just like

void SceneCreating(OgreWindow win)
{
....................................;
win.RenderWindow.SetFullscreen(true,1024,768);
}