10 #define GL_MULTISAMPLE 0x809d
18 void reshape(int x, int y);
19 void keyb(unsigned char key, int x, int y);
20 int parse_args(int argc, char **argv);
21 void print_usage(const char *argv0);
23 int win_width, win_height;
30 int main(int argc, char **argv)
32 unsigned int flags = GLUT_RGB | GLUT_DOUBLE;
34 glutInit(&argc, argv);
35 if(parse_args(argc, argv) == -1) {
41 flags |= GLUT_MULTISAMPLE;
45 glutInitWindowSize(1280, 800);
46 glutInitDisplayMode(flags);
47 glutCreateWindow("census");
53 glutDisplayFunc(display);
55 glutReshapeFunc(reshape);
56 glutKeyboardFunc(keyb);
68 if(init_logo("data/census.curves") == -1) {
74 glEnable(GL_MULTISAMPLE);
78 start_time = glutGet(GLUT_ELAPSED_TIME);
82 static void draw_disc(float x, float y, float rad, int sub)
85 glBegin(GL_TRIANGLE_FAN);
87 for(i=0; i<sub; i++) {
88 float t = (float)i / (float)(sub - 1);
89 float theta = t * M_PI * 2.0;
90 glVertex2f(cos(theta) * rad + x, sin(theta) * rad + y);
95 static void draw_line(float x0, float y0, float x1, float y1, float rad)
97 float dx, dy, rx, ry, len;
101 len = sqrt(dx * dx + dy * dy);
104 ry = -rad * dx / len;
106 draw_disc(x0, y0, rad, 8);
107 draw_disc(x1, y1, rad, 8);
110 glVertex2f(x0 + rx, y0 + ry);
111 glVertex2f(x1 + rx, y1 + ry);
112 glVertex2f(x1 - rx, y1 - ry);
113 glVertex2f(x0 - rx, y0 - ry);
117 #define LOOPTIME 1.3f
122 long msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
123 float t = (float)msec / 1000.0f;
124 float a[2], b[2], dt;
127 glClear(GL_COLOR_BUFFER_BIT);
131 anim = fmod(t / 6.0f, LOOPTIME);
132 alpha = 1.0f - ((anim - (LOOPTIME - 0.2)) / 0.2f);
133 if(alpha < 0.0f) alpha = 0.0f;
134 if(alpha > 1.0f) alpha = 1.0f;
136 dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
138 glColor4f(1, 1, 1, alpha);
139 for(i=0; i<nverts-1; i++) {
140 float t0 = (float)i * dt;
141 float t1 = (float)(i + 1) * dt;
144 draw_line(a[0], a[1], b[0], b[1], 0.02);
149 draw_disc(a[0], a[1], 0.05, 18);
153 draw_disc(b[0], b[1], 0.05, 18);
157 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
159 glColor4f(0.8, 0, 0, 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f));
160 draw_disc(0, 0, 0.14, 24);
164 glColor4f(0, 0, 0, 1.0f - alpha);
175 assert(glGetError() == GL_NO_ERROR);
183 void reshape(int x, int y)
185 float aspect = (float)x / (float)y;
189 glViewport(0, 0, x, y);
190 glMatrixMode(GL_PROJECTION);
192 glScalef(1.0f / aspect, 1.0f, 1.0f);
195 void keyb(unsigned char key, int x, int y)
197 static int saved_width = 800, saved_height = 600;
205 printf("nverts: %d\n", nverts);
211 printf("nverts: %d\n", nverts);
218 saved_width = win_width;
219 saved_height = win_height;
222 glutReshapeWindow(saved_width, saved_height);
228 int parse_args(int argc, char **argv)
232 for(i=1; i<argc; i++) {
233 if(argv[i][0] == '-') {
234 if(strcmp(argv[i], "-fs") == 0) {
236 } else if(strcmp(argv[i], "-noaa") == 0) {
238 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
239 print_usage(argv[0]);
242 fprintf(stderr, "invalid option: %s\n", argv[i]);
246 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
253 void print_usage(const char *argv0)
255 printf("Usage: %s [options]\n", argv0);
256 printf("Options:\n");
257 printf(" -fs: fullscreen\n");
258 printf(" -noaa: disable anti-aliasing\n");
259 printf(" -h,-help: print usage and exit\n");