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 pathTestTimeout.cs
61 lines (49 loc) · 1.76 KB
/
TestTimeout.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
namespace Glfw3.Tests
{
using OpenGL;
using System;
/// <summary>
/// This test is intended to verify that waiting for events with timeout works.
/// </summary>
/// <remarks>
/// Ported from <c>timeout.c</c>.
/// </remarks>
class TestTimeout : TestBase
{
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();
Glfw.Window window;
if (!Glfw.Init())
Environment.Exit(1);
window = Glfw.CreateWindow(640, 480, "Event Wait Timeout Test");
if (!window)
{
Glfw.Terminate();
Environment.Exit(1);
}
Glfw.MakeContextCurrent(window);
Glfw.SetKeyCallback(window, KeyCallback);
while (!Glfw.WindowShouldClose(window))
{
int width, height;
double r = rand.NextDouble(), g = rand.NextDouble(), b = rand.NextDouble();
double l = Math.Sqrt(r * r + g * g + b * b);
Glfw.GetFramebufferSize(window, out width, out height);
Gl.Viewport(0, 0, width, height);
Gl.ClearColor((float)(r / l), (float)(g / l), (float)(b / l), 1f);
Gl.Clear(ClearBufferMask.ColorBufferBit);
Glfw.SwapBuffers(window);
Glfw.WaitEventsTimeout(1.0);
}
Glfw.DestroyWindow(window);
Glfw.Terminate();
}
}
}