1. 测试是否安装成功
#include "SDL/SDL.h"
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
编译命令:
g++ main.c -o main -lSDL
如果程序能够编译通过并能够运行,那么SDL安装成功。
2. 加载一张图片
#include <stdio.h>
#include <SDL/SDL.h>
int main()
{
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
//Load image
hello = SDL_LoadBMP( "1.bmp" );
//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );
//Update Screen
SDL_Flip( screen );
//Pause
SDL_Delay( 5000 );
//Quit SDL
SDL_Quit();
//Free memory
SDL_FreeSurface( hello );
//Quit SDL
SDL_Quit();
return 0;
}
下载测试图片:
wget http://www.5ichai.com/1.bmp
编译命令:
g++ main1.c -o main -lSDL
3. 运行测试
win7 SSH 联机可以执行,但不太正常,本机下执行正常。