void init_fractal(t_mlx *e, t_env *w) { if (!(w->win = mlx_new_window(e->mlx, WIN_W, WIN_H, TITLE))) exit_str("Failed to create new window"); if (!(w->img_ptr = mlx_new_image(e->mlx, WIN_W, WIN_H))) exit_str("Failed to create new image"); w->img_addr = mlx_get_data_addr(w->img_ptr, &w->bpp, &w->linesize, &w->endian); if (IS_GPU && (w->linesize != WIN_W * 4 || w->bpp != 32)) { ft_printf_fd(2, "%sERROR:%; %red;Linesize and bpp are not as ", "\x1b[1;31m"); ft_printf_fd(2, "expected in OpenCL init%;\n"); ft_printf_fd(2, "%yellow;Expected : %d and %d\n", WIN_W * 4, 32); ft_printf_fd(2, "Received : %d and %d\n", w->linesize, w->bpp); exit(1); } set_hooks(w); w->e = e; ft_bzero(w->keys, KEYCODE_MAX); init_fractal_values(w); w->colorft = (w->fractalft != newton) ? DEFAULT_COLORFT : color5; w->colorft_num = (w->fractalft != newton) ? DEFAULT_COLORFT_NUM : 5; w->fractalft_num = get_fractalft_num(w); redraw_fractal(*w); }
si32 fill_cvars() { si32 i, ifld=0; ui08 filename[BUF_SIZE]; ui08 buf[BUF_SIZE]; FILE *fp; /**********************************************************************/ if (Glob->params.debug) fprintf(stderr, "--------fill_cvars------------- \n\n"); /* get memory for calculated variable table -- kept for duration of run */ Glob->cv = (CalculatedVariables *) ucalloc(MAX_CALC_FIELDS,(unsigned) sizeof(CalculatedVariables)); /* make filename for calcualted variables table */ sprintf(filename, Glob->params.cvars_file_path); if (Glob->params.debug) fprintf(stderr, "Calculated Variables table filename is %s \n",filename); /* open the file */ if ((fp = fopen(filename,"r")) == NULL) { exit_str("Could not open calculated variables file"); } /* read each line and extract field names, variable type and coefficients */ while (fgets(buf,BUF_SIZE,fp) != NULL) { if (buf[0] != COMMENT_CHAR) { sscanf(buf,"%s %s %lf %lf %lf %lf \n", Glob->cv[ifld].name, Glob->cv[ifld].var_type, &Glob->cv[ifld].c1, &Glob->cv[ifld].c2, &Glob->cv[ifld].c3, &Glob->cv[ifld].c4); /* fill in unknown for units, this will be filled in later * by individual calc_* functions */ strncpy(Glob->cv[ifld].units,"UNKNOWN ",8); /* fill in var_type with blanks so no null byte in first 8 chars */ for (i = strlen(Glob->cv[ifld].var_type); i < 8; i++) { memcpy(&Glob->cv[ifld].var_type[i]," ",1); } ifld ++; /* exit if there isn't enough memory for calc variables table */ if (ifld > MAX_CALC_FIELDS) exit_str("Not enough memory allocated for Calculated Variables Table"); } } /* end reading data */ /* set the total number of calculated fields */ Glob->num_calc_fields = ifld; /* print out calculated variables table info */ if (Glob->params.debug) { fprintf(stderr, "name f_type c1 c2 c3\n"); for (i = 0; i < Glob->num_calc_fields; i++) { fprintf(stderr, "%3d %s %s %f %f %f %f \n", i, Glob->cv[i].name, Glob->cv[i].var_type, Glob->cv[i].c1, Glob->cv[i].c2, Glob->cv[i].c3, Glob->cv[i].c4); } fprintf(stderr, "---------------------------------- \n\n"); } /* endif if debug and printing */ fclose(fp); return(OKAY); }