fwk: sync + window: em fix resize + support fixed resize
parent
a20b0b73ad
commit
afd2399ec0
|
@ -49,7 +49,7 @@ if not exist "emsdk" (
|
||||||
if "%EMSDK%"=="" call emsdk\emsdk_env.bat --system
|
if "%EMSDK%"=="" call emsdk\emsdk_env.bat --system
|
||||||
|
|
||||||
rem cook art
|
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 host webserver, compile and launch
|
||||||
rem start python -m http.server --bind 127.0.0.1 8000
|
rem start python -m http.server --bind 127.0.0.1 8000
|
||||||
|
|
|
@ -14,7 +14,6 @@ void game_loop(void *userdata) {
|
||||||
// key handler
|
// key handler
|
||||||
// if (input_down(KEY_F11) ) window_fullscreen( window_has_fullscreen()^1 );
|
// if (input_down(KEY_F11) ) window_fullscreen( window_has_fullscreen()^1 );
|
||||||
// if (input_down(KEY_ESC) ) window_loop_exit(); // @todo: break -> window_close()
|
// if (input_down(KEY_ESC) ) window_loop_exit(); // @todo: break -> window_close()
|
||||||
window_resize();
|
|
||||||
|
|
||||||
// animation
|
// animation
|
||||||
static float dx = 0, dy = 0;
|
static float dx = 0, dy = 0;
|
||||||
|
@ -602,7 +601,7 @@ void game_loop(void *userdata) {
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
// 75% sized, msaa x4 enabled
|
// 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" );
|
window_title( "V4K - SPACE pauses simulation" );
|
||||||
|
|
||||||
// fx_load("fx**.fs");
|
// fx_load("fx**.fs");
|
||||||
|
|
|
@ -104,8 +104,10 @@
|
||||||
canvas.height = window.innerHeight;
|
canvas.height = window.innerHeight;
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
canvas.width = window.innerWidth;
|
if (canvas.canResize) {
|
||||||
canvas.height = window.innerHeight;
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return canvas;
|
return canvas;
|
||||||
})(),
|
})(),
|
||||||
|
|
|
@ -2869,7 +2869,6 @@ WINDOW_VSYNC_DISABLED =8192,
|
||||||
int window_swap();
|
int window_swap();
|
||||||
void window_loop(void (*function)(void* loopArg), void* loopArg );
|
void window_loop(void (*function)(void* loopArg), void* loopArg );
|
||||||
void window_loop_exit();
|
void window_loop_exit();
|
||||||
void window_resize();
|
|
||||||
void window_title(const char *title);
|
void window_title(const char *title);
|
||||||
void window_icon(const char *file_icon);
|
void window_icon(const char *file_icon);
|
||||||
void window_color(unsigned color);
|
void window_color(unsigned color);
|
||||||
|
|
|
@ -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(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_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_title(const char *title);
|
||||||
API void window_icon(const char *file_icon);
|
API void window_icon(const char *file_icon);
|
||||||
|
@ -348962,6 +348961,7 @@ static int locked_aspect_ratio = 0;
|
||||||
struct app {
|
struct app {
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
int width, height, keep_running;
|
int width, height, keep_running;
|
||||||
|
unsigned flags;
|
||||||
|
|
||||||
struct nk_context *ctx;
|
struct nk_context *ctx;
|
||||||
struct nk_glfw *nk_glfw;
|
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_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA
|
||||||
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
||||||
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
||||||
|
|
||||||
|
g->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_glfw *window_handle_nkglfw() {
|
struct nk_glfw *window_handle_nkglfw() {
|
||||||
|
@ -349436,9 +349438,31 @@ int window_swap() {
|
||||||
static
|
static
|
||||||
void (*window_render_callback)(void* loopArg);
|
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
|
static
|
||||||
void window_loop_wrapper( void *loopArg ) {
|
void window_loop_wrapper( void *loopArg ) {
|
||||||
if( window_frame_begin() ) {
|
if( window_frame_begin() ) {
|
||||||
|
window_resize();
|
||||||
window_render_callback(loopArg);
|
window_render_callback(loopArg);
|
||||||
window_frame_end();
|
window_frame_end();
|
||||||
window_frame_swap();
|
window_frame_swap();
|
||||||
|
@ -349479,23 +349503,6 @@ vec2 window_canvas() {
|
||||||
#endif /* __EMSCRIPTEN__ */
|
#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() {
|
int window_width() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ static int locked_aspect_ratio = 0;
|
||||||
struct app {
|
struct app {
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
int width, height, keep_running;
|
int width, height, keep_running;
|
||||||
|
unsigned flags;
|
||||||
|
|
||||||
struct nk_context *ctx;
|
struct nk_context *ctx;
|
||||||
struct nk_glfw *nk_glfw;
|
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_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA
|
||||||
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
||||||
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
||||||
|
|
||||||
|
g->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_glfw *window_handle_nkglfw() {
|
struct nk_glfw *window_handle_nkglfw() {
|
||||||
|
@ -588,9 +591,31 @@ int window_swap() {
|
||||||
static
|
static
|
||||||
void (*window_render_callback)(void* loopArg);
|
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
|
static
|
||||||
void window_loop_wrapper( void *loopArg ) {
|
void window_loop_wrapper( void *loopArg ) {
|
||||||
if( window_frame_begin() ) {
|
if( window_frame_begin() ) {
|
||||||
|
window_resize();
|
||||||
window_render_callback(loopArg);
|
window_render_callback(loopArg);
|
||||||
window_frame_end();
|
window_frame_end();
|
||||||
window_frame_swap();
|
window_frame_swap();
|
||||||
|
@ -631,23 +656,6 @@ vec2 window_canvas() {
|
||||||
#endif /* __EMSCRIPTEN__ */
|
#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() {
|
int window_width() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(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_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_title(const char *title);
|
||||||
API void window_icon(const char *file_icon);
|
API void window_icon(const char *file_icon);
|
||||||
|
|
42
engine/v4k.c
42
engine/v4k.c
|
@ -19870,6 +19870,7 @@ static int locked_aspect_ratio = 0;
|
||||||
struct app {
|
struct app {
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
int width, height, keep_running;
|
int width, height, keep_running;
|
||||||
|
unsigned flags;
|
||||||
|
|
||||||
struct nk_context *ctx;
|
struct nk_context *ctx;
|
||||||
struct nk_glfw *nk_glfw;
|
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_MSAA2) glfwWindowHint(GLFW_SAMPLES, 2); // x2 AA
|
||||||
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
if(flags & WINDOW_MSAA4) glfwWindowHint(GLFW_SAMPLES, 4); // x4 AA
|
||||||
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
if(flags & WINDOW_MSAA8) glfwWindowHint(GLFW_SAMPLES, 8); // x8 AA
|
||||||
|
|
||||||
|
g->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nk_glfw *window_handle_nkglfw() {
|
struct nk_glfw *window_handle_nkglfw() {
|
||||||
|
@ -20344,9 +20347,31 @@ int window_swap() {
|
||||||
static
|
static
|
||||||
void (*window_render_callback)(void* loopArg);
|
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
|
static
|
||||||
void window_loop_wrapper( void *loopArg ) {
|
void window_loop_wrapper( void *loopArg ) {
|
||||||
if( window_frame_begin() ) {
|
if( window_frame_begin() ) {
|
||||||
|
window_resize();
|
||||||
window_render_callback(loopArg);
|
window_render_callback(loopArg);
|
||||||
window_frame_end();
|
window_frame_end();
|
||||||
window_frame_swap();
|
window_frame_swap();
|
||||||
|
@ -20387,23 +20412,6 @@ vec2 window_canvas() {
|
||||||
#endif /* __EMSCRIPTEN__ */
|
#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() {
|
int window_width() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(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_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_title(const char *title);
|
||||||
API void window_icon(const char *file_icon);
|
API void window_icon(const char *file_icon);
|
||||||
|
|
Loading…
Reference in New Issue