【发布时间】:2023-12-16 21:47:01
【问题描述】:
嗨,溢出者们! 我最近开始学习 SDL。我选择简单的直接媒体层作为我的 C++ 知识的外部 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;
}
我所做的只是制作了一个屏幕表面,对其进行双重缓冲,制作了图像的另一个表面,将两者结合在一起,并且由于某种原因,当我构建应用程序时,它会立即关闭!应用程序构建成功,但随后在没有打开窗口的情况下关闭!这真是令人沮丧。
我正在使用 XCode5 和 SDL 2.0.3 :)
需要帮助!
编辑:在错误日志中显示为SDL_LoadBMP(): Failed to load LAND.bmp。 bmp保存在根目录下,和main.cpp文件夹是同一个文件夹?为什么这不起作用?
【问题讨论】: