aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-06-29 17:20:42 -0500
committerturret <turret@duck.com>2023-06-29 17:20:42 -0500
commit7c53d95c6f5a8a1d1f67a0eb9a358f579b031391 (patch)
tree8d17549e129cc0df49f1389cfdfcb1c58f53f91a
parentf98f768869eac86701bd7291c966df46fd6df97d (diff)
downloaddonut-7c53d95c6f5a8a1d1f67a0eb9a358f579b031391.tar.gz
donut-7c53d95c6f5a8a1d1f67a0eb9a358f579b031391.tar.bz2
donut-7c53d95c6f5a8a1d1f67a0eb9a358f579b031391.zip
donut: implement double bufferingv3
-rw-r--r--config.mk2
-rw-r--r--donut.c12
2 files changed, 12 insertions, 2 deletions
diff --git a/config.mk b/config.mk
index 6880dbe..436d9d9 100644
--- a/config.mk
+++ b/config.mk
@@ -2,6 +2,6 @@ PREFIX = /usr/local
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -D_POSIX_C_SOURCE=200809L
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${CPPFLAGS}
-LDFLAGS = -lm -lX11
+LDFLAGS = -lm -lX11 -lXext
CC = cc
diff --git a/donut.c b/donut.c
index b136c36..36d7a19 100644
--- a/donut.c
+++ b/donut.c
@@ -28,6 +28,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
+#include <X11/extensions/Xdbe.h>
char *argv0;
#include "arg.h"
@@ -121,6 +122,12 @@ int main(int argc, char **argv) {
XClearWindow(dis, win);
XMapRaised(dis, win);
+ XdbeSwapInfo swap_info = {
+ win,
+ XdbeUndefined
+ };
+ XdbeBackBuffer back_buffer = XdbeAllocateBackBufferName(dis, win, swap_info.swap_action);
+
// torus rotation floats
float A = 0; // x-axis
float B = 0; // z-axis
@@ -149,12 +156,15 @@ int main(int argc, char **argv) {
for(int y = 0; height >= y; y++){
int color = (b[x + width * y] - 1 + M_SQRT2) / sqrt(8) * 255;
XSetForeground(dis, gc, color << 16 | color << 8 | color);
- XFillRectangle(dis, win, gc, x * SCALE, y * SCALE, SCALE, SCALE);
+ XFillRectangle(dis, back_buffer, gc, x * SCALE, y * SCALE, SCALE, SCALE);
}
}
+ XdbeSwapBuffers(dis, &swap_info, 1);
+
free(b);
+ XSync(dis, 1);
double etime = utime();
if(etime < stime + 1000/FPS_MAX)