bool Game::Init(const char* parTitle, int parXPos, int parYpos, int parWidth, int parHeight, int parFlags)
{
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "SDL init success\n";
// init the window
m_pWindow = SDL_CreateWindow(parTitle, parXPos, parYpos,
parWidth, parHeight, parFlags);
if (m_pWindow != 0) // window init success
{
std::cout << "window creation success\n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if (m_pRenderer != 0) // renderer init success
{
std::cout << "renderer creation success\n";
// 파란색 화면.
SDL_SetRenderDrawColor(m_pRenderer, 0, 0, 255, 255);
}
else
{
std::cout << "renderer init fail\n";
return false; // renderer init fail
}
}
else
{
std::cout << "window init fail\n";
return false; // window init fail
}
}
else
{
std::cout << "SDL init fail\n";
return false; // SDL init fail
}
std::cout << "init success\n";
m_bRunning = true; // everything inited successfully, start the main loop
/////////////////////////////////////////////////////////////////////////////////////////////
// 테스트를 위해서 임의로 init에서 그림을 생성하겠다.
// surface 생성
SDL_Surface* pTempSurface = IMG_Load("assets/enemy.png");
// surface를 이용해 texture 생성
m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer, pTempSurface);
// 사용한 surface 해제
SDL_FreeSurface(pTempSurface);
// 이제는 Texture를 이용해 그림을 그릴 준비가 끝났다.
// 우리가 로드한 텍스처에서 그림의 크기를 가져온다.
SDL_QueryTexture(m_pTexture, NULL, NULL, &m_sourceRectangle.w, &m_sourceRectangle.h);
// 그림이 뿌려질 x,y좌표를 0으로 설정한다.
m_destinationRectangle.x = m_sourceRectangle.x = 0;
m_destinationRectangle.y = m_sourceRectangle.y = 0;
// 본래 그림의 width, height 를 뿌려질 크기로 똑같이 설정.
m_destinationRectangle.w = m_sourceRectangle.w;
m_destinationRectangle.h = m_sourceRectangle.h;
/////////////////////////////////////////////////////////////////////////////////////////////
return true;
}