-
Notifications
You must be signed in to change notification settings - Fork 3
/
RobustEngine.cs
294 lines (211 loc) · 9 KB
/
RobustEngine.cs
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
using System;
using System.Collections.Generic;
using System.IO;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using RobustEngine.Graphics;
using RobustEngine.Graphics.Render;
using RobustEngine.Graphics.Shaders;
using RobustEngine.Graphics.Sprites;
using RobustEngine.System;
using RobustEngine.System.Settings;
using RobustEngine.System.Time;
using RobustEngine.Window;
using RobustEngine.Graphics.Shapes2D;
namespace RobustEngine
{
public class RobustEngine
{
//Render engine. Handles all rendering.
public int version;
public string GLINFO;
//Add this to Atmos Engine.
public delegate void OnAtmosUpdate();
//Rendering
public Dictionary<string, NativeWindow> Windows;
public RenderTarget[] Rendertargets; // This may be unused due to Multiple Windows.
public GameWindow GameScreen;
public GameWindow AltScreens; // All other non gamescreen windows
public static Shader CurrentShader;
public GraphicsContext Context;
public DisplayDevice SelectedMonitor;
public VideoSettings VSettings;
public int Frame;
public int FrameTime;
private bool ReadyToRun;
//Testing
public View PlayerView;
public Clock Timekeeper;
public SpriteBatch Spritebatch;
public Texture2D Texture;
public Triangle2D TriangleTest;
public Line2D LineTest;
public Sprite Sprite;
public RobustEngine()
{
}
public void Init()
{
RobustConsole.ClearConsole();
RobustConsole.SetLogLevel(LogLevel.Debug);
RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Init() Intializing...");
Timekeeper = new Clock();
VSettings = new VideoSettings(); //TODO import video settings here
GameScreen = new GameWindow(800, 800, GraphicsMode.Default, "RobustWando", GameWindowFlags.Default, DisplayDevice.Default, 3, 3, GraphicsContextFlags.Debug);
//GameScreen = new GameWindow();
//GameScreen.Size = VSettings.Size;
//GameScreen.WindowBorder = VSettings.Border;
//GameScreen.Title = "Space Station 14";
//GameScreen.Visible = true;
// GameScreen.VSync = VSyncMode.Off;
GameScreen.MakeCurrent(); //OPENGL CONTEXT STARTS HERE
GLINFO += "\n\n------------------------------------------------------------------";
GLINFO += "\n OpenGL Version: " + GL.GetString(StringName.Version);
GLINFO += "\n Vendor: " + GL.GetString(StringName.Vendor);
GLINFO += "\n GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion);
GLINFO += "\n------------------------------------------------------------------\n";
RobustConsole.Write(LogLevel.Info, this, GLINFO);
GameScreen.RenderFrame += Render;
GameScreen.UpdateFrame += Update;
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.ClearColor(0, 0, 0, 0); //GL.Enable(EnableCap.VertexArray);
var ImageTestFile = Path.Combine(Environment.CurrentDirectory, "Graphics", "Shaders", "ImageTest");
CurrentShader = new Shader(ImageTestFile + ".vert", ImageTestFile + ".frag");
//TESTING
Texture = new Texture2D("Devtexture_Floor.png");
LineTest = new Line2D(0, 0, 0, 0, 1);
//LineTest = new Line(0, 0, 1, 1, 1);
TriangleTest = new Triangle2D(0, 0, 256, 256);
Sprite = new Sprite("test", Texture);
Sprite.SetPosition(new Vector2(.4f, .4f));
PlayerView = new View(Vector2.One, 0, 10);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.ClearColor(Color.DimGray);
// GL.Viewport(0, 0, -1500, -1500);
//Context = new GraphicsContext(GraphicsMode.Default, GameScreen.WindowInfo,4,4,GraphicsContextFlags.Default);
//Context.MakeCurrent(GameScreen.WindowInfo);
//(Context as IGraphicsContextInternal).LoadAll();
//GL.Enable(EnableCap.Blend);
RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Init() Done.");
ReadyToRun = true;
}
#region State
public void Run()
{
RobustConsole.Write(LogLevel.Warning, "RobustEngine", "Starting Run loop...");
Timekeeper.Start();
GameScreen.Run(60);
}
public void Update(object Sender, FrameEventArgs E)
{
GameScreen.ProcessEvents();
// Sprite.Update();
mov += .01f;
}
float mov = .002f;
float scale = 1 / 256f;
int frames;
Vector2 scal = new Vector2(1 / 256f, 1 / 256f);
public void Render(object Sender, FrameEventArgs E)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
// PlayerView.Setup(800, 800);
// PlayerView.Update();
// Spritebatch.Begin();
CurrentShader.Enable();
// Sprite.Rect.DebugMode = Debug.None;
// Sprite.Rect.SetFillColor(Color.Blue);
LineTest.SetFillColor(Color.Red);
LineTest.SetOrigin(LineTest.Center);
// LineTest.SetPosition(new Vector2(.10f * x, .10f * y));
// LineTest.SetRotation(mov, Axis.Z);
LineTest.Update();
LineTest.Draw();
//LineTest.SetFillColor(Color.Blue);
//LineTest.SetOrigin(LineTest.Center);
//// LineTest.SetPosition(new Vector2(.10f * x, .10f * y));
//LineTest.SetRotation(90f, Axis.Z);
//LineTest.Update();
//LineTest.Draw();
//TriangleTest.SetFillColor(Color.Blue);
//TriangleTest.SetOrigin(TriangleTest.BottomLeft);
//TriangleTest.SetScale(scal);
//TriangleTest.SetRotation(-mov, Axis.Z);
//TriangleTest.SetPosition(new Vector2(scale, scale));
//TriangleTest.Update();
//TriangleTest.Draw();
//Sprite.SetOrigin(Sprite.Rect.Center);
//Sprite.SetScale(new Vector2(scale, scale)); //+ (.001f * x), scale + (.001f * y)));
//Sprite.SetRotation(mov, Axis.Z);
//Sprite.SetPosition(new Vector2(scale, scale));
//Sprite.Update();
//Sprite.Draw();
//// Sprite.SetOrigin(new Vector2(-.5f, -.5f));
//Sprite.SetScale(new Vector2(scale, scale));
//Sprite.SetRotation(mov);
//Sprite.SetPosition(new Vector2(scale * x, -scale * y));
//Sprite.Update();
//Sprite.Draw();
//// Sprite.SetOrigin(new Vector2(-.5f, -.5f));
//Sprite.SetScale(new Vector2(scale, scale));
//Sprite.SetRotation(mov);
//Sprite.SetPosition(new Vector2(-scale * x, scale * y));
//Sprite.Update();
//Sprite.Draw();
//// Sprite.Rect.DebugMode = Debug.Wireframe;
//// Sprite.SetOrigin(new Vector2(-.5f, -.5f));
//Sprite.SetScale(new Vector2(scale, scale)); ;
//Sprite.SetRotation(mov);
//Sprite.SetPosition(new Vector2(scale * x, scale * y));
//Sprite.Update();
//Sprite.Draw();
// Texture.Unbind();
CurrentShader.Disable();
GameScreen.SwapBuffers();
frames++;
if (Timekeeper.GetElapsed().Seconds >= 1)
{
RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() FPS " + frames);
Timekeeper.Start();
frames = 0;
}
// RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() MS " + Timekeeper.GetTime().Milliseconds.ToString());
}
public void Stop()
{
RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Stopping...");
}
#endregion State
public void setCurrentRenderTarget(RenderTarget RT)
{
}
public void setScreenTarget(NativeWindow NW)
{
}
#region Global Error Checking
public static void CheckGLErrors()
{
var FBOEC = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
while ((FBOEC == FramebufferErrorCode.FramebufferComplete))
{
RobustConsole.Write(LogLevel.Verbose, "RobustEngine", FBOEC.ToString()); //TODO expand error message
break;
}
var EC = GL.GetError();
while (EC != ErrorCode.NoError)
{
RobustConsole.Write(LogLevel.Fatal, "RobustEngine", EC.ToString()); // TODO expand error message
}
}
# endregion Global Error Checking
}
public enum Debug
{
None,
Points,
Wireframe,
}
}