This repository was archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
136 lines (111 loc) · 4.98 KB
/
Copy pathProgram.cs
File metadata and controls
136 lines (111 loc) · 4.98 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
using System;
using System.Linq;
using System.Runtime.InteropServices;
using static GLFWDotNet.GLFW;
namespace GLFWInfo
{
public static class Program
{
private const uint GL_RENDERER = 0x1F01;
private const uint GL_VERSION = 0x1F02;
private static class Delegates
{
public delegate IntPtr glGetString(uint name);
}
public static int Main(string[] args)
{
if (glfwInit() == 0)
{
Console.Error.WriteLine("Failed to initialize GLFW.");
return 1;
}
glfwGetVersion(out int major, out int minor, out int revision);
Console.WriteLine($"GLFW Version: {major}.{minor}.{revision}");
var versionString = glfwGetVersionString();
Console.WriteLine($"GLFW Version String: {versionString}");
var monitors = glfwGetMonitors();
if (monitors != null)
{
Console.WriteLine($"Monitor Count: {monitors.Length}");
foreach (var monitor in monitors)
{
Console.WriteLine($"\t{glfwGetMonitorName(monitor)}");
var videoMode = glfwGetVideoMode(monitor);
Console.WriteLine($"\t\tVideo Mode: {videoMode.width}x{videoMode.height}");
// I don't know that the average gamme ramp value has any use, I just
// use it so that I have a number to display. :-p
var gammaRamp = glfwGetGammaRamp(monitor);
Console.WriteLine($"\t\tGamma Ramp: {nameof(gammaRamp.size)}={gammaRamp.size} {nameof(gammaRamp.red)}={gammaRamp.red.Select(x => (int)x).Average()} {nameof(gammaRamp.green)}={gammaRamp.green.Select(x => (int)x).Average()} {nameof(gammaRamp.blue)}={gammaRamp.blue.Select(x => (int)x).Average()}");
}
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_VISIBLE, 0);
IntPtr window = glfwCreateWindow(1, 1, "", IntPtr.Zero, IntPtr.Zero);
if (window == IntPtr.Zero)
{
Console.Error.WriteLine("ERROR: Unable to create GL context.");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
var glGetString = Marshal.GetDelegateForFunctionPointer<Delegates.glGetString>(glfwGetProcAddress("glGetString"));
var version = Marshal.PtrToStringAnsi(glGetString(GL_VERSION));
Console.WriteLine($"GL Version: {version}");
var renderer = Marshal.PtrToStringAnsi(glGetString(GL_RENDERER));
Console.WriteLine($"GL Renderer: {renderer}");
var vulkanSupported = glfwVulkanSupported();
Console.WriteLine($"Vulkan supported: {vulkanSupported}");
var vulkanRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions();
if (vulkanRequiredInstanceExtensions != null)
{
Console.WriteLine("\tRequired Instance Extensions:");
foreach (var extension in vulkanRequiredInstanceExtensions)
{
Console.WriteLine("\t\t" + extension);
}
}
var joysticks = new int[]
{
GLFW_JOYSTICK_1,
GLFW_JOYSTICK_2,
GLFW_JOYSTICK_3,
GLFW_JOYSTICK_4,
GLFW_JOYSTICK_5,
GLFW_JOYSTICK_6,
GLFW_JOYSTICK_7,
GLFW_JOYSTICK_8,
GLFW_JOYSTICK_9,
GLFW_JOYSTICK_10,
GLFW_JOYSTICK_11,
GLFW_JOYSTICK_12,
GLFW_JOYSTICK_13,
GLFW_JOYSTICK_14,
GLFW_JOYSTICK_15,
GLFW_JOYSTICK_16,
};
int joystickCount = 0;
while (glfwJoystickPresent(joysticks[joystickCount]) != 0)
joystickCount++;
Console.WriteLine($"Joystick Count: {joystickCount}");
for (int i = 0; i < joystickCount; i++)
{
Console.WriteLine("\t" + glfwGetJoystickName(joysticks[i]));
var joystickAxes = glfwGetJoystickAxes(joysticks[i]);
Console.Write("\t\t\tAxes: ");
foreach (var joystickAxis in joystickAxes)
Console.Write(joystickAxis + " ");
Console.WriteLine();
var joystickButtons = glfwGetJoystickButtons(joysticks[i]);
Console.Write("\t\t\tButtons: ");
foreach (var joystickButton in joystickButtons)
Console.Write(joystickButton + " ");
Console.WriteLine();
}
glfwTerminate();
return 0;
}
}
}