【发布时间】:2013-11-18 02:32:50
【问题描述】:
IDE:代码::块 编译器:MinGW
我正确安装了 SDL 和 SDL_image(它在构建时不会出现任何错误)。 一切都编译得很好,但是当我运行它时,会出现 SDL 窗口,但图像从不闪烁,窗口。我使用 SDL_image,所以我可以加载 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;
}
【问题讨论】:
-
添加一些错误检查,看看
IMG_Load调用是否成功。 -
如果不是,请致电
SDL_GetError找出问题所在。
标签: c++ mingw sdl codeblocks sdl-image