redblobgames / helloworld-sdl2-opengl-emscripten

Basic program that uses SDL2+OpenGL, compiling both locally and via emscripten

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the hello world.

tangyiyang opened this issue · comments

I have build the project and can run the hello world natively, but the emscripten may wrong.

It keeps showing the message:

Downloading data...

here is the log, I guess the build procedure self is success.

em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c main.cc -o build/main.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c glwrappers.cc -o build/glwrappers.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c window.cc -o build/window.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c atlas.cc -o build/atlas.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c font.cc -o build/font.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c render-sprites.cc -o build/render-sprites.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c render-surface.cc -o build/render-surface.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c render-imgui.cc -o build/render-imgui.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c imgui/imgui.cc -o build/imgui/imgui.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c imgui/imgui_draw.cc -o build/imgui/imgui_draw.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -c imgui/imgui_demo.cc -o build/imgui/imgui_demo.em.o
em++ -std=c++11 -Oz -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s TOTAL_MEMORY=50331648 build/main.em.o build/glwrappers.em.o build/window.em.o build/atlas.em.o build/font.em.o build/render-sprites.em.o build/render-surface.em.o build/render-imgui.em.o build/imgui/imgui.em.o build/imgui/imgui_draw.em.o build/imgui/imgui_demo.em.o --preload-file assets/red-blob.png --preload-file assets/DroidSans.ttf -o html/_main.js
cp emscripten-shell.html html/index.html

BTW: I have install the emscripten manually, and export the emscripten to the PATH, do I have to install emscripten from brew or source code?

thanks, :)

Hi tangyiyang, one thing to check: some browsers will only let you load the page through http:// urls and it will not work through file:// urls.

You might also look at the browser's javascript console to see if it shows any errors.

With the current version of emscripten I'm having an error loading the PNG image :-( I'm not yet sure how to fix this.

That's really help. Thank you.

I installed a nginx on my machine and make a http request to /helloworld-sdl2-opengl-emscripten/html,
but have the problem below.

Unable to load image failed : Unsupported image formatModule.printErr @ index.html:66
http://localhost:8080/favicon.ico Failed to load resource: the server responded with a status of 502 (Bad Gateway)

:(

I'm having the same problem right now. It used to work, before I updated emscripten to a newer version :(, so I should probably go back to an older version and see what happens. The workaround would be to load a BMP file instead of a PNG, because BMP is supported directly by SDL and PNG requires SDL_Image.

Since I'm having trouble with images in emscripten, I added a non-image shape renderer module that you might try out. In main.cc, set SHOW_SPRITES to 0 and SHOW_SHAPES to 1 to see the shape renderer. It should work in emscripten.

I'm not actually using images in my emscripten project right now so debugging the image issue has been low on my list — sorry :(

That's really help a lot, I'm trying to read the documents of SDL and emscripten, your example really helps me a a lot. 👍

It looks like emscripten made some changes emscripten-core/emscripten#3831 and now we need the --use-preload-plugins option. I have updated the makefile.