emscripten_request_pointerlock() returns EMSCRIPTEN_RESULT_UNKNOWN_TARGET
-
I have made an example that calls
emscripten_request_pointerlock("screen", false);
by mouse click:void mousePressEvent(QMouseEvent *event) override { EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("screen", false); qDebug() << result; }
It prints -4 to the console that means
EMSCRIPTEN_RESULT_UNKNOWN_TARGET
.main.cpp
#include <QtGui/QMouseEvent> #include <QtGui/QOpenGLFunctions> #include <QtOpenGL/QOpenGLWindow> #include <QtWidgets/QApplication> #ifdef Q_OS_WASM #include <emscripten.h> #include <emscripten/html5.h> #endif class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions { public: OpenGLWindow() { setTitle("OpenGL ES 2.0, Qt6, C++"); resize(350, 350); } private: void mousePressEvent(QMouseEvent *event) override { EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("screen", false); qDebug() << result; } virtual void initializeGL() override { initializeOpenGLFunctions(); glClearColor(0.2f, 0.2f, 0.2f, 1.f); } virtual void paintGL() override { glClear(GL_COLOR_BUFFER_BIT); } }; int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL); QApplication app(argc, argv); OpenGLWindow w; w.show(); return app.exec(); }
pro
QT += core gui openglwidgets win32: LIBS += -lopengl32 CONFIG += c++17 wasm: INCLUDEPATH += "C:\emsdk\upstream\emscripten\cache\sysroot\include" SOURCES += \ main.cpp
-
The bug report was closed because
You need to handle this in a javascript mouse event and not a Qt mouse event
. I will continue here: https://forum.qt.io/topic/157373/emscripten_set_mousedown_callback-does-not-call-the-callback-function -
I use
screen
above because the Qt's html file has this element:<div id="screen"></div>
I have tried to useEMSCRIPTEN_EVENT_TARGET_DOCUMENT
instead ofscreen
but it returns -1 (it meansEMSCRIPTEN_RESULT_NOT_SUPPORTED
)EMSCRIPTEN_RESULT result = emscripten_request_pointerlock( EMSCRIPTEN_EVENT_TARGET_DOCUMENT, false); qDebug() << result;
-
-
I have created the bug report: https://bugreports.qt.io/browse/QTBUG-126513
-
Why cannot I set a mouse down callback from Qt's constructor? It prints nothing when I click:
EM_BOOL mouse_down_callback(int eventType, const EmscriptenMouseEvent *event, void *userData) { qDebug() << event->screenX << event->screenY; return 0; } class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions { public: OpenGLWindow() { setTitle("OpenGL ES 2.0, Qt6, C++"); resize(350, 350); emscripten_set_mousedown_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, mouse_down_callback ); }
-
The bug report was closed because
You need to handle this in a javascript mouse event and not a Qt mouse event
. I will continue here: https://forum.qt.io/topic/157373/emscripten_set_mousedown_callback-does-not-call-the-callback-function -