我刚在我的 Mac 上安装了 SDL2 框架,但是虽然编译和运行程序都成功了,但窗口没有响应(我复制了创建一些矩形的代码)。
我使用的是 Xcode,并且按照这里的教程http://lazyfoo.net/tutorials/SDL/01_hello_SDL/mac/xcode/index.php一步一步地操作。
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
cout << " Ok" << endl;
//Wait two seconds
SDL_Delay( 20000 );
}
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0;
为什么会出现这个问题? 非常感谢。
SDL_Delay(20000)
表示窗口会冻结 20 秒。你应该添加一个消息循环。 - user7860670SDL_PollEvent
的消息循环,如此处所示 https://wiki.libsdl.org/SDL_PollEvent。 - JustSomeGuy