1 분 소요


# define KEY_RELEASE	3
# define KEY_EXIT		17
# define KEY_ESC		53
# define KEY_W			13
# define KEY_A			0
# define KEY_S			1
# define KEY_D			2

ESC버튼 53
17번은 모니터상 엑스표눌렀을때

mlx_init();
map_info.win = mlx_new_window(map_info.mlx, \
	map_info.width * 64, map_info.height * 64, "taehyeong's game");
	mlx_hook(map_info.win, KEY_RELEASE, 0, &key_press, &map_info);
	mlx_hook(map_info.win, KEY_EXIT, 0, &exit_game, &map_info);
	mlx_loop(map_info.mlx);
int		key_press(int keycode, t_map_info *map_info);

	void	*mlx;
	void	*win;

img.empty = mlx_xpm_file_to_image \
		(mlx, "./images/empty.xpm", &img_width, &img_height);
mlx_put_image_to_window(map_info.mlx, map_info.win, \
		map_info.img.empty, 64 * w, 64 * h);

	mlx_destroy_window(map_info->mlx, map_info->win);



MiniLibx는 MacOS의 Cocoa(Appkit)와 OpenGL을 필요로 하기 때문에 컴파일시 링킹이 필요하다.

CFLAGS = -Wall -Wextra -Werror -Imlx -c
$(NAME): $(OBJ)
	$(CC) $(OBJ) -Lmlx -lmlx -framework OpenGL -framework AppKit -o $(NAME)

OpenGL 3D구현을 위한 라이브러리중 하나로 저수준의 라이브러리이다.

Appkit MacOS에서 제공되는 유저인터페이스를 위한 API

l : 같이 링크할 라이브러리 지정 L : 라이브러리를 찾을 디렉토리 지정



png -> xpm 변환 사이트

void	*mlx_init();

OS의 디스플레이와 소프트웨어를 연결. 실패시 NULL 반환. mlx인스턴스를 생성하고 그 주소를 반환.

void	*mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);

디스플레이에 새 윈도우창을 생성. 윈도우 창의 인스턴스 포인터를 반환. 참조할 수 있도록 저장해야한다.

void *mlx_ptr : mlx 인스턴스 포인터
int size_x : 윈도우창 너비
int size_y : 윈도우창 높이
char *title : 윈도우창 이름


int mlx_loop ( void *mlx_ptr );

띄운 창에서 키보드와 마우스의 입력을 기다린다. 창의 일부를 다시 그릴 수도 있다.

int	mlx_destroy_window(void *mlx_ptr, void *win_ptr);

윈도우창의 인스턴스를 삭제한다.
void *mlx_ptr : mlx 인스턴스 포인터
void *win_ptr : 윈도우창의 인스턴스 포인터
반환값 없음.

Image

void	*mlx_new_image(void *mlx_ptr,int width,int height);

void *mlx_ptr : mlx 인스턴스 포인터
int width : 그릴 픽셀의 좌표
int height : 그릴 픽셀의 좌표

char	*mlx_get_data_addr(void *img_ptr, int *bits_per_pixel, int *size_line, int *endian);

hook

int mlx_hook(void win_ptr, int x_event, int x_mask, int (*funct)(), void *param);

void win_ptr : 윈도우창의 인스턴스 포인터
int x_event : X11 event
int x_mask : 사용하지 않음. 0 입력
int (*funct)() : 호출할 함수 포인터
void *param : 함수에 전달할 파라미터를 인자로 받는 함수

X11 Events

Key Event
2 Key Press
3 Key Release
4 Button Press
5 Button Release
6 Motion Notify
7 Enter Notify
8 Leave Notify
9 Focus in
10 Focus out
11 Keyman Notify
12 Expose
13 GraphicsExpose
14 No Expose
15 Visibility Notify
16 Create Notify
17 Destroy Notify
18 Unmap Notify
19 Map Notify
20 Map Request
21 Reparent Notify
22 Configure Notify
23 Configure Request
24 Gravity Notify
25 Resize Request

댓글남기기