initial commit
authorJohn Tsiombikas <jtsiomb@census.gr>
Tue, 27 Aug 2019 14:14:29 +0000 (17:14 +0300)
committerJohn Tsiombikas <jtsiomb@census.gr>
Tue, 27 Aug 2019 14:14:29 +0000 (17:14 +0300)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
src/logo.h [new file with mode: 0644]
src/main.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..d90c263
--- /dev/null
@@ -0,0 +1,4 @@
+*.o
+*.d
+*.swp
+censuslogo
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..a1dc85b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
+src = $(wildcard src/*.c)
+obj = $(src:.c=.o)
+dep = $(obj:.o=.d)
+bin = censuslogo
+
+CFLAGS = -pedantic -Wall -g
+LDFLAGS = -lGL -lGLU -lglut -lm
+
+$(bin): $(obj)
+       $(CC) -o $@ $(obj) $(LDFLAGS)
+
+-include $(dep)
+
+%.d: %.c
+       @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
+
+.PHONY: clean
+clean:
+       rm -f $(obj) $(bin)
+
+.PHONY: cleandep
+cleandep:
+       rm -f $(dep)
diff --git a/src/logo.h b/src/logo.h
new file mode 100644 (file)
index 0000000..c483f0c
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef LOGO_H_
+#define LOGO_H_
+
+#define LOGO_W 90
+#define LOGO_H 85
+
+static const float logocp[][2] = {
+       {85, 48},
+       {68.5, 64.5},
+       {68.5, 64.5},
+       {52, 81},
+
+       {52, 81},
+       {43, 89},
+       {43, 89},
+       {34, 81},
+
+       {34, 81},
+       {18.5, 66},
+       {18.5, 66},
+       {3, 51},
+
+       {3, 51},
+       {-5, 41.5},
+       {-5, 41.5},
+       {4, 32},
+
+       {4, 32},
+       {19, 17},
+       {19, 17},
+       {33, 3},
+
+       {33, 3},
+       {42, -5},
+       {42, -5},
+       {52, 3},
+
+       {52, 3},
+       {68, 19},
+       {68, 19},
+       {85, 35},
+
+       {85, 35},
+       {75, 35},
+       {85, 35},
+       {75, 35},
+
+       {75, 35},
+       {62, 22},
+       {62, 22},
+       {49, 10},
+
+       {49, 10},
+       {42, 4},
+       {42, 4},
+       {36, 10},
+
+       {36, 10},
+       {23, 22},
+       {23, 22},
+       {11, 35},
+
+       {11, 35},
+       {5, 42},
+       {5, 42},
+       {11, 49},
+
+       {11, 49},
+       {23, 61},
+       {23, 61},
+       {36, 74},
+
+       {36, 74},
+       {42, 79},
+       {42, 79},
+       {49, 74},
+
+       {49, 74},
+       {62, 61},
+       {62, 61},
+       {75, 48},
+
+       {75, 48},
+       {65, 48},
+       {75, 48},
+       {65, 48},
+
+       {65, 48},
+       {55.5, 57.5},
+       {55.5, 57.5},
+       {46, 67},
+
+       {46, 67},
+       {42.5, 70},
+       {42.5, 70},
+       {39, 67},
+
+       {39, 67},
+       {28, 56},
+       {28, 56},
+       {17, 45},
+};
+
+#define LOGOCP_SIZE    (sizeof logocp / sizeof *logocp)
+
+#endif /* LOGO_H_ */
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..06477c1
--- /dev/null
@@ -0,0 +1,120 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <GL/glut.h>
+#include "logo.h"
+
+#define BEZ_SEG        16
+
+int init(void);
+void display(void);
+void reshape(int x, int y);
+void keyb(unsigned char key, int x, int y);
+
+void draw_bezier(float *cp, int sub);
+
+int main(int argc, char **argv)
+{
+       glutInit(&argc, argv);
+       glutInitWindowSize(800, 600);
+       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+       glutCreateWindow("census");
+
+       glutDisplayFunc(display);
+       glutReshapeFunc(reshape);
+       glutKeyboardFunc(keyb);
+
+       if(init() == -1) {
+               return 1;
+       }
+
+       glutMainLoop();
+       return 0;
+}
+
+int init(void)
+{
+       glEnable(GL_LINE_SMOOTH);
+       return 0;
+}
+
+void display(void)
+{
+       int i, nseg;
+
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glLineWidth(2.0);
+
+       glColor3f(1, 1, 1);
+       nseg = LOGOCP_SIZE / 4;
+       for(i=0; i<nseg; i++) {
+               draw_bezier((float*)(logocp + i * 4), BEZ_SEG);
+       }
+
+       glDisable(GL_BLEND);
+
+       glutSwapBuffers();
+       assert(glGetError() == GL_NO_ERROR);
+}
+
+void reshape(int x, int y)
+{
+       float aspect = (float)x / (float)y;
+
+       glViewport(0, 0, x, y);
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+       glScalef(1.0f / aspect, 1.0f, 1.0f);
+}
+
+void keyb(unsigned char key, int x, int y)
+{
+       switch(key) {
+       case 27:
+               exit(0);
+       }
+}
+
+#define LERP(a, b, t)  ((a) + ((b) - (a)) * (t))
+
+void draw_bezier(float *cp, int sub)
+{
+       int i;
+       float cx[4], cy[4], mx[3], my[3], mmx[2], mmy[2], x, y;
+
+       if(sub < 1) sub = 1;
+
+       for(i=0; i<4; i++) {
+               cx[i] = cp[i * 2] / LOGO_W - 0.5f;
+               cy[i] = 0.5f - cp[i * 2 + 1] / LOGO_H;
+       }
+
+       glBegin(GL_LINE_STRIP);
+       for(i=0; i<BEZ_SEG; i++) {
+               float t = (float)i / (float)(BEZ_SEG - 1);
+
+               mx[0] = LERP(cx[0], cx[1], t);
+               my[0] = LERP(cy[0], cy[1], t);
+
+               mx[1] = LERP(cx[1], cx[2], t);
+               my[1] = LERP(cy[1], cy[2], t);
+
+               mx[2] = LERP(cx[2], cx[3], t);
+               my[2] = LERP(cy[2], cy[3], t);
+
+               mmx[0] = LERP(mx[0], mx[1], t);
+               mmy[0] = LERP(my[0], my[1], t);
+
+               mmx[1] = LERP(mx[1], mx[2], t);
+               mmy[1] = LERP(my[1], my[2], t);
+
+               x = LERP(mmx[0], mmx[1], t);
+               y = LERP(mmy[0], mmy[1], t);
+
+               glVertex2f(x, y);
+       }
+       glEnd();
+}