This repository has been 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
/
Program.cs
57 lines (43 loc) · 1.68 KB
/
Program.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
using System;
using System.Runtime.InteropServices;
using static GLFWDotNet.GLFW;
namespace HelloWorld
{
public static class Program
{
private const uint GL_COLOR_BUFFER_BIT = 0x00004000;
private static class Delegates
{
public delegate void glClear(uint mask);
public delegate void glClearColor(float red, float green, float blue, float alpha);
}
public static int Main(string[] args)
{
if (glfwInit() == 0)
return -1;
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);
IntPtr window = glfwCreateWindow(640, 480, "Hello World!", IntPtr.Zero, IntPtr.Zero);
if (window == IntPtr.Zero)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
var glClear = Marshal.GetDelegateForFunctionPointer<Delegates.glClear>(glfwGetProcAddress("glClear"));
var glClearColor = Marshal.GetDelegateForFunctionPointer<Delegates.glClearColor>(glfwGetProcAddress("glClearColor"));
// Cornflower Blue. Never forget.
glClearColor(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 1);
while (glfwWindowShouldClose(window) == 0)
{
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
}
}