nuclear@0: #include nuclear@0: #include nuclear@2: #include nuclear@1: #include nuclear@2: #include nuclear@2: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include "sdr.h" nuclear@0: nuclear@3: enum { nuclear@3: SDR_LINE_DIST_BIT = 1, nuclear@3: SDR_PLOT_ORBIT_BIT = 2 nuclear@3: }; nuclear@3: const char *sdrdef[] = { nuclear@3: "#define LINE_DIST\n", nuclear@3: "#define PLOT_ORBIT\n" nuclear@3: }; nuclear@3: #define NUM_SDR_BITS (sizeof sdrdef / sizeof *sdrdef) nuclear@3: #define NUM_SHADERS (1 << NUM_SDR_BITS) nuclear@3: nuclear@0: int init(void); nuclear@0: void cleanup(void); nuclear@0: void disp(void); nuclear@0: void reshape(int x, int y); nuclear@1: void keydown(unsigned char key, int x, int y); nuclear@1: void keyup(unsigned char key, int x, int y); nuclear@0: void mouse(int bn, int st, int x, int y); nuclear@0: void motion(int x, int y); nuclear@2: void screenshot(void); nuclear@0: nuclear@1: static int win_width = 1280, win_height = 800; nuclear@1: static float win_aspect; nuclear@1: static int mouse_x = 640, mouse_y = 400; nuclear@3: static unsigned int prog_mbrot[NUM_SHADERS]; nuclear@0: nuclear@1: static float view_center[2] = {0.7, 0.0}; nuclear@1: static float view_scale = 1.2; nuclear@1: nuclear@3: static unsigned int sdrflags; nuclear@1: nuclear@0: int main(int argc, char **argv) nuclear@0: { nuclear@0: glutInit(&argc, argv); nuclear@0: glutInitWindowSize(1280, 800); nuclear@0: glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); nuclear@0: glutCreateWindow("fractorb"); nuclear@0: nuclear@0: glutDisplayFunc(disp); nuclear@0: glutReshapeFunc(reshape); nuclear@1: glutKeyboardFunc(keydown); nuclear@1: glutKeyboardUpFunc(keyup); nuclear@0: glutMouseFunc(mouse); nuclear@0: glutMotionFunc(motion); nuclear@0: nuclear@0: if(init() == -1) { nuclear@0: return 1; nuclear@0: } nuclear@0: atexit(cleanup); nuclear@0: nuclear@0: glutMainLoop(); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: int init(void) nuclear@0: { nuclear@3: int i, j; nuclear@3: unsigned int vs = 0, ps[NUM_SHADERS] = {0}; nuclear@3: nuclear@0: glewInit(); nuclear@0: nuclear@3: if(!(vs = load_vertex_shader("vertex.glsl"))) { nuclear@0: return -1; nuclear@0: } nuclear@3: nuclear@3: for(i=0; id_name, "img%d.ppm", &num) == 1) { nuclear@2: if(num >= shotnum) shotnum = num + 1; nuclear@2: } nuclear@2: } nuclear@2: closedir(dir); nuclear@2: } nuclear@2: } else { nuclear@2: ++shotnum; nuclear@2: } nuclear@2: nuclear@2: sprintf(fname, "img%04d.ppm", shotnum > 0 ? shotnum : 0); nuclear@2: if(!(fp = fopen(fname, "wb"))) { nuclear@2: fprintf(stderr, "failed to open %s for writing: %s\n", fname, strerror(errno)); nuclear@2: return; nuclear@2: } nuclear@2: nuclear@2: if(!(img = malloc(win_width * win_height * 3))) { nuclear@2: fprintf(stderr, "failed to allocate screenshot buffer\n"); nuclear@2: fclose(fp); nuclear@2: return; nuclear@2: } nuclear@2: nuclear@2: glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE, img); nuclear@2: nuclear@2: fprintf(fp, "P6\n%d %d\n255\n", win_width, win_height); nuclear@2: fwrite(img, 1, win_width * win_height * 3, fp); nuclear@2: fclose(fp); nuclear@2: free(img); nuclear@2: return; nuclear@2: }