t_img *init_img(t_env *env) { t_img *img; if (!(img = (t_img *)malloc(sizeof(t_img)))) ft_error("Can't create image."); img->img = mlx_new_image(env->mlx, X_SIZE, Y_SIZE); img->data = mlx_get_data_addr(img->img, &img->bpp, \ &img->sizeline, &img->endian); return (img); }
int start_minilibx(t_imgdata *imgdata) { imgdata->mlx_ptr = mlx_init(); imgdata->img_ptr = mlx_new_image(imgdata->mlx_ptr, WIN_WIDTH, WIN_HEIGHT); imgdata->win_ptr = mlx_new_window(imgdata->mlx_ptr, WIN_WIDTH, WIN_HEIGHT, "display"); imgdata->data = mlx_get_data_addr(imgdata->img_ptr, &imgdata->bpp, &imgdata->sizeline, &imgdata->endian); return (0); }
int ft_recreate(t_id *s) { if (s->img) mlx_destroy_image(s->mlx, s->img); s->img = mlx_new_image(s->mlx, W_X, W_Y); s->data = mlx_get_data_addr(s->img, &s->bit_per_pixel, &s->s_line, &s->endian); s->bpp = s->bit_per_pixel / 8; ft_corps(s); return (1); }
t_img *init_img(t_env *env) { t_img *img; if (!(img = (t_img *)malloc(sizeof(t_img)))) return (NULL); img->img = mlx_new_image(env->mlx, X_WIN, Y_WIN); img->data = mlx_get_data_addr(img->img, &img->bpp, \ &img->size_line, &img->endian); return (img); }
t_img *new_img(t_mlx *mlx) { t_img *img; if (!(img = (t_img *)malloc(sizeof(*img)))) str_exit(-1, "new.c : Error line 55"); img->img = mlx_new_image(mlx->mlx, mlx->w, mlx->h); img->addr = mlx_get_data_addr(img->img, &(img->bpp), &(img->size_l), &(img->endian)); return (img); }
t_img *img_init(void) { t_win *win; t_img *img; win = env_init(); img = (t_img *)malloc(sizeof(t_img)); img->img = mlx_new_image(win->mlx, WIDTH, HEIGHT); img->data = mlx_get_data_addr(img->img, &img->bpp, &img->size_line , &img->endian); return (img); }
void init_mlx(t_data *d) { d->mlx = mlx_init(); if(!(d->win = mlx_new_window(d->mlx, X_WIN, Y_WIN, "RT"))) exit(tt_pl("window open failed")); if(!(d->img = mlx_new_image(d->mlx, X_WIN, Y_WIN))) exit(tt_pl("image creation failed")); if(!(d->dimg = mlx_get_data_addr(d->img, &d->bpp, &d->size, &d->endian))) exit(tt_pl("Get image data failed")); d->bpp /= 8; d->max_size = (unsigned int)(d->size * Y_WIN); }
int main(int argc, char **argv) { t_env e; e.mlx = mlx_init(); if (e.mlx == NULL) return (0); e.win = mlx_new_window(e.mlx, 2400, 1300, "Fil de Fer"); if (e.win == NULL) return (0); e.im = mlx_new_image(e.mlx, 2400, 1300); e.imb = mlx_new_image(e.mlx, 2400, 1300); e.x = 0; e.y = 0; e.map = NULL; ft_init_space(argc, argv, &e); mlx_key_hook(e.win, key_hook, &e); mlx_expose_hook(e.win, expose_hook, &e); mlx_loop(e.mlx); return (0); }
void create_img(t_mlx *mlx, t_img *img) { img->win_x = 800; img->win_y = 600; img->sphere = mlx_new_image(mlx->mlx_ptr, img->win_x, img->win_y); img->data = mlx_get_data_addr(img->sphere, &(img->bpp), &(img->sizeline), &(img->endian)); color_img(img, mlx); /* if (mlx_put_image_to_window(mlx->mlx_ptr, mlx->win_ptr, */ /* img->sphere, 0, 0) == -1) */ /* exit(1); */ }
void init_libx(t_param *param, char *file) { param->mlx_ptr = mlx_init(); if (param->mlx_ptr == 0) my_puterror("Can not init LibX.\n"); param->win_ptr = mlx_new_window(param->mlx_ptr, WIN_X, WIN_Y, "Raytracer"); param->img = mlx_new_image(param->mlx_ptr, WIN_X, WIN_Y); treat_image(param, file); mlx_key_hook(param->win_ptr, &key, ¶m); mlx_expose_hook(param->win_ptr, &expose, param); mlx_loop(param->mlx_ptr); }
static void x_init(t_var *v) { if ((v->mlx = mlx_init()) == NULL) exit(EXIT_FAILURE); v->img = mlx_new_image(v->mlx, LEN_X, LEN_Y); v->win = mlx_new_window(v->mlx, LEN_X, LEN_Y, "Ray-Tracer"); v->data = mlx_get_data_addr(v->img, &v->bpp, &v->sizeline, &v->endian); v->pix_th[0] = 0; v->pix_th[1] = 0; v->pix_th[2] = 0; v->pix_th[3] = 0; }
int mouse_hook(int boutton, int x, int y, t_env *e) { printf("bouton = %d, x = %d, y = %d\n", boutton, x, y); if (boutton == LEFT_CLIC) { if (e->nbr_clic == 0) { ft_putstr("in nrbclic = 0"); e->nbr_clic++; e->xmintmp = e->xmin; e->ymintmp = e->ymin; e->xmin = e->xmin + x * e->stepx; e->ymin = e->ymin + y * e->stepy; } else if (e->nbr_clic == 1) { ft_putstr("in nrbclic = 1"); e->nbr_clic = 0; e->xmax = e->xmintmp + x * e->stepx; e->ymax = e->ymintmp + y * e->stepy; e->stepx = (double)(e->xmax - e->xmin) / WX; e->stepy = (double)(e->ymax - e->ymin) / WY; double x_f; double y_f; int nb_it; mlx_destroy_image(e->mlx, e->img); e->img = mlx_new_image(e->mlx, WX, WY); x_f = e->xmin; x = 0; while (x <= WX) { y = 0; y_f = e->ymin; while (y <= WY) { nb_it = is_converg((mandelbrot), x_f, y_f); // printf("val x_f = %lf, val de y_f = %lf, val de nb_it = %d\n", x_f, y_f, nb_it); // printf("val stepx= %lf, val de stepy = %lf, val de y %d= \n",e->stepx, e->stepy, y); if (nb_it < 1000) mlx_pixel_put_img(e->img, x, y, rainbow_gen(nb_it * 40)); else mlx_pixel_put_img(e->img, x, y, 0x000000); y++; y_f += e->stepy; } x_f += e->stepx; x++; } mlx_put_image_to_window(e->mlx, e->win, e->img, 0,0); } } return (0); }
int create_img(t_env *e, t_img *img) { t_texture *h; h = &(e->hand); h->i = mlx_xpm_file_to_image(e->mlx, "img/hand.xpm", &(h->wth), &(h->hgt)); if (!(img->i = mlx_new_image(e->mlx, WIN_W, WIN_H)) || !h->i) return (0); img->d = mlx_get_data_addr(img->i, &(img->bpp), &(img->sl), &(img->edn)); h->d = mlx_get_data_addr(h->i, &(h->bpp), &(h->sl), &(h->edn)); return (1); }
void ft_setimg(t_ba *ba) { int bpp; int size; int endian; size = 0; endian = 0; bpp = 0; ba->img = mlx_new_image(ba->mlx, WD_H, WD_W); ba->pix = mlx_get_data_addr(ba->img, &bpp, &size, &endian); }
t_img *init_img(void) { t_win *win; t_img *img; win = init_env(); img = (t_img*)malloc(sizeof(t_img)); img->img = mlx_new_image(win->mlx, WIN_WID, WIN_HEI); img->data = mlx_get_data_addr(img->img, &img->bbp, &img->size_line, &img->endian); return (img); }
void init_env(t_env *env) { env->mlx = mlx_init(); env->resolution.width = WIDTH; env->resolution.height = HEIGHT; env->win = mlx_new_window(env->mlx, WIDTH, HEIGHT, "RayTracer"); env->img.ptr = mlx_new_image(env->mlx, WIDTH, HEIGHT); env->img.data = mlx_get_data_addr(env->img.ptr, &env->img.bpp, &env->img.sizeline, &env->img.endianness); env->fov = 45; env->pos_absolute_camera = (t_vertex3){ .x = json_get(parser(env->file).data.obj, "pos_camera.x").data.number, .y = json_get(parser(env->file).data.obj, "pos_camera.y").data.number, .z = json_get(parser(env->file).data.obj, "pos_camera.z").data.number}; env->matrice = malloc(sizeof(t_color3) * (WIDTH * HEIGHT) + 1); env->angle = tanf(M_PI * 0.5f * env->fov / 180.); env->ratio = env->resolution.width / (float)env->resolution.height; env->invw = 1 / (float)env->resolution.width; env->invh = 1 / (float)env->resolution.height; env->nb_thread = 14; env->sampling = 4; env->anglex = 0; env->angley = 0; } int main(int argc, char **argv) { t_env env; struct stat file_stat; if (argc == 2) { env.file = argv[1]; if (stat(env.file, &file_stat) < 0) { ft_printf("file not exists\n"); exit(0); } file_is_modified(env.file, &env.oldtime, 1); init_env(&env); ft_setup_inter(env.fctinter); ft_setup_normal(env.fctnormal); mlx_do_key_autorepeatoff(env.mlx); mlx_hook(env.win, 2, (1L << 0), &key_press, &env); mlx_loop_hook(env.mlx, &loop_hook, &env); mlx_expose_hook(env.win, &rt_expose_hook, &env); mlx_loop(env.mlx); free(env.matrice); } else ft_printf("Usage: %s scene.json\n", argv[0]); return (0); }
void ft_initialization(t_id *s) { s->dp = 25; s->decalz = 0.2; s->slide = 0.2; s->img = mlx_new_image(s->mlx, W_X, W_Y); s->data = mlx_get_data_addr(s->img, &s->bit_per_pixel, &s->s_line, &s->endian); s->bpp = s->bit_per_pixel / 8; ft_display_hor(s); ft_display_ver(s); mlx_put_image_to_window(s->mlx, s->win, s->img, 0, 0); }
void ft_mlx(t_env *e) { e->f = malloc(sizeof(t_img)); e->mlx = mlx_init(); e->win = mlx_new_window(e->mlx, WIDTH + (2 * OFF), HEIGHT + (2 * OFF), "triangle_try_angle"); e->f->img = mlx_new_image(e->mlx, WIDTH + (2 * OFF), HEIGHT + (2 * OFF)); e->f->d = mlx_get_data_addr(e->f->img, &e->f->bpp, &e->f->line_size, &e->f->endian); mlx_key_hook(e->win, key_hook, e); mlx_mouse_hook(e->win, mouse_hook, e); mlx_expose_hook(e->win, expose_hook, e); mlx_loop(e->mlx); }
static t_img *ft_init_img(t_env *init) { t_img *img; if (!(img = (t_img *)malloc(sizeof(*img)))) error(); img->img = mlx_new_image(init->mlx, init->width, init->height); img->bpp = 0; img->sizel = 0; img->endn = 0; img->cimg = mlx_get_data_addr(img->img, &img->bpp, &img->sizel, &img->endn); return (img); }
void set_env(t_env *e, char *title, int w, int h) { e->mlx = mlx_init(); e->win = mlx_new_window(e->mlx, w, h, title); e->img = mlx_new_image(e->mlx, w, h); e->xmax = XMAX; e->xmin = XMIN; e->ymax = YMAX; e->ymin = YMIN; e->nbr_clic = 0; e->stepx = (double)(e->xmax - e->xmin) / WX; e->stepy = (double)(e->ymax - e->ymin) / WY; }
t_mlximg mlximg_create(void *mlx, int width, int height) { t_mlximg rtn; if ((rtn.ptr = mlx_new_image(mlx, width, height)) != NULL) { rtn.size.x = width; rtn.size.y = height; rtn.data = mlx_get_data_addr(rtn.ptr, &rtn.bpp, &rtn.linesize, &rtn.endianness); } return (rtn); }
// Inisialization img t_image *initialization_img(void *ptr_ini, int height, int width) { t_image *t_img; IMG = malloc(sizeof(*t_img)); IMG->ptr_ini = ptr_ini; IMG->height = height; IMG->width = width; IMG->img = mlx_new_image(ptr_ini, width, height); IMG->data = mlx_get_data_addr(IMG->img, &IMG->bpp, \ &IMG->sizeline, &IMG->endian); return (t_img); }
void render(t_env *e) { key_up_down(e); key_left_right(e); e->img = mlx_new_image(e->mlx, WIDTH, HEIGHT); e->imgpx = mlx_get_data_addr(e->img, &(e->bpp), &(e->size_line), &(e->endian)); raytrace(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); usleep(50); mlx_destroy_image(e->mlx, e->img); }
void initmlx() { char name[2]; name[0] = '1'; name[1] = 0; e.l = 1280; e.h = 800; e.mlx = mlx_init(); e.win = mlx_new_window(e.mlx, e.l, e.h, name); e.img = mlx_new_image(e.mlx, e.l, e.h); e.addr = mlx_get_data_addr(e.img, &(e.bpp), &(e.sizel), &(e.endian)); // bzero(e.tab, 10); }
void ft_launch(t_param *p, char *file) { if ((p->e.mlx = mlx_init()) == NULL) exit(ft_error("[Mlx init]: Initialisation impossible")); p->e.win = mlx_new_window(p->e.mlx, WIN_X, WIN_Y, p->file); p->e.img = mlx_new_image(p->e.mlx, WIN_X, WIN_Y); p->data = mlx_get_data_addr(p->e.img, &(p->bpp), &(p->sl), &(p->endian)); ft_work(p, 0); mlx_mouse_hook(p->e.win, &ft_mouse_hook, p); mlx_expose_hook(p->e.win, &ft_expose_hook, p); mlx_key_hook(p->e.win, &ft_key_hook, p); mlx_loop(p->e.mlx); }
static t_img *ft_init_img(t_env *init, int w, int h) { t_img *img; if (!(img = (t_img *)malloc(sizeof(*img)))) error("error : ft_init_img"); img->img = mlx_new_image(init->mlx, w, h); img->bpp = 0; img->sizel = 0; img->endn = 0; img->cimg = mlx_get_data_addr(img->img, &img->bpp, &img->sizel, &img->endn); return (img); }
int main(int ac, char **av) { t_rt rt; rt.mlx_ptr = mlx_init(); rt.win_ptr = mlx_new_window(rt.mlx_ptr , 400 , 400 , "My first window"); rt.img_ptr = mlx_new_image(rt.mlx_ptr, 400, 400); rt.data = mlx_get_data_addr(rt.img_ptr, &rt.bpp, &rt.sizeline, &rt.endian); remplis_image(&rt); mlx_put_image_to_window(rt.mlx_ptr, rt.win_ptr , rt.img_ptr, 0, 0); mlx_expose_hook(rt.win_ptr, gere_expose, &rt); mlx_loop(rt.mlx_ptr); }
t_gui new_gui(int w, int h, char *title) { t_gui env; env.mlx = mlx_init(); env.win = mlx_new_window(env.mlx, w, h, title); env.width = w; env.height = h; env.title = title; env.image = mlx_new_image(env.mlx, w, h); env.pixel = mlx_get_data_addr(env.image, &env.bpp, &env.sl, &env.endian); return (env); }
static int create_img(t_env *env) { t_img *img; env->img[10] = (t_img *)malloc(sizeof(t_img)); img = env->img[10]; if (!(img->img = mlx_new_image(env->ptr, SCREENWIDTH, SCREENHEIGHT))) exit (0); if (!(img->data = mlx_get_data_addr(img->img, &(img->bpp), &(img->sizel) , &(img->endian)))) exit (0); return (1); }
int init_mlx(t_win *win) { win->mlx = mlx_init(); win->win = mlx_new_window(win->mlx, WIDTH, HEIGHT, NAME); win->img = mlx_new_image(win->mlx, WIDTH, HEIGHT); win->endian = 1; win->bpp = 4; win->s_line = WIDTH; win->data = mlx_get_data_addr(win->img, &(win->bpp), &(win->s_line), &(win->endian)); mlx_key_hook(win->win, key_hook, win); // mlx_expose_hook(win->win, expose_hook, win); mlx_loop(win->mlx); return (0); }