1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <GLES2/gl2.h>
#include <math.h>
#include <assert.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#include <emscripten/threading.h>
#include <bits/errno.h>
#include <stdlib.h>
int main()
{
if (!emscripten_supports_offscreencanvas())
{
printf("Current browser does not support OffscreenCanvas. Skipping this test.\n");
return 0;
}
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
printf("Created context with handle %u\n", (unsigned int)ctx);
emscripten_webgl_make_context_current(ctx);
printf("You should see the canvas fade from black to red.\n");
double color = 0;
for(int i = 0; i < 100; ++i)
{
color += 0.01;
glClearColor(color, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
#if ASYNCIFY
emscripten_sleep(16);
#else
double now = emscripten_get_now();
while(emscripten_get_now() - now < 16) /*no-op*/;
#endif
}
emscripten_webgl_make_context_current(0);
emscripten_webgl_destroy_context(ctx);
printf("Thread quit\n");
return 0;
}
|