Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;SDL,SDL_图像问题_C++_Mingw_Sdl_Codeblocks_Sdl Image - Fatal编程技术网

C++ C++;SDL,SDL_图像问题

C++ C++;SDL,SDL_图像问题,c++,mingw,sdl,codeblocks,sdl-image,C++,Mingw,Sdl,Codeblocks,Sdl Image,IDE:代码::块 编译程序:MinGW 我已经正确安装了SDL和SDL_映像(构建时不会出现任何错误)。 一切都编译得很好,但当我运行它时,SDL窗口会出现,但图像永远不会闪烁,窗口。我使用SDL_图像以便加载PNG图像(或者我希望如此) 守则: #include <cstdlib> #include <iostream> #include "SDL_image.h" #include <SDL/SDL.h> int main ( int argc, ch

IDE:代码::块 编译程序:MinGW

我已经正确安装了SDL和SDL_映像(构建时不会出现任何错误)。 一切都编译得很好,但当我运行它时,SDL窗口会出现,但图像永远不会闪烁,窗口。我使用SDL_图像以便加载PNG图像(或者我希望如此)

守则:

#include <cstdlib>
#include <iostream>
#include "SDL_image.h"
#include <SDL/SDL.h>

int main ( int argc, char** argv )
{
    SDL_Surface* test = NULL;
    SDL_Surface* screen = NULL;
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Name the window
    SDL_WM_SetCaption( "Test-1", NULL );
    //Set up screen
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

    //Load image
    test = IMG_Load("Test.png");
    //Apply image to screen
    SDL_BlitSurface( test, NULL, screen, NULL );
    //Update Screen
    SDL_Flip( screen );

    //Pause
    SDL_Delay( 2000 );
    //Free the loaded image
    SDL_FreeSurface( test );

    //Quit SDL
    SDL_Quit();

    return 0;
}
#包括
#包括
#包括“SDL_image.h”
#包括
int main(int argc,字符**argv)
{
SDL_表面*测试=NULL;
SDL_表面*屏幕=空;
//启动SDL
SDL_Init(SDL_Init_EVERYTHING);
//命名窗口
SDL_WM_SetCaption(“测试-1”,空);
//设置屏幕
屏幕=SDL_设置视频模式(640、480、32、SDL_表面);
//加载图像
测试=IMG_载荷(“test.png”);
//将图像应用于屏幕
SDL_BlitSurface(测试、空、屏幕、空);
//更新屏幕
SDL_翻转(屏幕);
//停顿
SDL_延迟(2000年);
//释放加载的图像
SDL_自由曲面(测试);
//退出SDL
SDL_退出();
返回0;
}

也许你可以先创建一个窗口,然后创建一个曲面,然后通过曲面将图像拼接到窗口上?然后您可以尝试使用此功能:
SDL\u更新Windows界面(*windowinstance*)


这里有更多信息:(虽然这是加载一个*.bmp文件,但我相信概念是一样的)。也可以尝试上面提到的答案。可能只是找不到图像…

添加一些错误检查以查看
IMG\u Load
调用是否成功。如果没有成功,请调用
SDL\u GetError
以查找问题。