-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
147 lines (110 loc) · 4.7 KB
/
Copy pathProgram.cs
File metadata and controls
147 lines (110 loc) · 4.7 KB
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
using OpenTK.Graphics.OpenGL4;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.GraphicsLibraryFramework;
using OpenTK.Mathematics;
namespace MyGame
{
public class Program
{
public static GameWindow window = new GameWindow(Window.gws, Window.nws);
// public static Camera Camera = new Camera();
public static Camera Camera = new Camera(Vector3.UnitZ * 5f);
public static Vector2i Size = new Vector2i(window.Size.X, window.Size.Y);
private static ImGuiController ?Imgui_controller;
private static Game ?game;
private static Text ?text;
private static PhysicsWorld physicsWorld = new PhysicsWorld();
public static bool vsync = true;
public static bool fullscreen = false;
private static void Main()
{
window.Load += delegate
{
// DebugGL.InitDebug();
StartGlobal();
Imgui_controller = new ImGuiController(window.Size);
text = new Text("Resources/Fonts/Courier Prime Sans.ttf");
game = new Game();
};
window.RenderFrame += delegate(FrameEventArgs frameEventArgs)
{
physicsWorld.UpdateFrameSimulation(frameEventArgs.Time);
Imgui_controller!.Update(Program.window, (float)frameEventArgs.Time);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
game!.RenderFrame();
// imgui NaveBars
ImGuiProgram.RenderFrame();
Imgui_controller.Render();
ImGuiController.CheckGLError("End of frame");
window.Context.SwapBuffers();
};
window.UpdateFrame += delegate(FrameEventArgs eventArgs)
{
var input = window.IsKeyPressed;
if (input(Keys.Escape))
window.Close();
if(input(Keys.F))
{
fullscreen = fullscreen ? false : true;
window.WindowState = fullscreen ? WindowState.Normal : WindowState.Fullscreen;
}
if(input(Keys.V))
{
vsync = vsync ? false : true;
window.VSync = vsync ? VSyncMode.On : VSyncMode.Off;
}
TimerGL.TimerUpdateFrame(eventArgs);
// update game
Camera.UpdateCamera();
game!.UpdateFrame();
};
window.Resize += delegate(ResizeEventArgs resizeEventArgs)
{
Size = resizeEventArgs.Size;
GL.Viewport(0, 0, resizeEventArgs.Size.X, resizeEventArgs.Size.Y);
Camera.UpdateSize(resizeEventArgs.Size);
Imgui_controller!.WindowResized(resizeEventArgs.Size);
game!.ResizedFrame();
};
window.MouseWheel += delegate(MouseWheelEventArgs mouseWheelEventArgs)
{
Camera.UpdateFov(ref mouseWheelEventArgs);
};
window.TextInput += delegate(TextInputEventArgs textInputEventArgs)
{
Imgui_controller!.PressChar((char)textInputEventArgs.Unicode);
};
window.Unload += delegate
{
physicsWorld.Dispose();
game!.Dispose();
};
window.Run();
}
public static void StartGlobal()
{
// ativa o tete de profundidade(z_buffer), assim o OpenGL renderiza tudo de forma correta
// por padrao e gl_less
GL.Enable(EnableCap.DepthTest);
// GL.DepthFunc(DepthFunction.Less);
// GL.DepthFunc(DepthFunction.Lequal);
// nao renderiza o que esta atrás
// GL.Enable(EnableCap.CullFace);
// ativando o espaço Srgb sobre texturas
GL.Enable(EnableCap.FramebufferSrgb);
// antialising
GL.Enable(EnableCap.Multisample);
// filtra as costuras dos cube maps
GL.Enable(EnableCap.TextureCubeMapSeamless);
// habilita o point size, isso tem efeito apenas no shader de geometria
GL.Enable(EnableCap.ProgramPointSize);
// ativando a opacidade no fragment shader
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.ClearColor(Color4.Black);
GL.Enable(EnableCap.LineSmooth);
GL.Enable(EnableCap.ColorSum);
}
}
}