-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWindow.cs
More file actions
48 lines (40 loc) · 1.24 KB
/
Window.cs
File metadata and controls
48 lines (40 loc) · 1.24 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
using GLFW;
using static OpenGL.Gl;
namespace SharpEngine {
public class Window {
readonly GLFW.Window window;
Scene scene;
public bool IsOpen() => !Glfw.WindowShouldClose(window);
public void Load(Scene scene) {
this.scene = scene;
}
public Window() {
// initialize and configure
Glfw.Init();
Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL);
Glfw.WindowHint(Hint.ContextVersionMajor, 3);
Glfw.WindowHint(Hint.ContextVersionMinor, 3);
Glfw.WindowHint(Hint.Decorated, true);
Glfw.WindowHint(Hint.OpenglProfile, Profile.Core);
Glfw.WindowHint(Hint.OpenglForwardCompatible, Constants.True);
Glfw.WindowHint(Hint.Doublebuffer, Constants.True);
// create and launch a window
window = Glfw.CreateWindow(768, 768, "SharpEngine", Monitor.None, GLFW.Window.None);
Glfw.MakeContextCurrent(window);
OpenGL.Gl.Import(Glfw.GetProcAddress);
}
static void ClearScreen() {
glClearColor(.2f, .05f, .2f, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
public void Render() {
Glfw.PollEvents(); // react to window changes (position etc.)
ClearScreen();
this.scene?.Render();
Glfw.SwapBuffers(window);
}
public bool GetKey(Keys key) {
return Glfw.GetKey(this.window, key) == InputState.Press;
}
}
}