opengl_x11

Playing with OpenGL
git clone git://bsandro.tech/opengl_x11
Log | Files | Refs | README | LICENSE

commit f86593932252ed48f084bfe7669863ead9f3d60f
parent 992a70537d196093545a564c3e357dca07791f09
Author: bsandro <email@bsandro.tech>
Date:   Wed,  7 Jan 2026 01:01:26 +0200

rotating in geometry shader squares

Diffstat:
Mobj2d.c | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/obj2d.c b/obj2d.c @@ -51,19 +51,33 @@ static const GLchar *geometrySrc = R"( layout(points) in; layout(line_strip,max_vertices=6) out; in vec3 dotColor[]; +uniform double iTime; out vec3 fColor; + +mat2 rotate(float a) { + float s = sin(a); + float c = cos(a); + return mat2(c, -s, + s, c); +} + void main() { fColor = dotColor[0]; vec4 p = gl_in[0].gl_Position; - gl_Position = p+vec4(-0.1, -0.1, 0.0, 0.0); + vec4 p1 = p+vec4(-0.1, -0.1, 0.0, 0.0); + p1 = vec4(p.xy+rotate(float(iTime))*(p1.xy - p.xy), 0.0, 1.0); + gl_Position = p1; EmitVertex(); gl_Position = p+vec4(0.1, -0.1, 0.0, 0.0); + gl_Position = vec4(p.xy+rotate(float(iTime))*(gl_Position.xy - p.xy), 0.0, 1.0); EmitVertex(); gl_Position = p+vec4(0.1, 0.1, 0.0, 0.0); + gl_Position = vec4(p.xy+rotate(float(iTime))*(gl_Position.xy - p.xy), 0.0, 1.0); EmitVertex(); gl_Position = p+vec4(-0.1, 0.1, 0.0, 0.0); + gl_Position = vec4(p.xy+rotate(float(iTime))*(gl_Position.xy - p.xy), 0.0, 1.0); EmitVertex(); - gl_Position = p+vec4(-0.1, -0.1, 0.0, 0.0); + gl_Position = p1; EmitVertex(); EndPrimitive(); } @@ -132,7 +146,6 @@ struct vec2 rand_shift(void) { int main(void) { srand(time(0)); - printf("rngesus: %d, %d\n", rand() % 5, RAND_MAX); Display *dpy = XOpenDisplay(NULL); XSetWindowAttributes swa; Window win;