I've been struggling to port a simple C program that uses SDL2 for graphics to the web using emscripten. I scanned through example programs but was unable to find one that draws to the screen using SDL_RenderDrawPoint, SDL_RenderDrawLine, or SDL_RenderDrawRect. These functions work on the windows/ubuntu versions of my program, but not on the emscripten version. I simply see the screen painted with the cleared color, but nothing drawn to it.
Here's sample code that showcases the issue.
#include <stdio.h>
#include <SDL2/SDL.h>
#include <assert.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
int main(int argc, char* argv[])
{
// setup
SDL_Window * window;
SDL_Renderer * renderer;
assert(SDL_Init(SDL_INIT_VIDEO) == 0);
SDL_CreateWindowAndRenderer(640, 320, 0, &window, &renderer);
// clear screen with red color
SDL_SetRenderDrawColor(renderer, 200, 0, 0, 255);
SDL_RenderClear(renderer);
// draw green line across screen
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderDrawLine(renderer, 0, 0, 640, 320);
SDL_RenderPresent(renderer);
SDL_Delay(2000);
// free resources
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
I saved this code to main.c then ran:
emcc main.c -s USE_SDL=2 -o a.html
On Windows/Ubuntu, I see this:

On Emscripten (Chrome) I see this:

Is this a bug, or am I doing something wrong?