Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
ART-Pi Smart
【ART-Pi Smart】基于 SDL2 进行游戏开发
发布于 2022-02-09 09:03:02 浏览:1499
订阅该版
[tocm] ## 前瞻 前文回顾 [【ART-Pi Smart】上手体验以及 vscode 插件使用](https://club.rt-thread.org/ask/article/3267.html) [【ART-Pi Smart】使用 VS Code 开发 GUI 应用](https://club.rt-thread.org/ask/article/3304.html) [【ART-Pi Smart】基于 FFmpeg + SDL2 实现视频播放](https://club.rt-thread.org/ask/article/3332.html) 在上一篇分享中,我们在 ART-Pi Smart 平台上实现了视频解码播放的功能;SDL2 的功能不仅仅局限于图片、视频的播放;得益于 SDL2 丰富的拓展库,开发者可以快速、方便地实现非常多好玩的应用,例如:游戏开发。所以,在本篇文章中,基于 SDL2 以及其拓展库,我们将在 ART-Pi Smart 平台上运行一个好玩的地下城游戏。 ![screenshot.gif](https://oss-club.rt-thread.org/uploads/20220208/e843406463f9e9b3c1e5907a38cad0b0.gif) 这是一位开发者基于 SDL2 和纯 C 语言开发的类似于贪吃蛇的游戏。仓库地址:[rapiz1/DungeonRush: 👾🐍 A opensource game inspired by Snake, written in pure C with SDL (github.com)](https://github.com/rapiz1/DungeonRush) ## 交叉编译 在编译游戏源码之前,我们需要对游戏资源所依赖的 SDL2 的拓展库进行交叉编译,以适配 ART-Pi Smart 开发板; 本次移植的主要耗时就是在各种拓展的交叉编译环境设置上。每一个交叉编译生成的静态库文件都需要进行测试功能是否正常;所以我将此工程所需要的静态库文件以及示例代码放在了仓库 [github ](https://github.com/liukangcc/ART-Pi-Smart)中,如果有需要的小伙伴可以自行下载。 ### FreeType FreeType库是一个完全免费(开源)的、高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件,包括 [TrueType](https://baike.baidu.com/item/TrueType), [OpenType](https://baike.baidu.com/item/OpenType), Type1, CID, [CFF](https://baike.baidu.com/item/CFF), Windows FON/FNT, X11 PCF等 - 下载 ```shell wget https://download.savannah.gnu.org/releases/freetype/freetype-2.11.1.tar.gz ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1NF} $1 APP_NAME="freetype" VERSION="2.11.1" APP_DIR=${APP_NAME}-${VERSION} # default build function builddef() { cd ${APP_DIR} ./autogen.sh ./configure \ --host=${CROSS_COMPILE} \ --build=i686-pc-linux-gnu \ --target=${CROSS_COMPILE} \ --prefix=/home/liukang/repo/sdl_package/freetype_lib \ --enable-static \ LDFLAGS="-L/home/liukang/repo/sdl_package/zlib_lib/lib -L/home/liukang/repo/sdl_package/libpng_lib/lib" \ CPPFLAGS="-I/home/liukang/repo/sdl_package/zlib_lib/include -I/home/liukang/repo/sdl_package/libpng_lib/include" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= freetype install finished. =========" ``` ### zlib zlib是提供[数据压缩](https://baike.baidu.com/item/%E6%95%B0%E6%8D%AE%E5%8E%8B%E7%BC%A9/5198909)用的函式库。 - 下载 ```bash wget https://www.zlib.net/zlib-1.2.11.tar.gz ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1 APP_NAME="zlib" VERSION="1.2.11" APP_DIR=${APP_NAME}-${VERSION} # default build function builddef() { cd ${APP_DIR} ls ./configure \ --prefix=/home/liukang/repo/sdl_package/zlib_lib \ --static make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= zlib install finished. =========" ``` ### libpng libpng 是一款 C 语言编写的比较底层的读写 PNG 文件的跨平台的库。借助它,你可以轻松读写 PNG 文件的每一行像素 - 下载 ```bash wget https://github.com/glennrp/libpng/archive/refs/tags/v1.6.35.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ NF} $1 APP_NAME="libpng" VERSION="1.6.35" APP_DIR=${APP_NAME}-${VERSION} # default build function builddef() { cd ${APP_DIR} ./configure \ --host=${CROSS_COMPILE} \ --build=i686-pc-linux-gnu \ --target=${CROSS_COMPILE} \ --prefix=/home/liukang/repo/sdl_package/libpng_lib \ --enable-static \ --enable-shared=no \ LDFLAGS="-L/home/liukang/repo/sdl_package/zlib_lib/lib" \ CPPFLAGS="-I/home/liukang/repo/sdl_package/zlib_lib/include" \ CFLAG="-fPIC" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= libpng install finished. =========" ``` ### SDL2_GFX SDL2_gfx 库针对 SDL2 的渲染器提供了基本绘图功能,例如线、圆或多边形。 - 下载 ```shell wget https://jaist.dl.sourceforge.net/project/sdl2gfx/SDL2_gfx-1.0.1.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1NF} $1 ROOTDIR="/home/liukang/repo/ART-Pi-smart/userapps" APP_NAME="SDL2_gfx" VERSION="1.0.1" APP_DIR=${APP_NAME}-${VERSION} LIB_DIR=${ROOTDIR}/sdk/lib INC_DIR=${ROOTDIR}/sdk/include RT_DIR=${ROOTDIR}/sdk/rt-thread RT_INC=" -I. -Iinclude -I${ROOTDIR} -I${RT_DIR}/include -I${RT_DIR}/components/dfs -I${RT_DIR}/components/drivers -I${RT_DIR}/components/finsh -I${RT_DIR}/components/net -I${INC_DIR}/sdl -DHAVE_CCONFIG_H" RT_INC+=" -I${ROOTDIR}/../kernel/bsp/imx6ull-artpi-smart/drivers/" export CPPFLAGS=${RT_INC} export LDFLAGS="-L${LIB_DIR} " export LIBS="-T ${ROOTDIR}/linker_scripts/arm/cortex-a/link.lds -march=armv7-a -marm -msoft-float -L${RT_DIR}/lib -Wl,--whole-archive -lrtthread -Wl,--no-whole-archive -n -static -Wl,--start-group -lc -lgcc -lrtthread -Wl,--end-group" # default build function builddef() { cd ${APP_DIR} ./autogen.sh ./configure \ --target=${CROSS_COMPILE} \ --build=i686-pc-linux-gnu \ --host=${CROSS_COMPILE} \ --enable-static \ --enable-shared=no \ --enable-mmx=no make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 ``` - 实机效果 ![image.png](https://oss-club.rt-thread.org/uploads/20220208/796a689e6c74b52e977c7458ed7203fa.jpg.webp) ### SDL2_IMAGE SDL2_image 是图像文件加载库。它将图像加载为 SDL 表面和纹理,并支持以下格式:BMP,GIF,JPEG,LBM,PCX,PNG,PNM,SVG,TGA,TIFF,WEBP,XCF,XPM,XV。 - 下载 ```shell wget https://github.com/libsdl-org/SDL_image/archive/refs/tags/release-2.0.5.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1 APP_NAME="SDL2_image" VERSION="2.0.5" APP_DIR=${APP_NAME}-${VERSION} ROOTDIR="/home/liukang/repo/ART-Pi-smart/userapps" LIB_DIR=${ROOTDIR}/sdk/lib INC_DIR=${ROOTDIR}/sdk/include SDL_DIR=${ROOTDIR}/sdk/include/sdl RT_DIR=${ROOTDIR}/sdk/rt-thread RT_INC="-I${ROOTDIR} -I${RT_DIR}/include -I${RT_DIR}/components/dfs -I${RT_DIR}/components/drivers -I${RT_DIR}/components/finsh -I${RT_DIR}/components/net -I${INC_DIR} -I${SDL_DIR} -DHAVE_CCONFIG_H" RT_INC+=" -I${ROOTDIR}/../kernel/bsp/imx6ull-artpi-smart/drivers/" export CPPFLAGS="${RT_INC}" export LDFLAGS="-L${RT_DIR}/lib -L${LIB_DIR} -L/home/liukang/repo/sdl_package/zlib_lib/lib -L/home/liukang/repo/sdl_package/libpng_lib/lib" export LIBS="-T ${ROOTDIR}/linker_scripts/arm/cortex-a/link.lds -march=armv7-a -marm -msoft-float -Wl,--whole-archive -Wl,--no-whole-archive -n -static -Wl,--start-group -lc -lgcc -Wl,--end-group" # default build function builddef() { cd ${APP_DIR} ./configure \ --prefix=/home/liukang/repo/sdl_package/sdl_image_lib \ --target=${CROSS_COMPILE} \ --host=${CROSS_COMPILE} \ --build=i686-pc-linux-gnu \ --enable-shared=no \ --enable-static \ LIBPNG_CFLAGS="-I/home/liukang/repo/sdl_package/libpng_lib/include -I/home/liukang/repo/sdl_package/zlib_lib/include " \ LIBPNG_LIBS="-lpng16 -lz" \ SDL_CFLAGS="-I${LIB_DIR}" \ SDL_LIBS="-lSDL2 -lrtthread" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi } builddef $1 echo "========= sdl2_image install finished. =========" ``` - 实机效果 ![image.png](https://oss-club.rt-thread.org/uploads/20220208/af6d93907da8a521f28865fc5f171bfa.jpg.webp) ### SDL2_MIXER SDL_mixer 是一个示例多通道音频混音器库。它支持任意数量的同时播放 16 位立体声音频通道,以及由流行的 FLAC、MikMod MOD、Timidity MIDI、Ogg Vorbis 和 SMPEG MP3 库混合的单通道音乐。 - 下载 ```shell wget https://github.com/libsdl-org/SDL_mixer/archive/refs/tags/release-2.0.4.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=${CROSS_COMPILE}-nm APP_NAME="SDL2_mixer" VERSION="2.0.4" APP_DIR=${APP_NAME}-${VERSION} ROOTDIR="/home/liukang/repo/ART-Pi-smart/userapps" LIB_DIR=${ROOTDIR}/sdk/lib INC_DIR=${ROOTDIR}/sdk/include SDL_DIR=${ROOTDIR}/sdk/include/sdl RT_DIR=${ROOTDIR}/sdk/rt-thread RT_INC=" -I. -Iinclude -I${ROOTDIR} -I${RT_DIR}/include -I${RT_DIR}/components/dfs -I${RT_DIR}/components/drivers -I${RT_DIR}/components/finsh -I${RT_DIR}/components/net -I${INC_DIR} -I${SDL_DIR} -DHAVE_CCONFIG_H" RT_INC+=" -I${ROOTDIR}/../kernel/bsp/imx6ull-artpi-smart/drivers/" export CPPFLAGS=${RT_INC} export LDFLAGS="-L${RT_DIR}/lib -L${LIB_DIR} " export LIBS="-T ${ROOTDIR}/linker_scripts/arm/cortex-a/link.lds -march=armv7-a -marm -msoft-float -Wl,--whole-archive -lrtthread -Wl,--no-whole-archive -n -static -Wl,--start-group -lc -lgcc -lrtthread -Wl,--end-group" # default build function builddef() { cd ${APP_DIR} ./configure \ --prefix=/home/liukang/repo/sdl_package/sdl_mixer_lib \ --target=${CROSS_COMPILE} \ --host=${CROSS_COMPILE} \ --build=i686-pc-linux-gnu \ --enable-shared=no \ --disable-music-mod \ --enable-music-cmd=no \ --enable-music-mp3-mad-gpl --enable-music-mp3=no \ --enable-static \ SDL_CFLAGS="-I${LIB_DIR}" \ SDL_LIBS="-lSDL2 -lrtthread" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= sdl2_mixer building finished. =========" ``` ### SDL2_TTF SDL2 本身是没有绘制文字的功能的。但是官方给出了 SDL2_ttf 拓展库,让程序员可以绘制文字。注意 SDL2_ttf 只能够处理ttf文件。 - 下载 ```shell wget https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.0.18/SDL2_ttf-2.0.18.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1NF} $1ONF} $1ONF} $1 APP_NAME="SDL2_ttf" VERSION="2.0.18" APP_DIR=${APP_NAME}-${VERSION} ROOTDIR="/home/liukang/repo/ART-Pi-smart/userapps" LIB_DIR=${ROOTDIR}/sdk/lib INC_DIR=${ROOTDIR}/sdk/include RT_DIR=${ROOTDIR}/sdk/rt-thread SDL_DIR=${ROOTDIR}/sdk/include/sdl RT_INC=" -I. -Iinclude -I${ROOTDIR} -I${RT_DIR}/include -I${RT_DIR}/components/dfs -I${RT_DIR}/components/drivers -I${RT_DIR}/components/finsh -I${RT_DIR}/components/net -I${INC_DIR} -I${SDL_DIR} -DHAVE_CCONFIG_H" RT_INC+=" -I${ROOTDIR}/../kernel/bsp/imx6ull-artpi-smart/drivers/" export CPPFLAGS="${RT_INC} -I/home/liukang/repo/sdl_package/freetype_lib/include/freetype2/freetype -I/home/liukang/repo/sdl_package/zlib_lib/include -I/home/liukang/repo/sdl_package/libpng_lib/include" export LDFLAGS="-L${RT_DIR}/lib -L${LIB_DIR} -L/home/liukang/repo/sdl_package/freetype_lib/lib -L/home/liukang/repo/sdl_package/zlib_lib/lib -L/home/liukang/repo/sdl_package/libpng_lib/lib" export LIBS="-T ${ROOTDIR}/linker_scripts/arm/cortex-a/link.lds -march=armv7-a -marm -msoft-float -Wl,--whole-archive -Wl,--no-whole-archive -n -static -Wl,--start-group -lc -lgcc -Wl,--end-group" # default build function builddef() { cd ${APP_DIR} ./autogen.sh ./configure \ --prefix=/home/liukang/repo/sdl_package/ttf_lib \ --build=i686-pc-linux-gnu \ --host=${CROSS_COMPILE} \ --target=${CROSS_COMPILE} \ --enable-shared=no \ --enable-static \ SDL_CFLAGS="-I${LIB_DIR}" \ SDL_LIBS="-lSDL2 -lrtthread -lfreetype -lz -lpng16" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= sdl2_ttf install finished. =========" ``` - 实机效果 ![image.png](https://oss-club.rt-thread.org/uploads/20220208/8998ac095d5f554039d62a49a756b199.jpg.webp) ### SDL2_NET 这是一个小型跨平台网络库示例,带有示例聊天客户端和服务器应用程序。聊天客户端使用 GUIlib GUI 框架库 - 下载 ```shell wget https://github.com/libsdl-org/SDL_net/archive/refs/tags/release-2.0.1.zip ``` - 交叉编译 ```bash #!/bin/bash export RTT_EXEC_PATH=/home/liukang/repo/ART-Pi-smart/tools/gnu_gcc/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin export PATH=$PATH:$RTT_EXEC_PATH:$RTT_EXEC_PATH/../arm-linux-musleabi/bin export CROSS_COMPILE="arm-linux-musleabi" if [ "$1" == "debug" ]; then export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O0 -g -gdwarf-2 -Wall -n --static" else export CFLAGS="-march=armv7-a -marm -msoft-float -D__RTTHREAD__ -O2 -Wall -n --static" fi export AR=${CROSS_COMPILE}-ar export AS=${CROSS_COMPILE}-as export LD=${CROSS_COMPILE}-ld export RANLIB=${CROSS_COMPILE}-ranlib export CC=${CROSS_COMPILE}-gcc export CXX=${CROSS_COMPILE}-g++ export NM=$NF} $1NF} $1ONF} $1 APP_NAME="SDL2_net" VERSION="2.0.1" APP_DIR=${APP_NAME}-${VERSION} ROOTDIR="/home/liukang/repo/ART-Pi-smart/userapps" LIB_DIR=${ROOTDIR}/sdk/lib INC_DIR=${ROOTDIR}/sdk/include RT_DIR=${ROOTDIR}/sdk/rt-thread SDL_DIR=${ROOTDIR}/sdk/include/sdl RT_INC=" -I. -Iinclude -I${ROOTDIR} -I${RT_DIR}/include -I${RT_DIR}/components/dfs -I${RT_DIR}/components/drivers -I${RT_DIR}/components/finsh -I${RT_DIR}/components/net -I${INC_DIR} -I${SDL_DIR} -DHAVE_CCONFIG_H" RT_INC+=" -I${ROOTDIR}/../kernel/bsp/imx6ull-artpi-smart/drivers/" export CPPFLAGS=${RT_INC} export LDFLAGS="-L${RT_DIR}/lib -L${LIB_DIR} " export LIBS="-T ${ROOTDIR}/linker_scripts/arm/cortex-a/link.lds -march=armv7-a -marm -msoft-float -Wl,--whole-archive -Wl,--no-whole-archive -n -static -Wl,--start-group -lc -lgcc -Wl,--end-group" # default build function builddef() { cd ${APP_DIR} ./autogen.sh ./configure \ --prefix=/home/liukang/repo/sdl_package/sdl_net_lib \ --build=i686-pc-linux-gnu \ --host=${CROSS_COMPILE} \ --target=${CROSS_COMPILE} \ --enable-static \ --enable-shared=no \ --enable-gui=no \ SDL_CFLAGS="-I${LIB_DIR}" \ SDL_LIBS="-lSDL2 -lrtthread" make clean if [ "$1" == "verbose" ]; then make V=1 else make fi make install } builddef $1 echo "========= sdl2_net install finished. =========" ``` ## 游戏 Demo ### 创建工程 1. 使用 git 工具 clone 游戏源码: `git clone https://github.com/rapiz1/DungeonRush.git` 2. 使用 RT-Thread Smart VS Code 插件创建 make 工程; 3. 修改 Makefile 文件,添加静态库文件和路径: ```makefile VERSION = 1.0.0 CROSS_COMPILE = arm-linux-musleabi- CC = $(CROSS_COMPILE)gcc CP = $(CROSS_COMPILE)objcopy CXX = $(CROSS_COMPILE)g++ SZ = $(CROSS_COMPILE)size HEX = $(CP) -O ihex BIN = $(CP) -O binary -S # project 根路径 PROJECT_DIR := $(shell pwd) # userapps 根路径 UROOT_DIR = $(PROJECT_DIR)/../.. # rt-thread 路径 RT_DIR = $(UROOT_DIR)/sdk/rt-thread INC_DIR =$(UROOT_DIR)/sdk/rt-thread/include LIB_DIR = ${UROOT_DIR}/sdk/rt-thread/lib # SDL2 path SDL2_DIR=$(UROOT_DIR)/build/SDL2 # zlib path ZLIB_DIR=${UROOT_DIR}/build/zlib # freetype path FREETYPE_DIR=${UROOT_DIR}/build/freetype #libpng path LIBPNG_DIR=$(UROOT_DIR)/build/libpng # SDL2_image PATH SDL2_IMAGE_DIR=$(UROOT_DIR)/build/SDL2_image # SDL2_TTF PATH SDL2_TTF_DIR=$(UROOT_DIR)/build/SDL2_ttf # SDL2_GFX PATH SDL2_GFX_DIR=$(UROOT_DIR)/build/SDL2_gfx # SDL2_NET PATH SDL2_NET_DIR=$(UROOT_DIR)/build/SDL2_net # SDL2_MIXER PATH SDL2_MIXER_DIR=$(UROOT_DIR)/build/SDL2_mixer # GAME_PATH GAME_DIR=${PROJECT_DIR}/src # 配置编译参数 CFLAGS = -march=armv7-a -marm -msoft-float -D__RTTHREAD__ -Wall -Ofast -g -gdwarf-2 -n --static # 加入头文件搜索路径 CFLAGS += -I. -I$(UROOT_DIR) -I$(PROJECT_DIR) -I$(RT_DIR)/components/dfs -I$(RT_DIR)/components/drivers -I$(RT_DIR)/components/finsh -I$(RT_DIR)/components/net -I$(RT_DIR)/components/net/netdev -I$(RT_DIR)/components/net/arpa -I${INC_DIR} CFLAGS += -I${INC_DIR}/libc -I${INC_DIR}/sys -I${SDL2_DIR}/include/SDL2 -I${LIBPNG_DIR}/include/libpng16 -I${SDL2_IMAGE_DIR}/include/SDL2 -I${FREETYPE_DIR}/include/freetype2/freetype CFLAGS += -I${ZLIB_DIR}/include -I${SDL2_TTF_DIR}/include -I${SDL2_GFX_DIR}/include/SDL2 -I${SDL2_NET_DIR}/include -I${SDL2_MIXER_DIR}/include -I${GAME_DIR} # 加入链接文件 LDFLAGS = -march=armv7-a -marm -msoft-float -T ${UROOT_DIR}/linker_scripts/arm/cortex-a/link.lds # 加入库文件 LDFLAGS += -L${SDL2_DIR}/lib -L${ZLIB_DIR}/lib -L${LIBPNG_DIR}/lib -L${FREETYPE_DIR}/lib -L${SDL2_IMAGE_DIR}/lib -L${SDL2_TTF_DIR}/lib -L${SDL2_GFX_DIR}/lib -L${SDL2_MIXER_DIR}/lib -L${SDL2_NET_DIR}/lib -L${SDL2_MIXER_DIR}/lib -L$(LIB_DIR) -Wl,--whole-archive -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_net -lrtthread -lpng16 -lfreetype -lz -Wl,--no-whole-archive -n --static -Wl,--start-group -lrtthread -lSDL2 -lSDL2_ttf -lSDL2_image -lSDL2_mixer -lSDL2_net -lpng16 -lfreetype -lz -Wl,--end-group BUILD_DIR = build TARGET = DungeonRush # C sources C_SOURCES = \ src/ai.c \ src/audio.c \ src/bullet.c \ src/game.c \ src/helper.c \ src/main.c \ src/map.c \ src/net.c \ src/player.c \ src/prng.c \ src/render.c \ src/res.c \ src/sprite.c \ src/storage.c \ src/types.c \ src/ui.c \ src/weapon.c OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) vpath %.c $(sort $(dir $(C_SOURCES))) # default action: build all all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) $(AS) -c $(CFLAGS) $< -o $@ $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile $(CC) $(OBJECTS) $(LDFLAGS) -o $@ $(SZ) $@ hex: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) $(HEX) $< $@ bin: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) $(BIN) $< $@ $(BUILD_DIR): mkdir $@ clean: -rm -fR $(BUILD_DIR) .PHONY: default clean ``` ### 修改源码 在编译工程前,需要对部分源码进行修改。 1. 修改屏幕大小以适配 ART-Pi Smart 的显示屏 ![Snipaste_2022-02-08_13-53-11.png](https://oss-club.rt-thread.org/uploads/20220208/9e209a4d8398ebff8e09f9f306d9d4cc.png) 2. 屏蔽关于音频的代码;由于 ART-Pi Smart 开发板没有音频模块,所以,关于这部分代码,需要进行处理: ![Snipaste_2022-02-08_13-59-14.png](https://oss-club.rt-thread.org/uploads/20220208/4a97abf3998f7e645653e69e4c35c650.png.webp) ![Snipaste_2022-02-08_14-00-07.png](https://oss-club.rt-thread.org/uploads/20220208/cbd9da15a9a51acfa56df4799fbf79ed.png.webp) ### 编译工程 点击 VS Code 插件上的编译按钮,编译工程: ![Snipaste_2022-02-08_11-40-12.png](https://oss-club.rt-thread.org/uploads/20220208/d4272f7fa9530e30e735e055f545c078.png) ### 下载工程 将生成的 DungeonRush.elf 文件和 res 文件夹放入 sd 卡中,并插入到 ART-Pi Smart 开发板上,重启开发板。 ### 运行工程 ![Snipaste_2022-02-08_13-43-54.png](https://oss-club.rt-thread.org/uploads/20220208/1156a4aa3a1343c2012435f0495f52db.png) ### 效果展示 由于原始图片资源尺寸问题,所以移植到 ART-Pi Smart 开发板上时,显示会有问题,但整体功能上还是正常的: ![微信图片_20220208134332.jpg](https://oss-club.rt-thread.org/uploads/20220208/8c3fe39c41c806bc9357aa4b184ffb9e.jpg.webp) RT-Smart 交流平台 如果遇到什么问题需要协助,或有什么建议和意见需要反馈的,可以加入 ART-Pi Smart 官方交流 QQ 群或者登录论坛的 rt-smart 板块发帖反馈。 ART-Pi Smart : https://art-pi.gitee.io/smart-website/ ART-Pi Smart SDK : https://gitee.com/rtthread/ART-Pi-smart ART-Pi Smart 官方交流 QQ 群 :622828244 rt-smart 论坛板块(发帖反馈): https://club.rt-thread.org/ask/tag/1339.html
1
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
Papalymo
请勿打扰
文章
25
回答
85
被采纳
17
关注TA
发私信
相关文章
1
求助vscode开发art-pi smart开发板的问题
2
vscode下载rt-smart用户态代码时udb有问题
3
RGB565 显示图片异常
4
浮点数打印,从内核态直接打印和从用户态访问设备再触发打印,效果不一致
5
csi 开启 DMA_REQ_EN_RFF 前提下,开启 CSI 就卡住无打印
6
求助如何移植rt-thread到野火imx6ull开发板上
7
RT-thread smart 用户态程序运行出错
8
art-pi-smart 编译报错
9
ART-PI Smart User 运行LED 程序崩溃
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
freemodbus
PWM
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
中断
编译报错
Debug
SFUD
rt_mq_消息队列_msg_queue
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
a1012112796
10
个答案
1
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
YZRD
2
篇文章
5
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
Woshizhapuren
1
篇文章
5
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部