Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
How to pass data from WebAssembly OpenGL application to JavaScript?

I want to create a simple dialog in a browser that takes button click as input using WebAssembly.

I have succeeded creating an application using OpenGL, SDL2, and imGui and ported it to JavaScript using Emscripten. But I have problems passing data from the WebAssembly OpenGL application to JavaScript.

How can I pass data from C++ to Javascript to acknowledge the web page that users have done some actions (ex: Clicking "OK" button)?

I've tried to stop the Emscripten run loop using emscripten_cancel_main_loop. And the application just freezes on the web page.
I'm trying to emit events from C++ to JavaScript but couldn't figure out how it works.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

After several attempts, I've come to an approach to dispatch CustomEvent from WebAssembly to my Web page.

The function that was used to send data looks like this:

EM_JS(void, sendData, (int data), {
    window.dispatchEvent(
        new CustomEvent("fromWASM", {
            detail: {
                data: data
            }
        })
    );
});

Then call sendData() directly on C++ code as if it was a normal C++ function.

Finally, we'll need to listen to the event on the JavaScript side with addEventListener:

window.addEventListener('fromWASM', (event) => {
    console.log(event.detail);
});

I'm also wondering can we pass messages from the web page to the OpenGL application?

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda