cub3d (1 일차) - MiniLibX

HJ·2021년 3월 4일
0

cub3d

목록 보기
1/1

MiniLibX

윈도우 인터페이스 라이브러리
다음내용들은 man의 내용을 그대로 옮긴것임

To use MiniLibX functions, you may need to link your software with several libraries, including the MiniLibX library itself. On Unix/Linux, simply add the following arguments at linking time:

-lmlx -lXext -lX11

On MacOS, the dynamic Metal library will find on its own the missing components:

-lmlx

and still on MacOS, the static OpenGL version will need:

-lmlx -framework OpenGL -framework AppKit -lz

You may also need to specify the path to these libraries, using the -L flag.

여기서,
mlx_ptr은 mlx_init()에서 봔환된 값으로, 연결 식별자이다.
mlx_win은 mlx_new_window()에서 반환된 값으로, 창 식별자이다.

시작

1. void *mlx_init();

  • 시작함수
  • 소프트웨어와 디스플레이를 연결
  • 연결 실패시 NULL 또는 non-null pointer 리턴

이벤트 제어

2. int mlx_loop(void *mlx_ptr);

  • 이벤트 제어함수 (hanle keyboard or mouse events)
  • 이벤트에 연결되는 사용자 정의 함수를 호출한다.
    -키보드에 따른 이벤트,
    -마우스버튼에 따른 이벤트,
    -expose이벤트 (A part of the window should be re-drawn)
int mlx_key_hook ( void *win_ptr, int (*funct_ptr)(), void *param );

int mlx_mouse_hook ( void *win_ptr, int (*funct_ptr)(), void *param );

int mlx_expose_hook ( void *win_ptr, int (*funct_ptr)(), void *param );
  • mlx_ptr 이 필요함

이미지 조작

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

  • 새 이미지를 메모리에 생성시킨다.
  • 에러 발생시 NULL 리턴
  • 이미지를 조작하는데 필요한 이미지 식별자를 리턴한다.
  • 이미지 사이즈 (width * height)와 mlx_ptr이 필요하다.

4. int mlx_put_image_to_window ( void mlx_ptr, void win_ptr, void *img_ptr, int x, int y );

  • 디스플레이연결, 사용한 윈도우창 그리고 이미지 셋의 포인터가 필요
  • x와 y의 값은 이미지를 배치할 위치를 정한다.

5. int mlx_destroy_image (void mlx_ptr, void img_ptr );

  • 주어진 이미지를 삭제한다.
  • mlx_ptr 과 img_ptr이 필요하다.

창 관리

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

  • 새창을 스크린에 띄운다.
  • size_x, size_y (창 사이즈)

7. int mlx_destroy_window(void mlx_ptr, void win_ptr);

  • 지정된 창을 끈다.

8. Int mlx_pixel_put (void mlx_ptr, void win_ptr, int x, int y, int color):

  • 지정된 픽셀을 color로 win_ptr이 가르키는 window의 x, y좌표상에 그린다.

9. int mlx_string_put(void mlx_ptr, void win_ptr, int x, int y, int color, char *string);

  • 지정된 string을 color의 색으로 win_ptr이 가르키는 window의 x, y 좌표상에 출력한다.

color
= 0xTTRRGGBB
0x | T | R | G | B | --> color interger

  • 컬러 인코딩하기
int trgb(int t, int r, int g, int b)
{
	return (t << 24 | r << 16 | g << 8 | b);
}
  • 컬러 디코딩하기
예) t값
int get_t(int trgb)
{
	return (trgb & (0xFF << 24));
}

0개의 댓글