/* * author: Ryan O'Hara * Code licensed under the GPL. see FSF for license text. */ #include #include #include #include #include #define GLITZ_GLX_BACKEND 1 #ifdef GLITZ_GLX_BACKEND #include #include #endif int main() { Display *disp; XVisualInfo *visinfo; Window root,win; XSetWindowAttributes attr; XEvent event; cairo_t *cr; cairo_surface_t *crsurface; glitz_drawable_t *drawable; glitz_drawable_format_t *dformat; glitz_drawable_format_t dformtemp; glitz_surface_t *gsurface; glitz_format_t *format; unsigned int mask; int x,y; int i,j; x = 500; /* witdh */ y = 500; /* height */ /* open the display */ disp = XOpenDisplay(NULL); if( disp == NULL ) goto out; printf("display %s\n", XDisplayName( NULL )); root = RootWindow(disp, 0); if( !root ) goto out; glitz_glx_init(NULL); dformtemp.types.window = 1; dformtemp.doublebuffer = 0; mask = GLITZ_FORMAT_WINDOW_MASK; dformat = glitz_glx_find_drawable_format (disp, DefaultScreen(disp), mask, &dformtemp, 0); if (!dformat) goto out; visinfo = glitz_glx_get_visual_info_from_format (disp, DefaultScreen(disp), dformat); if(visinfo == NULL) goto out; /* create the window */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(disp, root, visinfo->visual, AllocNone); if( !attr.colormap ) goto out; /* win = XCreateWindow(disp, root, 0, 0, x, y, 0, visinfo->depth, InputOutput, visinfo->visual, CWColormap, &attr); */ win = XCreateSimpleWindow( disp, root, 0, 0, x, y, 0, 0, BlackPixel(disp, 0)); if( !win ) goto out; /* display the window */ XMapWindow(disp, win); drawable = glitz_glx_create_drawable_for_window( disp, DefaultScreen(disp), dformat, win, x, y); if (!drawable) { fprintf (stderr, "Error: couldn't create glitz drawable for window\n"); return -1; } format = glitz_find_standard_format( drawable, GLITZ_STANDARD_ARGB32 ); if( !format ) goto out; gsurface = glitz_surface_create( drawable, format, x, y, 0, NULL); if( !gsurface ) goto out; glitz_surface_attach( gsurface, drawable, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR, 0, 0); crsurface = cairo_glitz_surface_create( gsurface ); //crsurface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, x, y); if( !crsurface ) goto out; cr = cairo_create( crsurface ); /* never returns NULL */ cairo_set_source_rgba( cr, 1, 1, 0, 1); cairo_set_line_width( cr, .5); cairo_move_to (cr, 250, 10); cairo_line_to (cr, 100, 10); cairo_stroke (cr); /* run "pen" over the path */ cairo_move_to (cr, 250, 100); cairo_line_to (cr, 100, 100); cairo_stroke (cr); cairo_set_source_rgba( cr, 1, 0, 0, 1); cairo_set_line_width(cr, .5); cairo_rectangle(cr, 150, 200, 50, 50); cairo_save(cr); cairo_fill_preserve(cr); cairo_restore(cr); cairo_stroke(cr); printf("cairo status: %s\n", cairo_status_to_string( cairo_status(cr) )); sleep(5); cairo_destroy(cr); return 0; out: printf("error cairo status: %s\n", cairo_status_to_string( cairo_status(cr) )); return -1; }