@easywasm/gl 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/package.json +6 -4
- package/web/gl.js +1060 -0
- package/web/glfw.js +931 -0
- package/src/example.c +0 -58
- package/src/glfw3.h +0 -6577
package/src/example.c
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// this is an exmaple of wasm/native code
|
|
2
|
-
|
|
3
|
-
#include "glfw3.h"
|
|
4
|
-
#include <math.h>
|
|
5
|
-
|
|
6
|
-
#ifdef __wasm__
|
|
7
|
-
void glClearColor(float r, float g, float b, float a);
|
|
8
|
-
void glClear(unsigned int mask);
|
|
9
|
-
# define GL_COLOR_BUFFER_BIT 0x4000
|
|
10
|
-
#elif defined(__APPLE__)
|
|
11
|
-
# include <OpenGL/gl.h>
|
|
12
|
-
#else
|
|
13
|
-
# include <GL/gl.h>
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
static GLFWwindow* window = NULL;
|
|
17
|
-
|
|
18
|
-
static void key_callback(GLFWwindow* w, int key, int scancode, int action, int mods) {
|
|
19
|
-
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
|
20
|
-
glfwSetWindowShouldClose(w, GLFW_TRUE);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// On wasm: exported and called each tick by JS requestAnimationFrame.
|
|
24
|
-
// On native: called in the main loop below.
|
|
25
|
-
// Returns 1 to keep going, 0 to stop.
|
|
26
|
-
__attribute__((export_name("frame")))
|
|
27
|
-
int frame(void) {
|
|
28
|
-
if (!window || glfwWindowShouldClose(window)) return 0;
|
|
29
|
-
|
|
30
|
-
float t = (float)glfwGetTime();
|
|
31
|
-
glClearColor(
|
|
32
|
-
0.5f + 0.5f * sinf(t),
|
|
33
|
-
0.5f + 0.5f * sinf(t + 2.094f),
|
|
34
|
-
0.5f + 0.5f * sinf(t + 4.189f),
|
|
35
|
-
1.0f
|
|
36
|
-
);
|
|
37
|
-
glClear(GL_COLOR_BUFFER_BIT);
|
|
38
|
-
glfwSwapBuffers(window);
|
|
39
|
-
glfwPollEvents();
|
|
40
|
-
return 1;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
int main(void) {
|
|
44
|
-
if (!glfwInit()) return -1;
|
|
45
|
-
|
|
46
|
-
window = glfwCreateWindow(640, 480, "GLFW Demo", NULL, NULL);
|
|
47
|
-
if (!window) { glfwTerminate(); return -1; }
|
|
48
|
-
|
|
49
|
-
glfwMakeContextCurrent(window);
|
|
50
|
-
glfwSetKeyCallback(window, key_callback);
|
|
51
|
-
|
|
52
|
-
#ifndef __wasm__
|
|
53
|
-
while (frame()) {}
|
|
54
|
-
glfwTerminate();
|
|
55
|
-
#endif
|
|
56
|
-
|
|
57
|
-
return 0;
|
|
58
|
-
}
|