简体   繁体   English

C ++ - SDL无法正常工作

[英]C++ - SDL not working

I've tried to follow this tutorial on the basics of displaying an image with SDL. 我试图按照教程关于使用SDL显示图像的基础知识。 But, when I run the program, it returns a blank screen. 但是,当我运行程序时,它返回一个空白屏幕。 The image is in the correct directories, but it doesn't display in the program. 图像位于正确的目录中,但不会显示在程序中。 Am I doing something wrong? 难道我做错了什么? I'd really like SDL to work. 我真的很喜欢SDL。

EDIT 编辑

Here is my code: 这是我的代码:

#include <SDL/SDL.h>

using namespace std;

int main(int argc, char *argv[])
{
    SDL_Surface *hello;
    SDL_Surface *screen;
    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    hello = SDL_LoadBMP("hello.bmp");
    SDL_BlitSurface(hello, NULL, screen, NULL);
    SDL_Flip(screen);
    SDL_Delay(2000);
    SDL_FreeSurface(hello);
    SDL_Quit();
    return 0;
}

Use SDL_GetError() to find out why SDL_LoadBMP() fails loading your bitmap. 使用SDL_GetError()来找出SDL_LoadBMP()无法加载位图的原因。
Read this thread too 也读这个帖子

而不是SDL_Flip(screen)尝试使用SDL_UpdateRect(screen,0,0,0,0)

I thought I said I had fixed this months ago, seems as though I had not. 我以为我说我几个月前已经修好了,好像我没有。 I recompiled it again and it worked, very strange. 我再次重新编译它,它很有效,非常奇怪。

In the line: "hello = SDL_LoadBMP("hello.bmp");" 在行中: "hello = SDL_LoadBMP("hello.bmp");" , try "/hello.bmp" instead of "hello.bmp" . ,尝试"/hello.bmp"而不是"hello.bmp" I had the same problem but it seems that putting the slash ("/") before the file name helps in find and therefore, render the image, even if it isn't on the same directory as the program. 我有同样的问题,但似乎在文件名之前放斜杠(“/”)有助于查找,因此,渲染图像,即使它不在与程序相同的目录中。

If you are on Windows the instead of "/hello.bmp" , write "c://hello.bmp" . 如果您使用的是Windows而不是"/hello.bmp" ,请写入"c://hello.bmp" The first one was for Mac. 第一个是Mac。 (: (:

EDIT: Forget it, I just realized it actually doesn't work, it worked for me since I had the file on my disk directory. 编辑:忘记它,我只是意识到它实际上不起作用,它对我有用,因为我有我的磁盘目录上的文件。

确保hello.bmp位于当前目录中,并且它是可读且有效的BMP文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM