This repository was archived by the owner on Nov 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTestEmpty.cs
89 lines (70 loc) · 2.32 KB
/
TestEmpty.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
namespace Glfw3.Tests
{
using OpenGL;
using System;
using System.Threading;
/// <summary>
/// This test is intended to verify that posting of empty events works.
/// </summary>
/// <remarks>
/// Ported from <c>empty.c</c>.
/// </remarks>
class TestEmpty : TestBase
{
static volatile bool running = true;
static void ThreadMain()
{
while (running)
{
Thread.Sleep(1000);
Glfw.PostEmptyEvent();
}
}
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
{
if (key == Glfw.KeyCode.Escape && state == Glfw.InputState.Press)
Glfw.SetWindowShouldClose(window, true);
}
static void Main(string[] args)
{
Init();
var rand = new Random();
if (!Glfw.Init())
Environment.Exit(1);
var window = Glfw.CreateWindow(640, 480, "Empty Event Test");
if (!window)
{
Glfw.Terminate();
Environment.Exit(1);
}
Glfw.MakeContextCurrent(window);
Glfw.SetKeyCallback(window, KeyCallback);
var thread = new Thread(new ThreadStart(ThreadMain));
if (thread == null)
{
Log("Failed to create secondary thread");
Glfw.Terminate();
Environment.Exit(1);
}
thread.Start();
while (running)
{
int width, height;
float r = rand.Next(), g = rand.Next(), b = rand.Next();
float l = (float)Math.Sqrt(r * r + g * g + b * b);
Glfw.GetFramebufferSize(window, out width, out height);
Gl.Viewport(0, 0, width, height);
Gl.ClearColor(r / l, g / l, b / l, 1f);
Gl.Clear(ClearBufferMask.ColorBufferBit);
Glfw.SwapBuffers(window);
Glfw.WaitEvents();
if (Glfw.WindowShouldClose(window))
running = false;
}
Glfw.HideWindow(window);
thread.Join();
Glfw.DestroyWindow(window);
Glfw.Terminate();
}
}
}