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");
51 glutSetCursor(GLUT_CURSOR_NONE);
54 glutDisplayFunc(display);
56 glutReshapeFunc(reshape);
57 glutKeyboardFunc(keyb);
69 if(init_logo("data/census.curves") == -1) {
75 glEnable(GL_MULTISAMPLE);
79 start_time = glutGet(GLUT_ELAPSED_TIME);
83 static void draw_disc(float x, float y, float rad, int sub)
86 glBegin(GL_TRIANGLE_FAN);
88 for(i=0; i<sub; i++) {
89 float t = (float)i / (float)(sub - 1);
90 float theta = t * M_PI * 2.0;
91 glVertex2f(cos(theta) * rad + x, sin(theta) * rad + y);
96 static void draw_line(float x0, float y0, float x1, float y1, float rad)
98 float dx, dy, rx, ry, len;
102 len = sqrt(dx * dx + dy * dy);
105 ry = -rad * dx / len;
107 draw_disc(x0, y0, rad, 12);
108 draw_disc(x1, y1, rad, 12);
111 glVertex2f(x0 + rx, y0 + ry);
112 glVertex2f(x1 + rx, y1 + ry);
113 glVertex2f(x1 - rx, y1 - ry);
114 glVertex2f(x0 - rx, y0 - ry);
118 #define LOOPTIME 1.45f
123 long msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
124 float t = (float)msec / 1000.0f;
125 float a[2], b[2], dt;
128 glClear(GL_COLOR_BUFFER_BIT);
132 anim = fmod(t / 6.0f, LOOPTIME);
133 alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f);
134 if(alpha < 0.0f) alpha = 0.0f;
135 if(alpha > 1.0f) alpha = 1.0f;
137 dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
139 glColor4f(1, 1, 1, alpha);
140 for(i=0; i<nverts-1; i++) {
141 float t0 = (float)i * dt;
142 float t1 = (float)(i + 1) * dt;
145 draw_line(a[0], a[1], b[0], b[1], 0.02);
150 draw_disc(a[0], a[1], 0.05, 22);
154 draw_disc(b[0], b[1], 0.05, 22);
158 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
160 glColor4f(0.8, 0, 0, 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f));
161 draw_disc(0, 0, 0.14, 30);
165 glColor4f(0, 0, 0, 1.0f - alpha);
176 assert(glGetError() == GL_NO_ERROR);
184 void reshape(int x, int y)
186 float aspect = (float)x / (float)y;
190 glViewport(0, 0, x, y);
191 glMatrixMode(GL_PROJECTION);
193 glScalef(1.0f / aspect, 1.0f, 1.0f);
196 void keyb(unsigned char key, int x, int y)
198 static int saved_width = 800, saved_height = 600;
206 printf("nverts: %d\n", nverts);
212 printf("nverts: %d\n", nverts);
219 saved_width = win_width;
220 saved_height = win_height;
222 glutSetCursor(GLUT_CURSOR_NONE);
224 glutReshapeWindow(saved_width, saved_height);
225 glutSetCursor(GLUT_CURSOR_INHERIT);
231 int parse_args(int argc, char **argv)
235 for(i=1; i<argc; i++) {
236 if(argv[i][0] == '-') {
237 if(strcmp(argv[i], "-fs") == 0) {
239 } else if(strcmp(argv[i], "-noaa") == 0) {
241 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
242 print_usage(argv[0]);
245 fprintf(stderr, "invalid option: %s\n", argv[i]);
249 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
256 void print_usage(const char *argv0)
258 printf("Usage: %s [options]\n", argv0);
259 printf("Options:\n");
260 printf(" -fs: fullscreen\n");
261 printf(" -noaa: disable anti-aliasing\n");
262 printf(" -h,-help: print usage and exit\n");