Example #1
0
int main() {
    if (!glfwInit()) {
        return -1;
    }

    window = glfwCreateWindow(640, 480, "test_glfw_cursor_disabled", NULL, NULL);
    if (!window) {
        glfwTerminate();
        return -1;
    }

    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

    if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) {
        // Browsers do not allow disabling the cursor (Pointer Lock) without a gesture.
        printf("FAIL: glfwGetInputMode returned GLFW_CURSOR_DISABLED prematurely\n");
        REPORT_RESULT(result);
        exit(1);
    }
    printf("Pass 1: glfwGetInputMode not prematurely returning cursor disabled\n");
    printf("Click within the canvas to activate Pointer Lock\n");

#ifdef __EMSCRIPTEN__
    emscripten_set_pointerlockchange_callback(NULL, NULL, 0, on_pointerlockchange);
    emscripten_set_main_loop(render, 0, 1);
#else
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
    }
#endif

    glfwTerminate();
    return 0;
}
Example #2
0
FHTML5Application::FHTML5Application()
    : GenericApplication( MakeShareable( new FHTML5Cursor() ) )
    , ApplicationWindow(FHTML5Window::Make())
    , InputInterface( FHTML5InputInterface::Create(MessageHandler, Cursor ) )
    , WarmUpTicks(-1)
{

#if PLATFORM_HTML5_BROWSER
    // full screen will only be requested after the first click after the window gains focus.
    // the problem is that because of security/UX reasons browsers don't allow pointer lock in main loop
    // but only through callbacks generated by browser.

    // work around emscripten bug where deffered browser requests are not called if there are no callbacks.
    emscripten_set_mousedown_callback("#canvas",0,1,mouse_callback);
    emscripten_set_pointerlockchange_callback(0,0,true,pointerlockchange_callback);
#endif

}