commit 992a70537d196093545a564c3e357dca07791f09
parent 514631bf341f07cb92ea4825d827a4288173aea6
Author: bsandro <email@bsandro.tech>
Date: Tue, 6 Jan 2026 02:21:15 +0200
obj2d squares move slightly erratically
Diffstat:
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,10 @@
MAKEFLAGS+=-rR
CFLAGS=-std=gnu23 -Wpedantic -Wall -Wextra -Wunused -Os -s -fomit-frame-pointer -ffast-math -fno-stack-protector -march=native -fwrapv -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-unwind-tables -fmerge-all-constants -fno-ident
LDFLAGS=-lm -lGL -lGLU -lX11 -Wl,--gc-sections
+
+ifeq ($(origin CC),default)
CC=cc
+endif
.PHONY: clean
diff --git a/obj2d.c b/obj2d.c
@@ -27,7 +27,7 @@ x;
} \
}
-static const double current_ts() {
+static double current_ts() {
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return (double)ts.tv_sec + (double)ts.tv_nsec/1e9;
@@ -76,7 +76,7 @@ in vec3 fColor;
out vec4 outColor;
void main() {
vec3 color = fColor;
- if (gl_FragCoord.x < 300) {
+ if (gl_FragCoord.x < 300) {
color.g = 1.0f;
}
outColor = vec4(color, 1.0);
@@ -117,7 +117,22 @@ void __attribute((destructor)) end() {
printf("end()\n");
}
-int main(int argc, char *argv[]) {
+struct vec2 {
+ float x;
+ float y;
+};
+
+struct vec2 rand_shift(void) {
+ int xs = (rand()%2)==0?1:-1;
+ int ys = (rand()%2)==0?1:-1;
+ int x = xs*rand()%20;
+ int y = ys*rand()%20;
+ return (struct vec2){ .x=(float)x/10000.f, .y=(float)y/10000.f};
+}
+
+int main(void) {
+ srand(time(0));
+ printf("rngesus: %d, %d\n", rand() % 5, RAND_MAX);
Display *dpy = XOpenDisplay(NULL);
XSetWindowAttributes swa;
Window win;
@@ -214,9 +229,12 @@ int main(int argc, char *argv[]) {
glViewport(0, 0, ce->width, ce->height);
}
}
-vertices[0][0] += 0.0003f;
-glNamedBufferData(vbo, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
-
+ for (size_t i=0;i<LEN(vertices);++i) {
+ struct vec2 shift = rand_shift();
+ vertices[i][0] += shift.x;
+ vertices[i][1] += shift.y;
+ }
+ glNamedBufferData(vbo, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);
glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);