-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseApplicationSource.txt
executable file
·251 lines (202 loc) · 7.38 KB
/
BaseApplicationSource.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using Mogre;
using System;
namespace Mogre.TutorialFramework
{
class ShutdownException : Exception { }
public abstract partial class BaseApplication
{
protected Root mRoot;
protected SceneManager mSceneMgr;
protected Camera mCamera;
protected CameraMan mCameraMan;
protected RenderWindow mWindow;
protected string mPluginsCfg = "plugins.cfg";
protected string mResourcesCfg = "resources.cfg";
protected bool mShutDown = false;
protected int mTextureMode = 0;
protected int mRenderMode = 0;
protected DebugOverlay mDebugOverlay;
public void Go()
{
try
{
if (!Setup())
return;
mRoot.StartRendering();
DestroyScene();
}
catch (System.Runtime.InteropServices.SEHException e)
{
Console.WriteLine(e);
System.Windows.Forms.MessageBox.Show(
"An Ogre error has occurred. Check the Ogre.log file for details", "Exception",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
catch (Exception e)
{
Console.WriteLine(e);
System.Windows.Forms.MessageBox.Show(
e.Message, "Error",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
}
}
protected virtual bool Setup()
{
mRoot = new Root(mPluginsCfg);
if (!Configure())
return false;
ChooseSceneManager();
CreateCamera();
CreateViewports();
TextureManager.Singleton.DefaultNumMipmaps = 5;
CreateResourceListener();
LoadResources();
CreateScene();
CreateFrameListeners();
InitializeInput();
mDebugOverlay = new DebugOverlay(mWindow);
mDebugOverlay.AdditionalInfo = "Bilinear";
return true;
}
protected virtual bool Configure()
{
if (mRoot.ShowConfigDialog())
{
mWindow = mRoot.Initialise(true, "TutorialApplication Render Window");
return true;
}
else
{
return false;
}
}
protected virtual void ChooseSceneManager()
{
mSceneMgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
}
protected virtual void CreateCamera()
{
mCamera = mSceneMgr.CreateCamera("PlayerCam");
mCamera.Position = new Vector3(0, 100, 250);
mCamera.LookAt(new Vector3(0, 50, 0));
mCamera.NearClipDistance = 5;
mCameraMan = new CameraMan(mCamera);
}
protected virtual void CreateViewports()
{
// Create one viewport, entire window
var vp = mWindow.AddViewport(mCamera);
vp.BackgroundColour = ColourValue.Black;
// Alter the camera aspect ratio to match the viewport
mCamera.AspectRatio = (vp.ActualWidth / vp.ActualHeight);
}
protected virtual void CreateResourceListener()
{
}
protected virtual void LoadResources()
{
// Load resource paths from config file
var cf = new ConfigFile();
cf.Load(mResourcesCfg, "\t:=", true);
// Go through all sections & settings in the file
var seci = cf.GetSectionIterator();
while (seci.MoveNext())
{
foreach (var pair in seci.Current)
{
ResourceGroupManager.Singleton.AddResourceLocation(
pair.Value, pair.Key, seci.CurrentKey);
}
}
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}
protected void ReloadAllTextures()
{
TextureManager.Singleton.ReloadAll();
}
protected void CycleTextureFilteringMode()
{
mTextureMode = (mTextureMode + 1) % 4;
switch (mTextureMode)
{
case 0:
MaterialManager.Singleton.SetDefaultTextureFiltering(TextureFilterOptions.TFO_BILINEAR);
mDebugOverlay.AdditionalInfo = "BiLinear";
break;
case 1:
MaterialManager.Singleton.SetDefaultTextureFiltering(TextureFilterOptions.TFO_TRILINEAR);
mDebugOverlay.AdditionalInfo = "TriLinear";
break;
case 2:
MaterialManager.Singleton.SetDefaultTextureFiltering(TextureFilterOptions.TFO_ANISOTROPIC);
MaterialManager.Singleton.DefaultAnisotropy = 8;
mDebugOverlay.AdditionalInfo = "Anisotropic";
break;
case 3:
MaterialManager.Singleton.SetDefaultTextureFiltering(TextureFilterOptions.TFO_NONE);
MaterialManager.Singleton.DefaultAnisotropy = 1;
mDebugOverlay.AdditionalInfo = "None";
break;
}
}
protected void CyclePolygonMode()
{
mRenderMode = (mRenderMode + 1) % 3;
switch (mRenderMode)
{
case 0:
mCamera.PolygonMode = PolygonMode.PM_SOLID;
break;
case 1:
mCamera.PolygonMode = PolygonMode.PM_WIREFRAME;
break;
case 2:
mCamera.PolygonMode = PolygonMode.PM_POINTS;
break;
}
}
protected void TakeScreenshot()
{
mWindow.WriteContentsToTimestampedFile("screenshot", ".png");
}
protected virtual void CreateFrameListeners()
{
mRoot.FrameRenderingQueued += new FrameListener.FrameRenderingQueuedHandler(OnFrameRenderingQueued);
}
protected virtual bool OnFrameRenderingQueued(FrameEvent evt)
{
if (mWindow.IsClosed)
return false;
if (mShutDown)
return false;
try
{
ProcessInput();
UpdateScene(evt);
mCameraMan.UpdateCamera(evt.timeSinceLastFrame);
mDebugOverlay.Update(evt.timeSinceLastFrame);
return true;
}
catch (ShutdownException)
{
mShutDown = true;
return false;
}
}
protected void Shutdown()
{
throw new ShutdownException();
}
protected virtual void CreateScene()
{
}
protected virtual void UpdateScene(FrameEvent evt)
{
}
protected virtual void DestroyScene()
{
}
}
}