diff --git a/demos/html5/MAKE.bat b/demos/html5/MAKE.bat index d34226c..c447f43 100644 --- a/demos/html5/MAKE.bat +++ b/demos/html5/MAKE.bat @@ -49,7 +49,7 @@ if not exist "emsdk" ( if "%EMSDK%"=="" call emsdk\emsdk_env.bat --system rem cook art -..\..\tools\cook.exe --cook-jobs=1 --cook-ini=..\..\tools\cook_web.ini +..\..\tools\cook.exe --cook-jobs=1 --cook-ini=..\..\tools\cook.ini rem host webserver, compile and launch rem start python -m http.server --bind 127.0.0.1 8000 diff --git a/demos/html5/demo_collide.c b/demos/html5/demo_collide.c index 56b9368..b3c1bdd 100644 --- a/demos/html5/demo_collide.c +++ b/demos/html5/demo_collide.c @@ -14,7 +14,6 @@ void game_loop(void *userdata) { // key handler // if (input_down(KEY_F11) ) window_fullscreen( window_has_fullscreen()^1 ); // if (input_down(KEY_ESC) ) window_loop_exit(); // @todo: break -> window_close() - window_resize(); // animation static float dx = 0, dy = 0; @@ -602,7 +601,7 @@ void game_loop(void *userdata) { int main(void) { // 75% sized, msaa x4 enabled - window_create(0.75f, WINDOW_MSAA4); + window_create(0.75f, WINDOW_MSAA4/*|WINDOW_FIXED*/); window_title( "V4K - SPACE pauses simulation" ); // fx_load("fx**.fs"); diff --git a/demos/html5/template.html b/demos/html5/template.html index 12bef2c..0a0fcbe 100644 --- a/demos/html5/template.html +++ b/demos/html5/template.html @@ -104,8 +104,10 @@ canvas.height = window.innerHeight; window.addEventListener('resize', () => { - canvas.width = window.innerWidth; - canvas.height = window.innerHeight; + if (canvas.canResize) { + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + } }) return canvas; })(), diff --git a/engine/bind/v4k.lua b/engine/bind/v4k.lua index 16028b1..02bc5fb 100644 --- a/engine/bind/v4k.lua +++ b/engine/bind/v4k.lua @@ -2869,7 +2869,6 @@ WINDOW_VSYNC_DISABLED =8192, int window_swap(); void window_loop(void (*function)(void* loopArg), void* loopArg ); void window_loop_exit(); - void window_resize(); void window_title(const char *title); void window_icon(const char *file_icon); void window_color(unsigned color); diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 7f4a6fb..5966866 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -17326,7 +17326,6 @@ API int window_swap(); // single function that combines above functions (de API void window_loop(void (*function)(void* loopArg), void* loopArg ); // run main loop function continuously (emscripten only) API void window_loop_exit(); // exit from main loop function (emscripten only) -API void window_resize(); // resize if canvas size has changed (emscripten only) API void window_title(const char *title); API void window_icon(const char *file_icon); @@ -348962,6 +348961,7 @@ static int locked_aspect_ratio = 0; struct app { GLFWwindow *window; int width, height, keep_running; + unsigned flags; struct nk_context *ctx; struct nk_glfw *nk_glfw; @@ -349055,6 +349055,8 @@ void window_hints(unsigned flags) { if(flags & WINDOW_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA + + g->flags = flags; } struct nk_glfw *window_handle_nkglfw() { @@ -349436,9 +349438,31 @@ int window_swap() { static void (*window_render_callback)(void* loopArg); +static vec2 last_canvas_size; + +static +void window_resize() { +#if is(ems) + EM_ASM(canvas.canResize = 0); + if (g->flags&WINDOW_FIXED) return; + EM_ASM(canvas.canResize = 1); + vec2 size = window_canvas(); + do_once last_canvas_size = size; + if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { + w = size.x; + h = size.y; + g->width = w; + g->height = h; + glfwSetWindowSize(g->window, w, h); + // emscripten_set_canvas_size(w, h); + } +#endif /* __EMSCRIPTEN__ */ +} + static void window_loop_wrapper( void *loopArg ) { if( window_frame_begin() ) { + window_resize(); window_render_callback(loopArg); window_frame_end(); window_frame_swap(); @@ -349479,23 +349503,6 @@ vec2 window_canvas() { #endif /* __EMSCRIPTEN__ */ } -static vec2 last_canvas_size; - -void window_resize() { -#if is(ems) - vec2 size = window_canvas(); - do_once last_canvas_size = size; - if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { - w = size.x; - h = size.y; - g->width = w; - g->height = h; - glfwSetWindowSize(g->window, w, h); - // emscripten_set_canvas_size(w, h); - } -#endif /* __EMSCRIPTEN__ */ -} - int window_width() { return w; } diff --git a/engine/split/v4k_window.c b/engine/split/v4k_window.c index 03d0b64..08ba120 100644 --- a/engine/split/v4k_window.c +++ b/engine/split/v4k_window.c @@ -114,6 +114,7 @@ static int locked_aspect_ratio = 0; struct app { GLFWwindow *window; int width, height, keep_running; + unsigned flags; struct nk_context *ctx; struct nk_glfw *nk_glfw; @@ -207,6 +208,8 @@ void window_hints(unsigned flags) { if(flags & WINDOW_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA + + g->flags = flags; } struct nk_glfw *window_handle_nkglfw() { @@ -588,9 +591,31 @@ int window_swap() { static void (*window_render_callback)(void* loopArg); +static vec2 last_canvas_size; + +static +void window_resize() { +#if is(ems) + EM_ASM(canvas.canResize = 0); + if (g->flags&WINDOW_FIXED) return; + EM_ASM(canvas.canResize = 1); + vec2 size = window_canvas(); + do_once last_canvas_size = size; + if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { + w = size.x; + h = size.y; + g->width = w; + g->height = h; + glfwSetWindowSize(g->window, w, h); + // emscripten_set_canvas_size(w, h); + } +#endif /* __EMSCRIPTEN__ */ +} + static void window_loop_wrapper( void *loopArg ) { if( window_frame_begin() ) { + window_resize(); window_render_callback(loopArg); window_frame_end(); window_frame_swap(); @@ -631,23 +656,6 @@ vec2 window_canvas() { #endif /* __EMSCRIPTEN__ */ } -static vec2 last_canvas_size; - -void window_resize() { -#if is(ems) - vec2 size = window_canvas(); - do_once last_canvas_size = size; - if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { - w = size.x; - h = size.y; - g->width = w; - g->height = h; - glfwSetWindowSize(g->window, w, h); - // emscripten_set_canvas_size(w, h); - } -#endif /* __EMSCRIPTEN__ */ -} - int window_width() { return w; } diff --git a/engine/split/v4k_window.h b/engine/split/v4k_window.h index ab10e8b..39f74d3 100644 --- a/engine/split/v4k_window.h +++ b/engine/split/v4k_window.h @@ -33,7 +33,6 @@ API int window_swap(); // single function that combines above functions (de API void window_loop(void (*function)(void* loopArg), void* loopArg ); // run main loop function continuously (emscripten only) API void window_loop_exit(); // exit from main loop function (emscripten only) -API void window_resize(); // resize if canvas size has changed (emscripten only) API void window_title(const char *title); API void window_icon(const char *file_icon); diff --git a/engine/v4k.c b/engine/v4k.c index 98ff3c9..8ffc898 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -19870,6 +19870,7 @@ static int locked_aspect_ratio = 0; struct app { GLFWwindow *window; int width, height, keep_running; + unsigned flags; struct nk_context *ctx; struct nk_glfw *nk_glfw; @@ -19963,6 +19964,8 @@ void window_hints(unsigned flags) { if(flags & WINDOW_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA + + g->flags = flags; } struct nk_glfw *window_handle_nkglfw() { @@ -20344,9 +20347,31 @@ int window_swap() { static void (*window_render_callback)(void* loopArg); +static vec2 last_canvas_size; + +static +void window_resize() { +#if is(ems) + EM_ASM(canvas.canResize = 0); + if (g->flags&WINDOW_FIXED) return; + EM_ASM(canvas.canResize = 1); + vec2 size = window_canvas(); + do_once last_canvas_size = size; + if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { + w = size.x; + h = size.y; + g->width = w; + g->height = h; + glfwSetWindowSize(g->window, w, h); + // emscripten_set_canvas_size(w, h); + } +#endif /* __EMSCRIPTEN__ */ +} + static void window_loop_wrapper( void *loopArg ) { if( window_frame_begin() ) { + window_resize(); window_render_callback(loopArg); window_frame_end(); window_frame_swap(); @@ -20387,23 +20412,6 @@ vec2 window_canvas() { #endif /* __EMSCRIPTEN__ */ } -static vec2 last_canvas_size; - -void window_resize() { -#if is(ems) - vec2 size = window_canvas(); - do_once last_canvas_size = size; - if (size.x != last_canvas_size.x || size.y != last_canvas_size.y) { - w = size.x; - h = size.y; - g->width = w; - g->height = h; - glfwSetWindowSize(g->window, w, h); - // emscripten_set_canvas_size(w, h); - } -#endif /* __EMSCRIPTEN__ */ -} - int window_width() { return w; } diff --git a/engine/v4k.h b/engine/v4k.h index 2ddd4a8..681a4fc 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -3409,7 +3409,6 @@ API int window_swap(); // single function that combines above functions (de API void window_loop(void (*function)(void* loopArg), void* loopArg ); // run main loop function continuously (emscripten only) API void window_loop_exit(); // exit from main loop function (emscripten only) -API void window_resize(); // resize if canvas size has changed (emscripten only) API void window_title(const char *title); API void window_icon(const char *file_icon);