창까지 띄웠으면, 이제 키보드 입력을 받아보자

먼저 SDL 의 이벤트 시스템에 대해서 간단히 알아보자

이벤트 풀

기본적으로 SDL 에서는 이벤트가 발생하면 이벤트를 이벤트 풀이라는곳에 다 담아둔다

https://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php

https://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php

이벤트 풀이 담겨있는 이벤트는 SDL_PollEvent 함수를 통해서 불러올 수 있다.

https://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php

https://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php

이렇게 불러온 이벤트는 불러온 이벤트 타입에 따라서 다양하게 처리 할 수있다.

다양한 이벤트 타입들은 아래의 링크에서 확인가능하다.

SDL_Event

SDL_EventType

그럼 이벤트 타입에 따라서 어떻게 이벤트를 처리할까

바로 저번에 봤던 코드가 이것이다.

bool quit = false;
	SDL_Event event;
	while(!quit){
		while(SDL_PollEvent(&event)){
			switch(event.type){
			case SDL_QUIT:
				quit = true;
				break;
			}
		}
		SDL_Delay(1);
	}

SDL_QUIT 는 종료 요청이 들어온경우, 발생되는 이벤트이다.

따라서 SDL_PollEvent(&event) 으로 이벤트 풀에 있는 이벤트를 계속 가져오고 그중에서 event.typeSDL_QUIT 인게 있으면, quit 변수를 바꾸는 방식으로 while 문을 탈출 할 수 있게 한것이다.

위와 같은 방식으로 type 에 따라서 이벤트를 다양하게 처리할 수 있다.

키 입력

다양한 이벤트 중에서도 키보드 이벤트에 대해서 좀더 알아보자