Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/extensions/Xrender.h>
- #include <stdlib.h>
- #include <math.h>
- #include <stdlib.h>
- #include <sys/time.h>
- Display *display;
- int screen;
- Window root, window;
- XEvent event;
- Pixmap sourcePixmap;
- Picture sourcePicture;
- Pixmap maskPixmap;
- Picture maskPicture;
- /*Creates source picture*/
- Picture createSourcePicture()
- {
- XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardRGB24);
- sourcePixmap = XCreatePixmap(display, window, 100, 100, 24);
- XRenderPictureAttributes pict_attr;
- Picture picture = XRenderCreatePicture(display, sourcePixmap, fmt, 0, &pict_attr);
- XRenderColor yellow={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff};
- XRenderFillRectangle (display, PictOpSrc, picture, &yellow, 0, 0, 1000, 1000);
- return picture;
- }
- /*Creates mask picture*/
- Picture createMaskPicture()
- {
- XRenderPictFormat *fmt = XRenderFindStandardFormat(display, PictStandardA8);
- maskPixmap = XCreatePixmap(display, window, 1, 1, 8);
- XRenderPictureAttributes pict_attr;
- Picture picture = XRenderCreatePicture(display, maskPixmap, fmt, 0, &pict_attr);
- XRenderColor yellow={.red=0xffff, .green=0xffff, .blue=0, .alpha=0xffff};
- XRenderFillRectangle (display, PictOpSrc, picture, &yellow, 0, 0, 1000, 1000);
- return picture;
- }
- int main(int argc, char *argv[])
- {
- /*Bosing initialization stuff*/
- display=XOpenDisplay(NULL);
- int render_event_base, render_error_base;
- int render_present=XRenderQueryExtension(display, &render_event_base, &render_error_base);
- if (!render_present) {
- fprintf(stderr, "RENDER extension missing!\n");
- abort();
- }
- XRenderPictFormat *fmt=XRenderFindStandardFormat(display, PictStandardRGB24);
- screen=DefaultScreen(display);
- root=DefaultRootWindow(display);
- window = XCreateWindow(display, root, 0, 0, 640, 480, 0,
- DefaultDepth(display, screen), InputOutput,
- DefaultVisual(display, screen),
- 0, NULL);
- XRenderPictureAttributes pict_attr;
- pict_attr.poly_edge=PolyEdgeSmooth;
- pict_attr.poly_mode=PolyModeImprecise;
- Picture picture=XRenderCreatePicture(display, window, fmt, CPPolyEdge|CPPolyMode, &pict_attr);
- XSelectInput(display, window, KeyPressMask|KeyReleaseMask|ExposureMask
- |ButtonPressMask|StructureNotifyMask);
- /* now make the window visible */
- XMapWindow(display, window);
- XRenderColor color_white = {.red=0xffff, .green=0xffff, .blue=0xffff, .alpha=0xffff};
- sourcePicture = createSourcePicture();
- maskPicture = createMaskPicture();
- XRenderSetPictureFilter(display, sourcePicture, "fast", NULL, 0);
- XRenderSetPictureFilter(display, maskPicture, "fast", NULL, 0);
- XTransform xf;
- xf.matrix[0][0] = XDoubleToFixed(0.438791280945186);
- xf.matrix[0][1] = XDoubleToFixed(0.239712769302102);
- xf.matrix[0][2] = XDoubleToFixed(-13.755117572194017);
- xf.matrix[1][0] = XDoubleToFixed(-0.239712769302102);
- xf.matrix[1][1] = XDoubleToFixed(0.438791280945186);
- xf.matrix[1][2] = XDoubleToFixed(7.343992411903851);
- xf.matrix[2][0] = 0;
- xf.matrix[2][1] = 0;
- xf.matrix[2][2] = 1<<16;
- XRenderSetPictureTransform (display, sourcePicture, &xf);
- xf.matrix[0][0] = XDoubleToFixed(0.013712227529537);
- xf.matrix[0][1] = XDoubleToFixed(0.007491024040691);
- xf.matrix[0][2] = XDoubleToFixed(-0.429847424131063);
- xf.matrix[1][0] = XDoubleToFixed(-0.007491024040691);
- xf.matrix[1][1] = XDoubleToFixed(0.013712227529537);
- xf.matrix[1][2] = XDoubleToFixed(0.229499762871995);
- xf.matrix[2][0] = 0;
- xf.matrix[2][1] = 0;
- xf.matrix[2][2] = 1<<16;
- XRenderSetPictureTransform (display, maskPicture, &xf);
- while(1) {
- XNextEvent(display, &event);
- switch(event.type) {
- case Expose:
- {
- XRenderFillRectangle(display, PictOpOver,
- picture, &color_white, 0, 0, 1000, 1000);
- XRenderComposite (display, PictOpOver, sourcePicture, maskPicture, picture, 0, 0, 0, 0, 0, 0, 500, 500);
- break;
- case DestroyNotify:
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement