emscripten-core / emscripten-core/emscripten

Unable to create WebGL2 context using GLFW, and I can't find any example code for doing this with GLFW with Emscripten

Open
#20,363 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I'm pulling my hair out trying to get a basic "HelloTriangle" shader example working with WebGL2 and GLFW. The code works natively (OpenGL ES 3), but when I try to run the Emscripten version I get errors about "storage qualifier supported in GLSL ES 3.00 and above only" and "Floating-point suffix unsupported prior to GLSL ES 3.00" which leads me to believe I'm still getting a WebGL 1 context.

I did get a similar thing to work using the webgl_sample_query.cpp file from the Emscripten tests; the problem is that that sample doesn't use GLFW to create the context, and the GLFW boilerplate is different enough to that sample's boilerplate that I can't easily see how to merge the two. I did try copying some code over (you'll see in main.cpp), but it has no effect.

Based on all I've read it should (?) "just work" using the GLFW boilerplate, but this doesn't (apparently) result in a WebGL2 context. I thought, maybe I could just read the source code and see what needs to be passed to make GLFW hit the happy path of creating a WebGL2 enabled context, but I can't figure out where this source code file is. Because presumably when Emscripten is passed "-s USE_GLFW=3" that is using some custom version of GLFW built in to Emscripten. (That's also why I'm reporting this as a bug on the Emscripten repository and not against the GLFW project.)

The "Optimizing WebGL" page in the Emscripten docs gives a lot of different options based on different compatibility scenarios, but I'd really appreciate a succinct "here's all the compile options" and "here's all the link options" one **should** be using for **new** code for WebGL2.

Moreover if Emscripten supports GLFW, and Emscripten supports WebGL2, and GLFW supports OpenGL ES3, does Emscripten support WebGL2 _using_ GLFW? If the answer is no, you might want to put a warning about that gotcha in the documentation. If the answer is yes, where's the example code?

Thanks.

I've attached the code I'm using (it's not very long):
[CMakeLists.txt](https://github.com/emscripten-core/emscripten/files/12775830/CMakeLists.txt)
[main.cpp.txt](https://github.com/emscripten-core/emscripten/files/12775835/main.cpp.txt)
[webgl_sample_query.cpp.txt](https://github.com/emscripten-core/emscripten/files/12775836/webgl_sample_query.cpp.txt)

Output of emcc -v:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.22 (a9981ae2a7dc3c45f833d0b2202f739d87ac05c8)
clang version 16.0.0 (https://github.com/llvm/llvm-project 8491d01cc385d08b8b4f5dd097239ea0009ddc63)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.