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);
52 if(nloops > 0 && (anim < t / 6.0f)) {
57 alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f);
58 if(alpha < 0.0f) alpha = 0.0f;
59 if(alpha > 1.0f) alpha = 1.0f;
61 dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
63 glColor4f(1, 1, 1, alpha);
64 for(i=0; i<nverts-1; i++) {
65 float t0 = (float)i * dt;
66 float t1 = (float)(i + 1) * dt;
69 draw_line(a[0], a[1], b[0], b[1], 0.02);
74 draw_disc(a[0], a[1], 0.05, 22);
78 draw_disc(b[0], b[1], 0.05, 22);
82 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
84 glColor4f(0.8, 0, 0, 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f));
85 draw_disc(0, 0, 0.14, 30);
89 glColor4f(0, 0, 0, 1.0f - alpha);
100 static void draw_disc(float x, float y, float rad, int sub)
103 glBegin(GL_TRIANGLE_FAN);
105 for(i=0; i<sub; i++) {
106 float t = (float)i / (float)(sub - 1);
107 float theta = t * M_PI * 2.0;
108 glVertex2f(cos(theta) * rad + x, sin(theta) * rad + y);
113 static void draw_line(float x0, float y0, float x1, float y1, float rad)
115 float dx, dy, rx, ry, len;
119 len = sqrt(dx * dx + dy * dy);
122 ry = -rad * dx / len;
124 draw_disc(x0, y0, rad, 12);
125 draw_disc(x1, y1, rad, 12);
128 glVertex2f(x0 + rx, y0 + ry);
129 glVertex2f(x1 + rx, y1 + ry);
130 glVertex2f(x1 - rx, y1 - ry);
131 glVertex2f(x0 - rx, y0 - ry);
136 void app_reshape(int x, int y)
138 float aspect = (float)x / (float)y;
139 glViewport(0, 0, x, y);
140 glMatrixMode(GL_PROJECTION);
142 glScalef(1.0f / aspect, 1.0f, 1.0f);
145 void app_keyboard(int key, int pressed)
153 printf("nverts: %d\n", nverts);
158 printf("nverts: %d\n", nverts);
173 int app_parse_args(int argc, char **argv)
177 for(i=1; i<argc; i++) {
178 if(argv[i][0] == '-') {
179 if(strcmp(argv[i], "-fs") == 0) {
181 } else if(strcmp(argv[i], "-noaa") == 0) {
183 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
184 print_usage(argv[0]);
187 fprintf(stderr, "invalid option: %s\n", argv[i]);
191 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
198 static void print_usage(const char *argv0)
200 printf("Usage: %s [options]\n", argv0);
201 printf("Options:\n");
202 printf(" -fs: fullscreen\n");
203 printf(" -noaa: disable anti-aliasing\n");
204 printf(" -h,-help: print usage and exit\n");