10 #define GL_MULTISAMPLE 0x809d
18 static void draw_disc(float x, float y, float rad, int sub);
19 static void draw_line(float x0, float y0, float x1, float y1, float rad);
20 static void print_usage(const char *argv0);
24 if(init_logo("data/census.curves") == -1) {
30 glEnable(GL_MULTISAMPLE);
37 #define LOOPTIME 1.45f
39 void app_display(void)
42 float t = (float)msec / 1000.0f;
46 glClear(GL_COLOR_BUFFER_BIT);
50 anim = fmod(t / 6.0f, LOOPTIME);
51 alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f);
52 if(alpha < 0.0f) alpha = 0.0f;
53 if(alpha > 1.0f) alpha = 1.0f;
55 dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
57 glColor4f(1, 1, 1, alpha);
58 for(i=0; i<nverts-1; i++) {
59 float t0 = (float)i * dt;
60 float t1 = (float)(i + 1) * dt;
63 draw_line(a[0], a[1], b[0], b[1], 0.02);
68 draw_disc(a[0], a[1], 0.05, 22);
72 draw_disc(b[0], b[1], 0.05, 22);
76 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
78 glColor4f(0.8, 0, 0, 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f));
79 draw_disc(0, 0, 0.14, 30);
83 glColor4f(0, 0, 0, 1.0f - alpha);
94 static void draw_disc(float x, float y, float rad, int sub)
97 glBegin(GL_TRIANGLE_FAN);
99 for(i=0; i<sub; i++) {
100 float t = (float)i / (float)(sub - 1);
101 float theta = t * M_PI * 2.0;
102 glVertex2f(cos(theta) * rad + x, sin(theta) * rad + y);
107 static void draw_line(float x0, float y0, float x1, float y1, float rad)
109 float dx, dy, rx, ry, len;
113 len = sqrt(dx * dx + dy * dy);
116 ry = -rad * dx / len;
118 draw_disc(x0, y0, rad, 12);
119 draw_disc(x1, y1, rad, 12);
122 glVertex2f(x0 + rx, y0 + ry);
123 glVertex2f(x1 + rx, y1 + ry);
124 glVertex2f(x1 - rx, y1 - ry);
125 glVertex2f(x0 - rx, y0 - ry);
130 void app_reshape(int x, int y)
132 float aspect = (float)x / (float)y;
133 glViewport(0, 0, x, y);
134 glMatrixMode(GL_PROJECTION);
136 glScalef(1.0f / aspect, 1.0f, 1.0f);
139 void app_keyboard(int key, int pressed)
147 printf("nverts: %d\n", nverts);
152 printf("nverts: %d\n", nverts);
167 int app_parse_args(int argc, char **argv)
171 for(i=1; i<argc; i++) {
172 if(argv[i][0] == '-') {
173 if(strcmp(argv[i], "-fs") == 0) {
175 } else if(strcmp(argv[i], "-noaa") == 0) {
177 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
178 print_usage(argv[0]);
181 fprintf(stderr, "invalid option: %s\n", argv[i]);
185 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
192 static void print_usage(const char *argv0)
194 printf("Usage: %s [options]\n", argv0);
195 printf("Options:\n");
196 printf(" -fs: fullscreen\n");
197 printf(" -noaa: disable anti-aliasing\n");
198 printf(" -h,-help: print usage and exit\n");