Exemplo n.º 1
0
void			ft_init(t_env *env)
{
	ft_calc_cam(env);
	env->mlx = mlx_init();
	env->window = mlx_new_window(env->mlx, WIDTH, HEIGHT, TITLE);
	env->img = mlx_new_image(env->mlx, WIDTH, HEIGHT);
	env->data = mlx_get_data_addr(env->img, &env->bpp,
										&env->size_line, &env->endian);
	env->calc->ambient = (double)AMBIENT;
	ft_scene(env);
	mlx_key_hook(env->window, ft_key_hook, env);
	mlx_expose_hook(env->window, ft_expose_hook, env);
	mlx_loop(env->mlx);
}
Exemplo n.º 2
0
t_gui	new_gui(int w, int h, char *title)
{
	t_gui	gui;

	if ((gui.mlx = mlx_init()) == NULL)
		ft_exit(0, "FetalError: mlx could not initialize");
	gui.win = mlx_new_window(gui.mlx, w, h, title);
	gui.width = w;
	gui.height = h;
	gui.title = title;
	gui.image = mlx_new_image(gui.mlx, w, h);
	gui.pixel = mlx_get_data_addr(gui.image, &gui.bpp, &gui.sl, &gui.endian);
	return (gui);
}
Exemplo n.º 3
0
int		ft_wolf3d(t_glob *gl)
{
	gl->img = mlx_new_image(gl->mlx, gl->s_x, gl->s_y);
	gl->disp = mlx_get_data_addr(gl->img, &(gl->bpp), &(gl->sizeline),
			&(gl->endian));
	ft_move_rot(gl);
	ft_detect_wall(gl);
	mlx_string_put(gl->mlx, gl->win, 20, 20, 0xFFFFFF, "FPS : ");
	mlx_string_put(gl->mlx, gl->win, 80, 20, 0xFFFFFF,
			ft_itoa(1.0 / gl->ftime));
	if (gl->sprint)
		gl->ms = gl->ms * 2;
	return (0);
}
Exemplo n.º 4
0
static void		ft_init_env(t_env *e)
{
	t_img	*i;

	i = e->img;
	i->img = mlx_new_image(e->mlx, WIDTH, HEIGHT);
	i->addr = mlx_get_data_addr(i->img, &i->bpp, &i->ln_size, &i->endian);
	i->color = 0x4B0082;
	i->pos_x = 1.0;
	i->pos_y = 1.0;
	i->angle = 0.0;
	ft_draw_wall(e);
	mlx_put_image_to_window(e->mlx, e->win, i->img, 0, 0);
}
Exemplo n.º 5
0
void			get_textures(t_v_env *param, void *e)
{
	T0.file = "./textures/0.xpm";
	T0.img = mlx_xpm_file_to_image(e, T0.file, &T0.size_x, &T0.size_y);
	if (T0.img == NULL)
		v_exit("%r#20", 20);
	T0.data = mlx_get_data_addr(T0.img, &T0.bpp, &T0.sizeline, &T0.endian);
	T1.file = "./textures/1.xpm";
	T1.img = mlx_xpm_file_to_image(e, T1.file, &T1.size_x, &T1.size_y);
	if (T1.img == NULL)
		v_exit("%r#20", 20);
	T1.data = mlx_get_data_addr(T1.img, &T1.bpp, &T1.sizeline, &T1.endian);
	T2.file = "./textures/2.xpm";
	T2.img = mlx_xpm_file_to_image(e, T2.file, &T2.size_x, &T2.size_y);
	if (T2.img == NULL)
		v_exit("%r#20", 20);
	T2.data = mlx_get_data_addr(T2.img, &T2.bpp, &T2.sizeline, &T2.endian);
	T3.file = "./textures/3.xpm";
	T3.img = mlx_xpm_file_to_image(e, T3.file, &T3.size_x, &T3.size_y);
	if (T3.img == NULL)
		v_exit("%r#20", 20);
	T3.data = mlx_get_data_addr(T3.img, &T3.bpp, &T3.sizeline, &T3.endian);
	get_text_sequel(param, e);
}
Exemplo n.º 6
0
void    ft_initialization(t_id *s)
{
    s->x1 = -2.1;
    s->x2 = 0.6;
    s->y1 = -1.2;
    s->y2 = 1.2;
    s->iter_max = 50;
    s->zoom = 1;
    s->oldx1 = s->x1;
    s->oldy1 = s->y1;
    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;
}
Exemplo n.º 7
0
void	my_pixel_put_to_image(t_img *myimg, int x, int y, int color)
{
	int				i;
	unsigned char	color1;
	unsigned char	color2;
	unsigned char	color3;

	myimg->data = mlx_get_data_addr(myimg->img_ptr,
			&myimg->bpp, &myimg->sizeline, &myimg->endian);
	myimg->data[y * myimg->sizeline + x * myimg->bpp / 8] = color % 256;
	color /= 256;
	myimg->data[y * myimg->sizeline + x * myimg->bpp / 8 + 1] = color % 256;
	color /= 256;
	myimg->data[y * myimg->sizeline + x * myimg->bpp / 8 + 2] = color % 256;
}
Exemplo n.º 8
0
void	mlx_initialize(t_gfx *g)
{
	g->mlx = mlx_init();
	if (!g->mlx)
		die("Count not init mlx");
	if (!(g->win = mlx_new_window(g->mlx, g->width, g->height, "Raytracer")))
		die("Could not create the window.");
	if (!(g->img = mlx_new_image(g->mlx, g->width, g->height)))
		die("Could not create the image.");
	g->data = mlx_get_data_addr(g->img, &g->bpp, &g->line_size, &g->endian);
	if (!g->data)
		die("Could not get image data.");
	mlx_hooks_init(g);
	mlx_loop(g->mlx);
}
Exemplo n.º 9
0
static void			init_mlx_ptr(t_rt *rt)
{
  if ((rt->mlx.mlx_ptr = mlx_init()) == NULL)
    exit(EXIT_FAILURE);
  if ((rt->mlx.win_ptr
       = mlx_new_window(rt->mlx.mlx_ptr,
                        WIDTH, HEIGHT, WINDOW_NAME)) == NULL
      || (rt->mlx.img_ptr =
	  mlx_new_image(rt->mlx.mlx_ptr, WIDTH, HEIGHT)) == NULL
      || (rt->mlx.data = mlx_get_data_addr(rt->mlx.img_ptr,
					  &rt->mlx.bits,
					  &rt->mlx.sizeline,
					  &rt->mlx.endian)) == NULL)
    my_error("error: mlx: An error has occured.\n", 0);
}
Exemplo n.º 10
0
t_image		*ft_mlx_new_image(void *mlx, int width, int height)
{
	t_image		*img;

	if ((img = malloc(sizeof(t_image))) == NULL)
		return (NULL);
	img->width = width;
	img->height = height;
	if ((img->img_ptr = mlx_new_image(mlx, width, height)) == NULL)
		return (NULL);
	if ((img->data_addr = mlx_get_data_addr(img->img_ptr,
			&(img->bits_per_pixel), &(img->size_line), &(img->endian))) == NULL)
		return (NULL);
	return (img);
}
Exemplo n.º 11
0
void		window_init(t_window *w)
{
  w->x = 500;
  w->y = 500;
  w->xs = 50;
  w->ys = 50;
  w->zs = 50;
  if ((w->mlx_ptr = mlx_init()) == NULL)
    my_exit2("Error -> Mlx_init Failed");
  w->win_ptr = mlx_new_window(w->mlx_ptr, w->x, w->y,
			      "Raytracer - V1 - Julien Karst");
  w->img_ptr = mlx_new_image(w->mlx_ptr, w->x, w->y);
  w->img_tab = (int*)mlx_get_data_addr(w->img_ptr, &(w->bpp),
				       &(w->sizeline), &(w->endian));
}
Exemplo n.º 12
0
int key_reaction(int keycode, t_id *param)
{
	param->dp = 25;
	if (keycode == 53)
		exit(0);
	if (keycode == 49)
	{
		param->img = mlx_new_image(param->img, W_X, W_Y);
		param->data = mlx_get_data_addr(param->img, &param->bit_per_pixel, &param->s_line, &param->endian);
		param->bpp = param->bit_per_pixel / 8;
		ft_display_hor(param);
		ft_display_ver(param);
	}
	if (keycode == 69)
	{
		mlx_destroy_image(param->mlx, param->img);
		param->img = mlx_new_image(param->img, W_X, W_Y);
		param->data = mlx_get_data_addr(param->img, &param->bit_per_pixel, &param->s_line, &param->endian);
		param->bpp = param->bit_per_pixel / 8;
		param->dp = param->dp + 5;
		ft_display_ver(param);
		ft_display_hor(param);
	}
	if (keycode == 78)
	{
		mlx_destroy_image(param->mlx, param->img);
		param->img = mlx_new_image(param->img, W_X, W_Y);
		param->data = mlx_get_data_addr(param->img, &param->bit_per_pixel, &param->s_line, &param->endian);
		param->bpp = param->bit_per_pixel / 8;
		param->dp = param->dp - 5;
		ft_display_ver(param);
		ft_display_hor(param);
	}
	mlx_put_image_to_window(param->mlx, param->win, param->img, 0, 0);
	return (0);	
}
Exemplo n.º 13
0
int		load_each_texture(t_each_text *texture, char *path,
				  t_data *data)
{
  texture->texture = mlx_xpm_file_to_image(data->windo.mlx_ptr,
					   path,
					   &(texture->size_x),
					   &(texture->size_y));
  if (texture->texture == NULL)
    return (FAIL);
  texture->data = mlx_get_data_addr(texture->texture,
				    &(texture->bpp),
				    &(texture->sizeline),
				    &(texture->endian));
  return (SUCCES);
}
Exemplo n.º 14
0
t_img	*ft_load_img(void *mlx, char *src)
{
	t_img	*i;

	if (!src || !(i = (t_img*)malloc(sizeof(t_img))))
		return (NULL);
	if (!(i->img = mlx_xpm_file_to_image(mlx, src, &(i->width), &(i->height))))
		return (NULL);
	i->data = mlx_get_data_addr(i->img, &(i->bpp),
								&(i->sizeline), &(i->endian));
	i->sl_div = i->sizeline / 4;
	i->bpp_div = i->bpp / 8 / 4;
	i->udata = (unsigned int*)i->data;
	return (i);
}
Exemplo n.º 15
0
void	image(t_env *e)
{
	if (e->img)
		mlx_destroy_image(e->mlx, e->img);
	e->img = mlx_new_image(e->mlx, e->image_x, e->image_y);
	e->img_addr = mlx_get_data_addr(e->img,
			&e->bits_pix, &e->size_line, &e->end);
	if (ft_strcasecmp(e->fract, "mandelbrot") == 0)
		display_mandelbrot(e);
	if (ft_strcasecmp(e->fract, "julia") == 0)
		display_julia(e);
	if (ft_strcasecmp(e->fract, "carpet") == 0)
		display_carpet(e);
	mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0);
}
Exemplo n.º 16
0
void		printselected(t_data *e, int q)
{
	t_overview	over;
	char		*path;

	e->index_q = q;
	e->img = mlx_new_image(e->mlx_ptr, IMG_H, IMG_W);
	e->str = mlx_get_data_addr(e->img, &(e->bpp), &(e->sl), &(e->nd));
	path = ft_strjoin("./samples/", e->path);
	over = ft_parser(path);
	render(e, over);
	ft_expose_hook(e);
	mlx_expose_hook(e->mlx_win, ft_expose_hook, e);
	free(path);
}
Exemplo n.º 17
0
void		create_win(t_screen *screen)
{
  PX(screen->mlx = mlx_init());
  PX(screen->win = mlx_new_window(screen->mlx,
			       screen->width, screen->height,
				  "Raytracer"));
  PX(screen->img.img = mlx_new_image(screen->mlx,
				  screen->width, screen->height));
  PX(screen->img.data = mlx_get_data_addr(screen->img.img,
					  &screen->img.bpp,
					  &screen->img.sizeline,
					  &screen->img.endian));
  screen->img.x_size = screen->width;
  screen->img.y_size = screen->height;
}
Exemplo n.º 18
0
void	init(t_lx *mlx)
{
  mlx->mlx_ptr = mlx_init();
  mlx->img_ptr = mlx_new_image(mlx->mlx_ptr, WIDTH, HEIGHT);
  mlx->win_ptr = mlx_new_window(mlx->mlx_ptr, WIDTH, HEIGHT, "Wolf3D");
  mlx->data = (unsigned char *)mlx_get_data_addr
    (mlx->img_ptr, &(mlx->bpp), &(mlx->sizeline), &(mlx->endian));
  mlx->floor_cl = 110;
  mlx->sky_cl = 60;
  mlx->n_cl = 40;
  mlx->s_cl = 200;
  mlx->e_cl = 100;
  mlx->w_cl = 240;
  mlx->ang = 0;
  aff_first_ok_img(mlx);
}
Exemplo n.º 19
0
void	start_write(t_map *w)
{
	w->zoom = 15;
	w->prof = w->zoom / 7;
	w->flag = 0;
	w->mlx = mlx_init();
	size_win(w);
	w->win = mlx_new_window(w->mlx, w->width, w->height, "FDF");
	w->img = mlx_new_image(w->mlx, w->width, w->height);
	w->data = mlx_get_data_addr(w->img, &(w->bpp), &(w->sizeline), &(w->endian));
	mlx_hook(w->win, 2, 3, check_keys, w);
	draw(w);
	mlx_put_image_to_window(w->mlx, w->win, w->img, 0, 0);
	mlx_string_put(w->mlx, w->win, 20, 1, 0xFFFFFF, "PRESS 'I' FOR INFO");
	mlx_loop(w->mlx);
}
Exemplo n.º 20
0
t_img	*ft_new_img(void *mlx, int width, int height)
{
	t_img	*i;

	if (!(i = (t_img*)malloc(sizeof(t_img))))
		return (NULL);
	i->width = width;
	i->height = height;
	i->img = mlx_new_image(mlx, width, height);
	i->data = mlx_get_data_addr(i->img, &(i->bpp),
								&(i->sizeline), &(i->endian));
	i->sl_div = i->sizeline / 4;
	i->bpp_div = i->bpp / 8 / 4;
	i->udata = (unsigned int*)i->data;
	return (i);
}
Exemplo n.º 21
0
void	map_processing(t_e *e)
{
	e->mlx = mlx_init();
	e->win = mlx_new_window(e->mlx, WIN_W, WIN_H, WIN_N);
	e->ima = mlx_new_image(e->mlx, WIN_W, WIN_H);
	e->ima_data = mlx_get_data_addr(
			e->ima, &(e->ima_bits), &(e->ima_line), &(e->ima_endi));
	e->grid = create_grid(e);
	reset(e);
	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_hook(e->win, 17, (1L << 17), &end_exe, e);
	mlx_hook(e->win, 2, (1L << 0), &key_hook_press, e);
	mlx_loop(e->mlx);
}
Exemplo n.º 22
0
int			main(int argc, char **argv)
{
	t_env env;

	(void)argc;
	(void)argv;
	t_env_init(&env);
	env.mlx = mlx_init();
	env.win = mlx_new_window(env.mlx, L_SIZE, H_SIZE, "SUNAKU");
	env.image = mlx_new_image(env.mlx, L_SIZE, H_SIZE);
	env.img = mlx_get_data_addr(env.image, &env.bpp, &env.sline, &env.endiant);
	mlx_hook(env.win, 2, 1, key_up_hook, &env);
	mlx_loop_hook(env.mlx, expose_hook, &env);
	mlx_loop(env.mlx);
	return (0);
}
Exemplo n.º 23
0
int     init_mlx(t_mlx *mlx)
{
  int   *ret;

  ret = mlx->mlx_ptr = mlx_init();
  if (ret == NULL)
    exit(EXIT_FAILURE);
  ret = mlx->win_ptr = mlx_new_window(mlx->mlx_ptr, WIN_X, WIN_Y, WIN_NAME);
  if (ret == NULL)
    exit(EXIT_FAILURE);
  ret = mlx->img_ptr = mlx_new_image(mlx->mlx_ptr, WIN_X, WIN_Y);
  if (ret == NULL)
    exit(EXIT_FAILURE);
  mlx->data = mlx_get_data_addr(mlx->img_ptr, &(mlx->bpp),
				&(mlx->size_line), &(mlx->endian));
}
Exemplo n.º 24
0
int		ft_move(t_env *env)
{
	env->adr = mlx_new_image(env->mlx, env->win_h, env->win_l);
	env->img = mlx_get_data_addr(env->adr, &env->bpp, &env->sl, &env->endian);
	ft_fractal(env);
	mlx_put_image_to_window(env->mlx, env->win, env->adr, 0, 0);
	mlx_string_put(env->mlx, env->win, 50, 5, 0xff0000,
			"zoom:");
	mlx_string_put(env->mlx, env->win, 50, 30, 0xff0000,
	ft_itoa(env->zoom));
	mlx_string_put(env->mlx, env->win, 390, 30, 0xff0000,
			ft_itoa(env->imax));
	mlx_string_put(env->mlx, env->win, 390, 5, 0xff0000,
			"iteration:");
	return (0);
}
Exemplo n.º 25
0
Arquivo: main.c Projeto: vdaviot/Fdf
static void	ft_init(t_env *env)
{
	env->color = 0xfdffef;
	env->mlx = mlx_init();
	env->win = mlx_new_window(env->mlx, WIN_X, WIN_Y, "42");
	env->img = mlx_new_image(env->mlx, WIN_X, WIN_Y);
	env->data = mlx_get_data_addr(env->img, &env->bpp, &env->sline, &env->end);
	env->count = 0;
	env->high = 0;
	env->copy = NULL;
	env->zoomplus = 0;
	env->padx = X_SIZE;
	env->pady = Y_SIZE;
	env->a = 1;
	if (!(env->ptr2 = (t_coord*)malloc(sizeof(t_coord))))
		return ;
}
Exemplo n.º 26
0
void		ft_create_image(t_window *w, int i) // Bolean : en fonction du "i", cree l'image et place son contenu dans la fenetre ou la detruit. Appelee dans ft_draw
{
	int		size;
	int		endian;
	int		bpp;

	if (i == 1)
	{
		w->img_ptr = mlx_new_image(w->mlx, 800, 500);
		w->content = mlx_get_data_addr(w->img_ptr, &bpp, &size, &endian);
	}
	if (i == 2)
	{
		mlx_put_image_to_window(w->mlx, w->win, w->img_ptr, 0, 0);
		mlx_destroy_image(w->mlx, w->img_ptr);
	}
}
Exemplo n.º 27
0
int             my_put_pixel_in_img(void *img, t_coord *coord, t_color *color)
{
  int           bpp;
  int           sizeline;
  int           endian;
  char		*data;

  if (img == NULL || coord == NULL || color == NULL)
    return (1);
  if ((data = mlx_get_data_addr(img, &bpp, &sizeline, &endian)) == NULL)
    return (2);
  data[coord->y * sizeline + coord->x * 4] = color->b;
  data[coord->y * sizeline + coord->x * 4 + 1] = color->v;
  data[coord->y * sizeline + coord->x * 4 + 2] = color->r;
  data[coord->y * sizeline + coord->x * 4 + 3] = endian;
  return (0);
}
Exemplo n.º 28
0
Arquivo: init.c Projeto: Truphino/fdf
t_mlx			*init_mlx(int x, int y, t_ref *d_ref)
{
    t_mlx		*d_mlx;

    if ((d_mlx = (t_mlx *)ft_memalloc(sizeof(t_mlx))) == NULL)
        return (NULL);
    if ((d_mlx->mlx = mlx_init()) == NULL)
        return (NULL);
    d_mlx->win = mlx_new_window(d_mlx->mlx, x, y, "Fdf");
    d_mlx->size_x = x;
    d_mlx->size_y = y;
    d_mlx->img = mlx_new_image(d_mlx->mlx, x, y);
    d_mlx->c_img = mlx_get_data_addr(d_mlx->img,
                                     &(d_mlx->bit), &(d_mlx->size_line), &(d_mlx->endian));
    d_mlx->d_ref = d_ref;
    return (d_mlx);
}
Exemplo n.º 29
0
void	ft_new_image(t_mlx *mlx)
{
	t_img	*img;
	void	*d;

	if (!(img = (t_img *)ft_memalloc(sizeof(t_img))))
		return ;
	img->endian = 0;
	img->width = mlx->width;
	img->p_img = mlx_new_image(mlx->p_mlx, mlx->width, mlx->height);
	if (!img->p_img)
		return ;
	d = mlx_get_data_addr(img->p_img, &img->bpp, &img->width, &img->endian);
	img->octet = img->bpp / 8;
	img->data = d;
	mlx->mlx_img = img;
	mlx->mlx_img->max_size = img->octet * mlx->width * mlx->height;
}
Exemplo n.º 30
0
int		main(int ac, char **av)
{
	t_env	e;

	init_var(ac, av, &e);
	e.mlx = mlx_init();
	if (e.mlx == NULL)
		exit(0);
	e.win = mlx_new_window(e.mlx, W_WIDTH, W_HEIGHT, "Fract'ol");
	e.img = mlx_new_image(e.mlx, W_WIDTH, W_HEIGHT);
	e.data = mlx_get_data_addr(e.img, &e.bpp, &e.sl, &e.endian);
	mlx_hook(e.win, MotionNotify, PointerMotionMask, mouse_move, &e);
	mlx_expose_hook(e.win, expose_hook, &e);
	mlx_mouse_hook(e.win, mouse_hook, &e);
	mlx_key_hook(e.win, key_hook, &e);
	mlx_loop(e.mlx);
	return (0);
}