所以我一直在关注this set of tutorials,以便在使用SDL制作游戏引擎之前先了解一下SDL的一般知识。但是,一旦我到达this part of the tutorial,我就开始遇到问题了。
每当我尝试使用IMG_Load或任何相关命令时,都会导致程序立即关闭。当我使用SDL_LoadBMP时,我做得很好,但现在问题才开始出现。即使我完全复制教程中的代码,它仍然希望不愉快。
bool init()
{
//Initialization flags
bool success = true;
//Initiralize SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL failed to initialize! Details: %s\n", SDL_GetError());
success = false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
//Create a window
gWindow = SDL_CreateWindow("densipoint", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(gWindow == 0)
{
printf("Window failed to display! Details: %s\n", SDL_GetError());
success = false;
}
else
{
//Create renderer for window
gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if(gRenderer == 0)
{
printf("Renderer failed to be created! Details: %s\n", SDL_GetError());
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor(gRenderer, 0xff, 0xff, 0xff, 0xff);
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ))
{
printf("SDL_image failed to initialize! Details: %s\n", IMG_GetError());
success = false;
}
}
}
}
return success;
}
任何想法/建议?我使用命令行MinGW和g ++编译器。
编辑:我已将问题缩小到初始化SDL_image的问题。
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ))
{
printf("SDL_image failed to initialize! Details: %s\n", IMG_GetError());
success = false;
}