Browse Source

Various updates

master
Wesley Kerfoot 5 years ago
parent
commit
b0bab3a9d9
  1. 116
      blit.c

116
blit.c

@ -1,29 +1,60 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xcms.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
Display*
getDisplay() {
/* Get a display to use */
/* Currently just uses the default display */
Display *display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Could not open the display! :(\n");
exit(1);
}
return display;
}
XColor
getColor(unsigned short red,
unsigned short green,
unsigned short blue) {
/* Return a new XColor structure */
/* Initialize it with RGB */
XColor xcolor;
xcolor.red = red;
xcolor.green = green;
xcolor.blue = blue;
xcolor.flags = DoRed | DoGreen | DoBlue;
return xcolor;
}
int int
main(void) { main(void) {
Display *display;
Window window; Window window;
XEvent event; XEvent event;
const char *msg = "Hello, world!\n"; const char *msg = "Hello, world!\n";
int screen; XColor xcolor = getColor(0xffff, 0xffff, 0xffff);
// Opens the current display Display *display = getDisplay();
display = XOpenDisplay(NULL);
if (display == NULL) { int screen = DefaultScreen(display);
fprintf(stderr, "Could not open the display! :(\n");
exit(1);
}
printf("%p\n", display); GC gc = XDefaultGC(display, screen);
screen = DefaultScreen(display); XAllocColor(display,
XDefaultColormap(display, screen),
&xcolor);
window = XCreateSimpleWindow(display, window = XCreateSimpleWindow(display,
RootWindow(display, screen), RootWindow(display, screen),
@ -32,8 +63,8 @@ main(void) {
100, 100,
100, 100,
1, 1,
BlackPixel(display, screen), WhitePixel(display, screen),
WhitePixel(display, screen)); xcolor.pixel);
printf("%p\n", window); printf("%p\n", window);
@ -43,6 +74,23 @@ main(void) {
XMapWindow(display, window); XMapWindow(display, window);
int depth = DefaultDepth(display, DefaultScreen(display));
Pixmap pixmap;
pixmap = XCreatePixmap(display,
window,
100,
100,
depth);
int factor = 0;
struct timespec req;
struct timespec rem;
req.tv_sec = 0;
req.tv_nsec = 20000000;
while (1) { while (1) {
/* Event loop that handles events from the X server's event queue */ /* Event loop that handles events from the X server's event queue */
/* Will actually block if there are no events */ /* Will actually block if there are no events */
@ -50,27 +98,41 @@ main(void) {
XNextEvent(display, &event); XNextEvent(display, &event);
if (event.type == Expose) { if (event.type == Expose) {
XFillRectangle(display, XColor boxcolor = getColor(32000, 0, 32000);
window,
DefaultGC(display, screen), XAllocColor(display,
20, XDefaultColormap(display, screen),
20, &boxcolor);
10,
10); XSetForeground(display, gc, boxcolor.pixel);
XDrawString(display,
window,
DefaultGC(display, screen),
10,
50,
msg,
strlen(msg));
} }
if (event.type == KeyPress) { if (event.type == KeyPress) {
break; break;
} }
for(int x = 0; x < 100; x++) {
for(int y = 0; y < 100; y++) {
XDrawPoint(display, pixmap, gc, x, y);
}
}
factor++;
XCopyArea(display,
pixmap,
window,
gc,
0,
0,
100,
100,
factor,
factor);
nanosleep(&req, &rem);
} }
XCloseDisplay(display); XCloseDisplay(display);

Loading…
Cancel
Save