前言
前几篇我们体验了使用ffmpeg进行多媒体开发,本篇使用SDL来进行GUI相关的应用开发。通过加载位图显示的Demo来演示。构建
下载源码https://github.com/libsdl-org/SDL/releases/
https://github.com/libsdl-org/SDL/releases/download/release-2.26.4/SDL2-2.26.4.tar.gz解压tar -xvf SDL2-2.26.4.tar.gz进入工作目录cd SDL2-2.26.4/创建目录mkdir build配置./configure --prefix=$PWD/build构建安装make && make install编译完如下:
Build下生成4个文件夹bin share lib include生成的库文件位于build/lib头文件位于build/include/SDL2/
测试vi /etc/profile添加export C_INCLUDE_PATH=/root/SDL2-2.26.4/build/include/SDL2:$C_INCLUDE_PATHexport LIBRARY_PATH=/root/SDL2-2.26.4/build/lib:$LIBRARY_PATHexport LD_LIBRARY_PATH=/root/SDL2-2.26.4/build/lib:$LD_LIBRARY_PATH source /etc/profile创建源文件内容如下sdltest.c#include
#include
int main(int argc, char* argv[])
{
/* 初始化SDL */
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("SDL_Init Error %s.n", SDL_GetError());
return 1;
}
/* 打开窗口 */
SDL_Window *win = SDL_CreateWindow("Hello World", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if(win == NULL)
{
printf("SDL_CreateWindow Error %s.n",SDL_GetError());
SDL_Quit();
return 1;
}
/* 创建渲染器 */
SDL_Renderer *ren = SDL_CreateRenderer(win , -1, SDL_RENDERER_SOFTWARE);
if(ren == NULL)
{
SDL_DestroyWindow(win);
printf("SDL_CreateRenderer Error %s.n",SDL_GetError());
SDL_Quit();
return 1;
}
/* 加载位图图像 */
SDL_Surface *bmp = SDL_LoadBMP("hello.bmp");
if(bmp == NULL)
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
printf("SDL_LoadBMP Error %s.n",SDL_GetError());
SDL_Quit();
return 1;
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
if (tex == NULL)
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
printf("SDL_CreateTextureFromSurface Error %s.n",SDL_GetError());
SDL_Quit();
return 1;
}
//A sleepy rendering loop, wait for 3 seconds and render and present the screen each time
for (int i = 0; i < 3; ++i)
{
//First clear the renderer
SDL_RenderClear(ren);
//Draw the texture
SDL_RenderCopy(ren, tex, NULL, NULL);
//Update the screen
SDL_RenderPresent(ren);
//Take a quick break after all that hard work
SDL_Delay(1000);
}
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
运行./sdltest可以看到加载显示了位图
总结从以上可以看出,直接在开发板构建SDL,并进行应用编译开发,非常方便。所以使用本开发板可以任意选择各种技术栈进行开发,在进行多媒体终端开发时也有多种选择,非常方便,这得益于开发板运行完整的ubuntu系统和强劲的性能。
我要赚赏金
