void *ThreadMain(void *arg)
{
  printf("Thread started. You should see the WebGL canvas fade from black to red.\n");
  EmscriptenWebGLContextAttributes attr;
  emscripten_webgl_init_context_attributes(&attr);
  attr.explicitSwapControl = EM_TRUE;
  ctx = emscripten_webgl_create_context(0, &attr);
  emscripten_webgl_make_context_current(ctx);

  double color = 0;
  for(int i = 0; i < 100; ++i)
  {
    color += 0.01;
    glClearColor(color, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    EMSCRIPTEN_RESULT r = emscripten_webgl_commit_frame();
    assert(r == EMSCRIPTEN_RESULT_SUCCESS);

    double now = emscripten_get_now();
    while(emscripten_get_now() - now < 16) /*no-op*/;
  }

  emscripten_webgl_make_context_current(0);
  emscripten_webgl_destroy_context(ctx);
  emscripten_atomic_store_u32(&threadRunning, 0);
  printf("Thread quit\n");
  pthread_exit(0);
}
Example #2
0
static void
_cg_winsys_display_destroy(cg_display_t *display)
{
    cg_webgl_display_t *webgl_display = display->winsys;

    c_return_if_fail(webgl_display != NULL);

    if (webgl_display->context > 0)
        emscripten_webgl_destroy_context(webgl_display->context);

    if (webgl_display->window > 0)
        CGlib_Emscripten_DestroyWindow(webgl_display->window);

    c_free(webgl_display->window_id);

    c_slice_free(cg_webgl_display_t, display->winsys);
    display->winsys = NULL;
}