1

我有一个在 xcode 中制作的 SDL 应用程序。

int main( int argc, char* args[] )
{
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //The images
    SDL_Surface* hello = NULL;
    SDL_Window* screen = NULL;
    SDL_Renderer *sdlRenderer = NULL;

    //Set up screen
    screen = SDL_CreateWindow("My Game Window",
                          SDL_WINDOWPOS_UNDEFINED,
                          SDL_WINDOWPOS_UNDEFINED,
                          640, 480,
                          SDL_WINDOW_OPENGL);

    //Create Renderer
    sdlRenderer = SDL_CreateRenderer(screen, -1, 0);

    //Load image
    hello = SDL_LoadBMP( "hello.bmp" );

    //Create texture from the surface
    SDL_Texture* hello_texture = SDL_CreateTextureFromSurface(sdlRenderer, hello);

    //copy texture to the renderer's buffer.
    SDL_RenderCopy(sdlRenderer, hello_texture, NULL, NULL);

    //Update Screen
    SDL_RenderPresent(sdlRenderer);

    //Pause
    SDL_Delay( 5000 );

    //Quit SDL
    SDL_Quit();

    return 0;
}

所以一切正常,但没有图像出现。调试后发现load_bmp返回null。所以我试图通过这个找出正确的文件路径应该是什么:

 CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
    CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle );
    resourcesURL = CFBundleCopyResourceURL(
                                      mainBundle,
                                      CFSTR("hello.bmp"),
                                      NULL,
                                      NULL
                                      );

但这也没有给我任何东西,所以似乎 hello.bmp 没有正确地复制到包中?有没有其他人遇到过这个并且不需要做什么?

4

0 回答 0