forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglfw3.c
191 lines (155 loc) · 6.41 KB
/
glfw3.c
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
static void errorcb(int error, const char *msg) { (void)error; (void)msg; }
static void monitcb(GLFWmonitor *monitor, int event) { assert(monitor != NULL); (void)event; }
static void wposicb(GLFWwindow *window, int x, int y) { assert(window != NULL); (void)x; (void)y; }
static void wsizecb(GLFWwindow *window, int w, int h) { assert(window != NULL); (void)w; (void)h; }
static void wcloscb(GLFWwindow *window) { assert(window != NULL); }
static void wrfrscb(GLFWwindow *window) { assert(window != NULL); }
static void wfocucb(GLFWwindow *window, int focused) { assert(window != NULL); (void)focused; }
static void wiconcb(GLFWwindow *window, int iconified) { assert(window != NULL); (void)iconified; }
static void wfsizcb(GLFWwindow *window, int w, int h) { assert(window != NULL); (void)w; (void)h; }
static void wkeypcb(GLFWwindow *window, int key, int scancode, int action, int mods) {
assert(window != NULL); (void)key; (void)scancode; (void)action; (void)mods;
}
static void wcharcb(GLFWwindow *window, unsigned int cp) { assert(window != NULL); (void)cp; }
static void wmbutcb(GLFWwindow *window, int button, int action, int mods) {
assert(window != NULL); (void)button; (void)action; (void)mods;
}
static void wcurpcb(GLFWwindow *window, double x, double y) { assert(window != NULL); (void)x; (void)y; }
static void wcurecb(GLFWwindow *window, int entered) { assert(window != NULL); (void)entered; }
static void wscrocb(GLFWwindow *window, double x, double y) { assert(window != NULL); (void)x; (void)y; }
int main()
{
GLFWwindow *window;
char *userptr = "userptr";
glfwSetErrorCallback(errorcb);
assert(glfwInit() == GL_TRUE);
assert(!strcmp(glfwGetVersionString(), "3.0.0 JS WebGL Emscripten"));
{
int major, minor, rev;
glfwGetVersion(&major, &minor, &rev);
assert(major == 3);
assert(minor == 0);
assert(rev == 0);
}
{
int count, x, y, w, h;
GLFWmonitor **monitors = glfwGetMonitors(&count);
assert(count == 1);
for (int i = 0; i < count; ++i) {
assert(monitors[i] != NULL);
}
assert(glfwGetPrimaryMonitor() != NULL);
glfwGetMonitorPos(monitors[0], &x, &y);
glfwGetMonitorPhysicalSize(monitors[0], &w, &h);
assert(glfwGetMonitorName(monitors[0]) != NULL);
glfwSetMonitorCallback(monitcb);
// XXX: not implemented
// assert(glfwGetVideoModes(monitors[0], &count) != NULL);
// assert(glfwGetVideoMode(monitors[0]) != NULL);
// glfwSetGamma(monitors[0], 1.0f);
// assert(glfwGetGammaRamp(monitors[0]) != NULL);
// glfwSetGammaRamp(monitors[0], ramp);
}
{
int x, y, w, h;
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
assert(window != NULL);
glfwSetWindowPosCallback(window, wposicb);
glfwSetWindowSizeCallback(window, wsizecb);
glfwSetWindowCloseCallback(window, wcloscb);
glfwSetWindowRefreshCallback(window, wrfrscb);
glfwSetWindowFocusCallback(window, wfocucb);
glfwSetWindowIconifyCallback(window, wiconcb);
glfwSetFramebufferSizeCallback(window, wfsizcb);
assert(glfwWindowShouldClose(window) == 0);
glfwSetWindowShouldClose(window, 1);
assert(glfwWindowShouldClose(window) == 1);
glfwSetWindowTitle(window, "test");
glfwSetWindowTitle(window, "glfw3.c");
// XXX: not implemented
// glfwSetWindowPos(window, 1, 1);
glfwGetWindowPos(window, &x, &y); // stub
glfwGetWindowSize(window, &w, &h);
assert(w == 640 && h == 480);
glfwSetWindowSize(window, 1, 1);
glfwGetWindowSize(window, &w, &h);
assert(w == 1 && h == 1);
glfwSetWindowSize(window, 640, 480);
glfwGetFramebufferSize(window, &w, &h);
// XXX: not implemented
// glfwIconifyWindow(window);
// glfwRestoreWindow(window);
// glfwShowWindow(window);
// glfwHideWindow(window);
assert(glfwGetWindowMonitor(window) == NULL);
glfwDestroyWindow(window);
window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL);
assert(window != NULL);
assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor());
glfwDestroyWindow(window);
window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
assert(window != NULL);
assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API);
assert(glfwGetWindowUserPointer(window) == NULL);
glfwSetWindowUserPointer(window, userptr);
assert(glfwGetWindowUserPointer(window) == userptr);
}
{
double x, y;
glfwSetKeyCallback(window, wkeypcb);
glfwSetCharCallback(window, wcharcb);
glfwSetMouseButtonCallback(window, wmbutcb);
glfwSetCursorPosCallback(window, wcurpcb);
glfwSetCursorEnterCallback(window, wcurecb);
glfwSetScrollCallback(window, wscrocb);
// XXX: stub, events come immediatly
// glfwPollEvents();
// glfwWaitEvents();
assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);
// XXX: not implemented
// glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwGetKey(window, GLFW_KEY_A);
glfwGetMouseButton(window, 0);
glfwGetCursorPos(window, &x, &y);
// XXX: not implemented
// glfwSetCursorPos(window, 0, 0);
}
{
// XXX: not implemented
// glfwJoystickPresent(joy);
// glfwGetJoystickAxes(joy, &count);
// glfwGetJoystickButtons(joy, &count);
// glfwGetJoystickName(joy);
}
{
// XXX: not implemented
// glfwSetClipboardString(window, "string");
// glfwGetClipboardString(window);
}
{
glfwGetTime();
glfwSetTime(0);
}
{
glfwMakeContextCurrent(window); // stub
assert(glfwGetCurrentContext() == window);
glfwSwapBuffers(window); // stub
glfwSwapInterval(0); // stub
}
{
assert(glfwExtensionSupported("nonexistant") == 0);
assert(glfwGetProcAddress("nonexistant") == NULL);
}
glfwTerminate();
#ifdef REPORT_RESULT
int result = 1;
REPORT_RESULT();
#endif
return 0;
}