C++ SDL图像渲染困难

C++ SDL图像渲染困难,c++,xcode,macos,sdl,C++,Xcode,Macos,Sdl,嗨,各位飞越者! 我最近开始学习SDL。我选择了简单的直接媒体层作为我的C++ API的外部API,因为我发现它提供了游戏开发者最直观的增强机制。 #include <iostream> #include "SDL/SDL.h" using std::cerr; using std::endl; int main(int argc, char* args[]) { // Initialize the SDL if (SDL_Init(SDL_INIT_VIDEO) != 0) {

嗨,各位飞越者! 我最近开始学习SDL。我选择了简单的直接媒体层作为我的C++ API的外部API,因为我发现它提供了游戏开发者最直观的增强机制。
#include <iostream>
#include "SDL/SDL.h"

using std::cerr;
using std::endl;

int main(int argc, char* args[])
{
// Initialize the SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
    cerr << "SDL_Init() Failed: " << SDL_GetError() << endl;
    exit(1);
}

// Set the video mode
SDL_Surface* display;
display = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (display == NULL)
{
    cerr << "SDL_SetVideoMode() Failed: " << SDL_GetError() << endl;
    exit(1);
}

// Set the title bar
SDL_WM_SetCaption("SDL Tutorial", "SDL Tutorial");

// Load the image
SDL_Surface* image;
image = SDL_LoadBMP("LAND.bmp");
if (image == NULL)
{
    cerr << "SDL_LoadBMP() Failed: " << SDL_GetError() << endl;
    exit(1);
}

// Main loop
SDL_Event event;
while(1)
{
    // Check for messages
    if (SDL_PollEvent(&event))
    {
        // Check for the quit message
        if (event.type == SDL_QUIT)
        {
            // Quit the program
            break;
        }
    }
    // Game loop will go here...
    // Apply the image to the display
    if (SDL_BlitSurface(image, NULL, display, NULL) != 0)
    {
        cerr << "SDL_BlitSurface() Failed: " << SDL_GetError() << endl;
        exit(1);
    }

    //Update the display
    SDL_Flip(display);

}

// Tell the SDL to clean up and shut down
SDL_Quit();

return 0;    
}
#包括
#包括“SDL/SDL.h”
使用std::cerr;
使用std::endl;
int main(int argc,char*args[]
{
//初始化SDL
如果(SDL_Init(SDL_Init_视频)!=0)
{

cerr您应该能够使用图像的绝对(完整)路径来测试代码。这将验证代码是否实际工作

为了能够使用具有绝对路径的资源,您应该创建一个生成阶段来复制文件。目标应设置为“产品目录”。您可以将子路径留空或提供一个目录来放置资源(当您获得大量资源时,这将非常有用)例如纹理。如果你提供了一个子路径,那么修改你的代码,使之成为
textures/LAND.bmp

您还可以使用构建阶段将SDL2.framework和任何其他(如SDL2_映像等)打包到最终应用程序中。这将允许计算机上没有SDL的用户运行应用程序。为此,请创建另一个构建阶段,将dentiation设置为“Frameworks”,并将子路径保留为空。然后只需添加任何框架即可您希望与应用程序打包。您希望在内部版本设置中进行的另一项设置是将“运行路径搜索路径”(在“链接”下找到)更改为
@executable\u path/。/Frameworks
,以便应用程序知道在何处查找打包的框架

我有一个关于在Xcode中配置SDL2的教程,还有一个模板可以让它快速运行


非常感谢!我成功地添加了构建阶段,砰,它成功了。非常感谢您的帮助。