From 2d93dfd42ac5b5d2fbd00f6226c987c78d276b49 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 20:16:00 -0700 Subject: [PATCH 01/17] Emscripten can use its own GLFW/GLEW instead; exclude bundled deps --- CMakeLists.txt | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 851ae3ad7..a4b190ada 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,35 @@ project(craft) FILE(GLOB SOURCE_FILES src/*.c) -add_executable( - craft - ${SOURCE_FILES} - deps/glew/src/glew.c - deps/lodepng/lodepng.c - deps/noise/noise.c - deps/sqlite/sqlite3.c - deps/tinycthread/tinycthread.c) +if (EMSCRIPTEN) + add_executable( + craft + ${SOURCE_FILES} + #deps/glew/src/glew.c + deps/lodepng/lodepng.c + deps/noise/noise.c + deps/sqlite/sqlite3.c + deps/tinycthread/tinycthread.c) +else () + add_executable( + craft + ${SOURCE_FILES} + deps/glew/src/glew.c + deps/lodepng/lodepng.c + deps/noise/noise.c + deps/sqlite/sqlite3.c + deps/tinycthread/tinycthread.c) +endif () add_definitions(-std=c99 -O3) -add_subdirectory(deps/glfw) -include_directories(deps/glew/include) -include_directories(deps/glfw/include) +if (NOT EMSCRIPTEN) + # Emscripten includes its own GLFW and GLEW ports + add_subdirectory(deps/glfw) + include_directories(deps/glew/include) + include_directories(deps/glfw/include) +endif () + include_directories(deps/lodepng) include_directories(deps/noise) include_directories(deps/sqlite) From ccfee47571acff8d57efa429c52759a9ed3ee324 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 20:17:46 -0700 Subject: [PATCH 02/17] Update readme for how to build to target Emscripten --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8708e4c9d..b64397242 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ terminal. make ./craft +To build for the web (experimental), install [Emscripten](http://emscripten.org) and instead run: + + cmake -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake . + ### Multiplayer Register for an account! From ca9c743ce917d54d4340626f79dc1311252d04f3 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 20:35:59 -0700 Subject: [PATCH 03/17] Emscripten compile out curl library --- CMakeLists.txt | 8 ++++++-- src/auth.c | 6 ++++++ src/main.c | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4b190ada..a352e470c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,12 @@ if(MINGW) "C:/Program Files/CURL/include" "C:/Program Files (x86)/CURL/include") endif() -find_package(CURL REQUIRED) -include_directories(${CURL_INCLUDE_DIR}) +if (NOT EMSCRIPTEN) + find_package(CURL REQUIRED) + include_directories(${CURL_INCLUDE_DIR}) +else () + set(CURL_LIBRARIES "") +endif () if(APPLE) target_link_libraries(craft glfw diff --git a/src/auth.c b/src/auth.c index 4ff781580..857f7ca96 100644 --- a/src/auth.c +++ b/src/auth.c @@ -1,4 +1,6 @@ +#ifndef __EMSCRIPTEN__ #include +#endif #include #include #include @@ -21,6 +23,9 @@ size_t write_function(char *data, size_t size, size_t count, void *arg) { int get_access_token( char *result, int length, char *username, char *identity_token) { +#ifdef __EMSCRIPTEN__ + return 0; +#else static char url[] = "https://craft.michaelfogleman.com/api/1/identity"; strncpy(result, "", length); CURL *curl = curl_easy_init(); @@ -46,4 +51,5 @@ int get_access_token( } } return 0; +#endif } diff --git a/src/main.c b/src/main.c index a0b622861..3463f8593 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ #include #include +#ifndef __EMSCRIPTEN__ #include +#endif #include #include #include @@ -2585,7 +2587,9 @@ void reset_model() { int main(int argc, char **argv) { // INITIALIZATION // +#ifndef __EMSCRIPTEN__ curl_global_init(CURL_GLOBAL_DEFAULT); +#endif srand(time(NULL)); rand(); @@ -2958,6 +2962,8 @@ int main(int argc, char **argv) { } glfwTerminate(); +#ifndef __EMSCRIPTEN__ curl_global_cleanup(); +#endif return 0; } From 859fb217695f7dace12ef9e63c199324396986b2 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 20:47:12 -0700 Subject: [PATCH 04/17] Emscripten supports GLFW 3.x, pass USE_GLFW=3 to use it --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a352e470c..1f1baf178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,11 @@ endif () add_definitions(-std=c99 -O3) +if (EMSCRIPTEN) + # Emscripten default is GLFW 2.x but we use GLFW 3.x + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3") +endif () + if (NOT EMSCRIPTEN) # Emscripten includes its own GLFW and GLEW ports add_subdirectory(deps/glfw) From f5fb72544b7124e6dd8a562d313c8329aa51254b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 21:20:30 -0700 Subject: [PATCH 05/17] Refactor main loop into one_iter() --- src/main.c | 86 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/src/main.c b/src/main.c index 3463f8593..3f46938de 100644 --- a/src/main.c +++ b/src/main.c @@ -2585,6 +2585,21 @@ void reset_model() { g->time_changed = 1; } +void one_iter(); +static FPS fps = {0, 0, 0}; +static double last_commit; +static double last_update; +static double previous; +static State *s; +static Player *me; +static Attrib block_attrib = {0}; +static Attrib line_attrib = {0}; +static Attrib text_attrib = {0}; +static Attrib sky_attrib = {0}; +static GLuint sky_buffer; +static int g_running; +static int g_inner_break; + int main(int argc, char **argv) { // INITIALIZATION // #ifndef __EMSCRIPTEN__ @@ -2656,10 +2671,6 @@ int main(int argc, char **argv) { load_png_texture("textures/sign.png"); // LOAD SHADERS // - Attrib block_attrib = {0}; - Attrib line_attrib = {0}; - Attrib text_attrib = {0}; - Attrib sky_attrib = {0}; GLuint program; program = load_program( @@ -2731,8 +2742,8 @@ int main(int argc, char **argv) { } // OUTER LOOP // - int running = 1; - while (running) { + g_running = 1; + while (g_running) { // DATABASE INITIALIZATION // if (g->mode == MODE_OFFLINE || USE_CACHE) { db_enable(); @@ -2756,13 +2767,13 @@ int main(int argc, char **argv) { // LOCAL VARIABLES // reset_model(); - FPS fps = {0, 0, 0}; - double last_commit = glfwGetTime(); - double last_update = glfwGetTime(); - GLuint sky_buffer = gen_sky_buffer(); + //FPS fps = {0, 0, 0}; + last_commit = glfwGetTime(); + last_update = glfwGetTime(); + sky_buffer = gen_sky_buffer(); - Player *me = g->players; - State *s = &g->players->state; + me = g->players; + s = &g->players->state; me->id = 0; me->name[0] = '\0'; me->buffer = 0; @@ -2776,8 +2787,32 @@ int main(int argc, char **argv) { } // BEGIN MAIN LOOP // - double previous = glfwGetTime(); + previous = glfwGetTime(); + g_inner_break = 0; while (1) { + one_iter(); + if (g_inner_break) break; + } + + // SHUTDOWN // + db_save_state(s->x, s->y, s->z, s->rx, s->ry); + db_close(); + db_disable(); + client_stop(); + client_disable(); + del_buffer(sky_buffer); + delete_all_chunks(); + delete_all_players(); + } + + glfwTerminate(); +#ifndef __EMSCRIPTEN__ + curl_global_cleanup(); +#endif + return 0; +} + +void one_iter() { // WINDOW SIZE AND SCALE // g->scale = get_scale_factor(); glfwGetFramebufferSize(g->window, &g->width, &g->height); @@ -2941,29 +2976,12 @@ int main(int argc, char **argv) { glfwSwapBuffers(g->window); glfwPollEvents(); if (glfwWindowShouldClose(g->window)) { - running = 0; - break; + g_running = 0; + g_inner_break = 1; } if (g->mode_changed) { g->mode_changed = 0; - break; + g_inner_break = 1; } - } - - // SHUTDOWN // - db_save_state(s->x, s->y, s->z, s->rx, s->ry); - db_close(); - db_disable(); - client_stop(); - client_disable(); - del_buffer(sky_buffer); - delete_all_chunks(); - delete_all_players(); - } - - glfwTerminate(); -#ifndef __EMSCRIPTEN__ - curl_global_cleanup(); -#endif - return 0; } + From a05c2801fdb61a09140645a9eb9bedc5cd898965 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 21:30:35 -0700 Subject: [PATCH 06/17] Emscripten set main loop --- src/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.c b/src/main.c index 3f46938de..7a2e66b2d 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,9 @@ #ifndef __EMSCRIPTEN__ #include #endif +#ifdef __EMSCRIPTEN__ +#include +#endif #include #include #include @@ -2788,11 +2791,15 @@ int main(int argc, char **argv) { // BEGIN MAIN LOOP // previous = glfwGetTime(); +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(one_iter, 60, 1); +#else g_inner_break = 0; while (1) { one_iter(); if (g_inner_break) break; } +#endif // SHUTDOWN // db_save_state(s->x, s->y, s->z, s->rx, s->ry); From 2c3a8dc90548c23a26ffbe3a39e26663a78f97d9 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 21:33:44 -0700 Subject: [PATCH 07/17] Call glfwSwapInterval after setting the main loop to appease Emscripten --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 7a2e66b2d..18e726cff 100644 --- a/src/main.c +++ b/src/main.c @@ -2622,7 +2622,6 @@ int main(int argc, char **argv) { } glfwMakeContextCurrent(g->window); - glfwSwapInterval(VSYNC); glfwSetInputMode(g->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetKeyCallback(g->window, on_key); glfwSetCharCallback(g->window, on_char); @@ -2794,6 +2793,7 @@ int main(int argc, char **argv) { #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(one_iter, 60, 1); #else + glfwSwapInterval(VSYNC); g_inner_break = 0; while (1) { one_iter(); From 6b9f6d895ffdba629d94ca39654bb6d2fd15694e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 21:34:13 -0700 Subject: [PATCH 08/17] glLogicOp unsupportable in Emscripten, see https://github.com/kripken/emscripten/issues/1416 --- src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.c b/src/main.c index 18e726cff..dd04cdcda 100644 --- a/src/main.c +++ b/src/main.c @@ -2634,7 +2634,9 @@ int main(int argc, char **argv) { glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); +#ifndef __EMSCRIPTEN__ // TODO: remove, what is replacement? glLogicOp not in >=GLES2: https://github.com/kripken/emscripten/issues/1416 glLogicOp(GL_INVERT); +#endif glClearColor(0, 0, 0, 1); // LOAD TEXTURES // From 83a9eacbc1bdd2d67e37420b273f31736a9850c1 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 22:01:36 -0700 Subject: [PATCH 09/17] Use set_target_properties() to set -s USE_GLFW=3 instead --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f1baf178..fae0a0d54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ add_definitions(-std=c99 -O3) if (EMSCRIPTEN) # Emscripten default is GLFW 2.x but we use GLFW 3.x - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3") + set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3") endif () if (NOT EMSCRIPTEN) From a1fdc37e5bf66c8f755b8876b8f4d7d52cd98729 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 22:06:43 -0700 Subject: [PATCH 10/17] Emscripten embed files for glsl shaders --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fae0a0d54..2c66b2aa1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ endif () add_definitions(-std=c99 -O3) if (EMSCRIPTEN) - # Emscripten default is GLFW 2.x but we use GLFW 3.x - set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3") + # Emscripten default is GLFW 2.x but we use GLFW 3.x, also include data files + set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3 --embed-file ../shaders/") endif () if (NOT EMSCRIPTEN) From 8fd7a41e1c55f38b87192208a5b36a1d76193591 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 22:09:34 -0700 Subject: [PATCH 11/17] Update readme to use 'build' directory for cmake, per convention --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b64397242..a64f0d90f 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,16 @@ terminal. git clone https://github.com/fogleman/Craft.git cd Craft - cmake . + mkdir build + pushd build + cmake .. make - ./craft + popd + ./build/craft To build for the web (experimental), install [Emscripten](http://emscripten.org) and instead run: - cmake -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake . + cmake -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake .. ### Multiplayer From 601a5c3e188df2d2dfb669ea6f106062cefc7e7d Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 22:36:22 -0700 Subject: [PATCH 12/17] GLSL shaders: remove version 120 to improve compatibility WebGL 1 only supports version 100, but OpenGL fails with '#version 100' so just remove the version and remove the use of new features in 120. See additions: https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions#glsl-120-additions --- shaders/block_fragment.glsl | 2 +- shaders/block_vertex.glsl | 6 +++--- shaders/line_fragment.glsl | 2 +- shaders/line_vertex.glsl | 2 +- shaders/sky_fragment.glsl | 2 +- shaders/sky_vertex.glsl | 2 +- shaders/text_fragment.glsl | 2 +- shaders/text_vertex.glsl | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/shaders/block_fragment.glsl b/shaders/block_fragment.glsl index 31092ab13..f8488f0d3 100644 --- a/shaders/block_fragment.glsl +++ b/shaders/block_fragment.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform sampler2D sampler; uniform sampler2D sky_sampler; diff --git a/shaders/block_vertex.glsl b/shaders/block_vertex.glsl index 30249e935..dd6b40779 100644 --- a/shaders/block_vertex.glsl +++ b/shaders/block_vertex.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform mat4 matrix; uniform vec3 camera; @@ -17,7 +17,7 @@ varying float fog_height; varying float diffuse; const float pi = 3.14159265; -const vec3 light_direction = normalize(vec3(-1.0, 1.0, -1.0)); +vec3 light_direction = normalize(vec3(-1.0, 1.0, -1.0)); void main() { gl_Position = matrix * position; @@ -34,6 +34,6 @@ void main() { fog_factor = pow(clamp(camera_distance / fog_distance, 0.0, 1.0), 4.0); float dy = position.y - camera.y; float dx = distance(position.xz, camera.xz); - fog_height = (atan(dy, dx) + pi / 2) / pi; + fog_height = (atan(dy, dx) + pi / 2.0) / pi; } } diff --git a/shaders/line_fragment.glsl b/shaders/line_fragment.glsl index 5e21117d9..e79b2533e 100644 --- a/shaders/line_fragment.glsl +++ b/shaders/line_fragment.glsl @@ -1,4 +1,4 @@ -#version 120 + void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/shaders/line_vertex.glsl b/shaders/line_vertex.glsl index 8ccd4b598..69226b2cb 100644 --- a/shaders/line_vertex.glsl +++ b/shaders/line_vertex.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform mat4 matrix; diff --git a/shaders/sky_fragment.glsl b/shaders/sky_fragment.glsl index 258289666..f3308fde9 100644 --- a/shaders/sky_fragment.glsl +++ b/shaders/sky_fragment.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform sampler2D sampler; uniform float timer; diff --git a/shaders/sky_vertex.glsl b/shaders/sky_vertex.glsl index fe79e517b..34cd5af82 100644 --- a/shaders/sky_vertex.glsl +++ b/shaders/sky_vertex.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform mat4 matrix; diff --git a/shaders/text_fragment.glsl b/shaders/text_fragment.glsl index 25ee603a9..961469c33 100644 --- a/shaders/text_fragment.glsl +++ b/shaders/text_fragment.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform sampler2D sampler; uniform bool is_sign; diff --git a/shaders/text_vertex.glsl b/shaders/text_vertex.glsl index b842ae9e1..70502c8c2 100644 --- a/shaders/text_vertex.glsl +++ b/shaders/text_vertex.glsl @@ -1,4 +1,4 @@ -#version 120 + uniform mat4 matrix; From d6869aa43ffbf0f706587d6ceac3e2fa2d23071b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 23:05:10 -0700 Subject: [PATCH 13/17] Specify float precision required for WebGL --- shaders/block_fragment.glsl | 4 +++- shaders/block_vertex.glsl | 4 +++- shaders/line_fragment.glsl | 4 +++- shaders/line_vertex.glsl | 4 +++- shaders/sky_fragment.glsl | 4 +++- shaders/sky_vertex.glsl | 4 +++- shaders/text_fragment.glsl | 4 +++- shaders/text_vertex.glsl | 4 +++- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/shaders/block_fragment.glsl b/shaders/block_fragment.glsl index f8488f0d3..ee3e00ac3 100644 --- a/shaders/block_fragment.glsl +++ b/shaders/block_fragment.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform sampler2D sampler; uniform sampler2D sky_sampler; diff --git a/shaders/block_vertex.glsl b/shaders/block_vertex.glsl index dd6b40779..b88f6b555 100644 --- a/shaders/block_vertex.glsl +++ b/shaders/block_vertex.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform mat4 matrix; uniform vec3 camera; diff --git a/shaders/line_fragment.glsl b/shaders/line_fragment.glsl index e79b2533e..c56883b4a 100644 --- a/shaders/line_fragment.glsl +++ b/shaders/line_fragment.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/shaders/line_vertex.glsl b/shaders/line_vertex.glsl index 69226b2cb..6e1a7e92e 100644 --- a/shaders/line_vertex.glsl +++ b/shaders/line_vertex.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform mat4 matrix; diff --git a/shaders/sky_fragment.glsl b/shaders/sky_fragment.glsl index f3308fde9..4b40bc2bd 100644 --- a/shaders/sky_fragment.glsl +++ b/shaders/sky_fragment.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform sampler2D sampler; uniform float timer; diff --git a/shaders/sky_vertex.glsl b/shaders/sky_vertex.glsl index 34cd5af82..aa78202a3 100644 --- a/shaders/sky_vertex.glsl +++ b/shaders/sky_vertex.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform mat4 matrix; diff --git a/shaders/text_fragment.glsl b/shaders/text_fragment.glsl index 961469c33..a69a6723a 100644 --- a/shaders/text_fragment.glsl +++ b/shaders/text_fragment.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform sampler2D sampler; uniform bool is_sign; diff --git a/shaders/text_vertex.glsl b/shaders/text_vertex.glsl index 70502c8c2..1d1b64d99 100644 --- a/shaders/text_vertex.glsl +++ b/shaders/text_vertex.glsl @@ -1,4 +1,6 @@ - +#ifdef GL_ES +precision mediump float; +#endif uniform mat4 matrix; From 6303def57bb292d52f4a79c53a089601d2e21486 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 23:24:35 -0700 Subject: [PATCH 14/17] Add int precision for glsl to fix: Uniforms with the same name but different type/precision: ortho --- shaders/block_fragment.glsl | 1 + shaders/block_vertex.glsl | 1 + 2 files changed, 2 insertions(+) diff --git a/shaders/block_fragment.glsl b/shaders/block_fragment.glsl index ee3e00ac3..4d0f1d1f7 100644 --- a/shaders/block_fragment.glsl +++ b/shaders/block_fragment.glsl @@ -1,5 +1,6 @@ #ifdef GL_ES precision mediump float; +precision mediump int; #endif uniform sampler2D sampler; diff --git a/shaders/block_vertex.glsl b/shaders/block_vertex.glsl index b88f6b555..1ea677b54 100644 --- a/shaders/block_vertex.glsl +++ b/shaders/block_vertex.glsl @@ -1,5 +1,6 @@ #ifdef GL_ES precision mediump float; +precision mediump int; #endif uniform mat4 matrix; From 16868e520ed91699aefc6faa346e8bf5a3988ed3 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 23:27:04 -0700 Subject: [PATCH 15/17] Embed texture files for Emscripten --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c66b2aa1..14a4f1450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ add_definitions(-std=c99 -O3) if (EMSCRIPTEN) # Emscripten default is GLFW 2.x but we use GLFW 3.x, also include data files - set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3 --embed-file ../shaders/") + set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3 --embed-file ../shaders/ --embed-file ../textures/") endif () if (NOT EMSCRIPTEN) From 603fd1e34615b76fece1edfc743ceba143a28a8b Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sat, 1 Apr 2017 23:29:41 -0700 Subject: [PATCH 16/17] Increase Emscripten memory from 16M to 32M - finally, it renders! --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14a4f1450..c44acffa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ add_definitions(-std=c99 -O3) if (EMSCRIPTEN) # Emscripten default is GLFW 2.x but we use GLFW 3.x, also include data files - set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3 --embed-file ../shaders/ --embed-file ../textures/") + set_target_properties(craft PROPERTIES LINK_FLAGS "-s USE_GLFW=3 --embed-file ../shaders/ -s TOTAL_MEMORY=33554432 --embed-file ../textures/") endif () if (NOT EMSCRIPTEN) From d863daf0a20f8183a542e2b3f9d0c172ae5f06cc Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Sun, 2 Apr 2017 11:02:34 -0700 Subject: [PATCH 17/17] Emscripten generates .html wrapper not only .js --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c44acffa4..fc117df4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ if (EMSCRIPTEN) deps/noise/noise.c deps/sqlite/sqlite3.c deps/tinycthread/tinycthread.c) + # Generate HTML file wrapper in addition to .js + set(CMAKE_EXECUTABLE_SUFFIX ".html") else () add_executable( craft