Created
January 24, 2014 16:29
-
-
Save anonymous/8600771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
#include <unistd.h> | |
#include <cairo-gl.h> | |
#ifndef M_PI | |
#define M_PI (3.14159265) | |
#endif | |
static EGLint eglDpyAttrs[] = { | |
EGL_RED_SIZE, 8, | |
EGL_GREEN_SIZE, 8, | |
EGL_BLUE_SIZE, 8, | |
EGL_DEPTH_SIZE, 24, | |
EGL_STENCIL_SIZE, 8, | |
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, | |
EGL_NONE | |
}; | |
static const EGLint eglCtxAttrs[] = { | |
EGL_CONTEXT_CLIENT_VERSION, 2, | |
EGL_NONE | |
}; | |
const int gWidth = 500; | |
const int gHeight = 500; | |
int main(int argc, char *argv[]) { | |
EGLDisplay display; | |
EGLint nConfigs; | |
EGLConfig config; | |
EGLSurface surface; | |
EGLContext context; | |
cairo_device_t* cd; | |
cairo_surface_t* cs; | |
cairo_t *cr; | |
Display *xDpy; | |
Window window; | |
double angle; | |
struct timeval start, now; | |
xDpy = XOpenDisplay(NULL); | |
window = XCreateSimpleWindow(xDpy, XDefaultRootWindow(xDpy), 0, 0, gWidth, gHeight, 0, 0, 0); | |
XMapWindow(xDpy, window); | |
display = eglGetDisplay(xDpy); | |
eglInitialize(display, NULL, NULL); | |
eglChooseConfig(display, eglDpyAttrs, &config, 1, &nConfigs); | |
eglBindAPI(EGL_OPENGL_ES_API); | |
context = eglCreateContext(display, config, NULL, eglCtxAttrs); | |
cd = cairo_egl_device_create(display, context); | |
surface = eglCreateWindowSurface(display, config, window, 0); | |
cs = cairo_gl_surface_create_for_egl(cd, surface, gWidth, gHeight); | |
gettimeofday(&start, NULL); | |
for(;;) { | |
cr = cairo_create(cs); | |
gettimeofday(&now, NULL); | |
angle = (now.tv_sec - start.tv_usec + (now.tv_usec-start.tv_usec)*1e-6) * M_PI/2; | |
cairo_set_source_rgba(cr, 1., 1., 1., 1.); | |
cairo_paint(cr); | |
cairo_set_source_rgba(cr, 0., 0., 0., 1.); | |
cairo_set_line_width (cr, 10.); | |
cairo_arc (cr, gWidth/2., gHeight/2., 100., angle, angle + M_PI/4); | |
cairo_stroke (cr); | |
cairo_destroy(cr); | |
cairo_gl_surface_swapbuffers(cs); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment