Linux 下SDL2 image安装及使用

1. 安装SDL image 2.0

sudo apt-get install libsdl2-image-dev

如果没有安装过SDL2 ,应该会自动安装,也可以自己安装

sudo apt-get install libsdl2-dev

2. 测试,创建test,c,键入如下代码

#include 
#include 

int main()
{
	SDL_Window* window =0;
	SDL_Renderer* render=0;
	SDL_Texture *texture=0;
	SDL_Rect src,dst;
	int width,height;
	SDL_Init(SDL_INIT_EVERYTHING);
	window=SDL_CreateWindow("hello",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN);
	render=SDL_CreateRenderer(window,-1,0);
	texture=IMG_LoadTexture(render,"tux.jpg");
	SDL_QueryTexture(texture,NULL,NULL,&width,&height);
	src.x=src.y=0;
	src.w=width;
	src.h=height;
	dst.x=30;
	dst.y=20;
	dst.w=width/2;
	dst.h=height/2;
	SDL_SetRenderDrawColor(render,0,0,0,255);
	SDL_RenderClear(render);
	SDL_RenderCopy(render,texture,&src,&dst);
	SDL_RenderPresent(render);
	SDL_Delay(3000);
	SDL_DestroyWindow(window);
	SDL_DestroyRenderer(render);
	SDL_Quit();
	return 0;
}

4.编译

gcc test.c -lSDL2 -lSDL2_image
编译成功,在当前目录下生成a.out可执行文件

5,测试

弄张图片命名为tux.jpg 放到该目录下

执行 ./a.out 

Linux 下SDL2 image安装及使用_第1张图片



你可能感兴趣的:(SDL)