create webGL context in javascript and use it in CPP code. possible?

36 views
Skip to first unread message

nevo natan

unread,
Jul 7, 2019, 7:51:42 AM7/7/19
to emscripten-discuss

I am trying create webGL canvas and context in Javascript:

var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var buffer = gl.createBuffer();

and then use it in my cpp:

// EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);...
glGenBuffers(1, &vb);

but without emscripten_webgl_create_context  I always get 

Uncaught (in promise) TypeError: Cannot read property 'createBuffer' of undefined
    at __glGenObject (output.js:1)

if I use emscripten_webgl_create_context all works well.

what am I doing wrong? Help much appreciated!

Shachar Langbeheim

unread,
Jul 7, 2019, 9:02:18 AM7/7/19
to emscripten-discuss
As you said, the thing you're doing wrong is not calling emscripten_webgl_create_context. As far as I understand, emscripten uses JS's webGL context (and textures, and other objects) behind the screen, so you have to register the context you're using with emscripten in order for it to transform your OpenGL calls to calls on the relevant WebGL objects.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/b51bce37-a3f4-4472-8e78-eb6de7e59b9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages