位图无法在 SDL 中加载
Bitmap won't load in SDL
***固定
*****结果我的位图文件被破坏了。我可以打开文件查看,但我的应用程序无法查看。我制作了一个新的图像,效果很好。
我在sdl中显示位图图像时遇到问题。程序以代码2退出,所以我知道位图没有加载。我在windows 7 64位上使用vc2010。BMP的名称是hello.BMP,我试着把它放在应用程序文件、源文件和项目文件旁边,但它仍然无法加载它。我也试过把它放进c:\中,然后从那里加载它,但没有成功。这是我第一次尝试使用SDL。这是代码:
#include "stdlib.h"
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_Surface *screen; //This pointer will reference the backbuffer
SDL_Surface *image; //This pointer will reference our bitmap sprite
SDL_Surface *temp; //This pointer will temporarily reference our bitmap sprite
SDL_Rect src, dest; //These rectangles will describe the source and destination regions of our blit
//We must first initialize the SDL video component, and check for success
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %sn", SDL_GetError());
return 1;
}
//When this program exits, SDL_Quit must be called
atexit(SDL_Quit);
//Set the video mode to fullscreen 640x480 with 16bit colour and double-buffering
screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
if (screen == NULL) {
printf("Unable to set video mode: %sn", SDL_GetError());
return 1;
}
//Load the bitmap into a temporary surface, and check for success
temp = SDL_LoadBMP("hello.bmp");
if (temp == NULL) {
printf("Unable to load bitmap: %sn", SDL_GetError());
return 2;
}
//Convert the surface to the appropriate display format
image = SDL_DisplayFormat(temp);
//Release the temporary surface
SDL_FreeSurface(temp);
//Construct the source rectangle for our blit
src.x = 0;
src.y = 0;
src.w = image->w; //Use image->w to display the entire width of the image
src.h = image->h; //Use image->h to display the entire height of the image
//Construct the destination rectangle for our blit
dest.x = 100; //Display the image at the (X,Y) coordinates (100,100)
dest.y = 100;
dest.w = image->w; //Ensure the destination is large enough for the image's entire width/height
dest.h = image->h;
//Blit the image to the backbuffer
SDL_BlitSurface(image, &src, screen, &dest);
//Flip the backbuffer to the primary
SDL_Flip(screen);
//Wait for 2500ms (2.5 seconds) so we can see the image
SDL_Delay(2500);
//Release the surface
SDL_FreeSurface(image);
//Return success!
return 0;
}
您正在加载位图。因此,如果你正在使用visualstudio,有一个简单的解决方案。转到add new file
,然后单击resource
。有一个位图文件可以在visualstudio中创建。因此,复制您的位图,然后在visualstudio上单击编辑,打开位图并单击粘贴。Boom完成后,将您的图像名称更改为代码中的图像,然后它就会正常工作,因为没有链接问题。
相关文章:
- 无法在 macOS 上的 SDL 游戏中加载图像
- 如何使用 emscripten 使用 SDL 将纹理加载到 WebAssembly 项目中
- 带有SDL/加载库的现代OpenGL
- SDL加载项库未正确链接
- 在visual Studio 2012上使用SDL加载.BMP图像时,它只显示一个帧
- 从 zip 加载到 SDL,代码在 x64 中工作,但不能在 x86 中工作
- 使用 SDL 加载 OpenGL 纹理
- SDL 无法在 2.1 Mac OSX Yosemite 上加载 OpenGL 上下文
- Xcode 5 C++SDL应用程序未在Xcode IDE外部加载
- SDL从文件加载图像
- 在SDL中对X位图加载器进行编码
- c++ OpenGL/SDL 2.0加载纹理失败
- SDL加载我的图像搞砸了
- 如何在SDL上加载原始像素位图
- SDL无法使用文件和标头加载媒体
- 为什么SDL不加载我的图像时,主应用程序通过快捷方式访问
- C++ - SDL/OpenGL 加载的图像的颜色反转
- 位图无法在 SDL 中加载
- C++/SDL从lua加载字符串数组
- SDL-未加载图像