本文的环境是基于linux的,ubuntu20.04
1、因为新版本的ART-Pi-smart,改了库的路径,但是里面的一些脚本还没有做同步的更新,所以需要我们手动去修改一下。
先进入ART-Pi-smar在的目录
`gedit userapps/gnu-apps/sdl/build_sdl.sh
此时在重新执行一下
按照那个大佬的文章,里面关于makefile脚本的那一段,在链接库的时候少链接了sdl,所以完全按照那篇文章来执行的话会报错,提示找不到相应的函数定义,还有需要做的改成
![M%W0 MN[V[_BE(M_U6)_TGY.png](.webp "M%W0MN[V[_BE(M_U6)_TGY.png”)
跑一下大佬的程序
自己写的一个mo,本来是想基于这个来控制硬件的,但不知道是啥用rtthread.h头文件会报错,啥用linuxio的方式好似也不行demo,就放弃,实现触摸屏加入会改变屏幕方块的颜色。
#include
#include
#include
extern Uint32 rtt_screen_width;
extern Uint32 rtt_screen_heigth;
static SDL_Rect rect = { 100, 100, 30, 30};
void signalHandler( int signum )
{
printf("Interrupt signal %d received.
", signum);
SDL_Quit();
// exit(signum);
}
int main(void)
{
signal(SIGINT, signalHandler); //ctrl+c signalHandler
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Renderer *renderer;
//use dummy video driver
SDL_setenv("SDL_VIDEODRIVER","rtt",1);
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s
", SDL_GetError() );
return -1;
}
window = SDL_CreateWindow( "Home", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, rtt_screen_width, rtt_screen_heigth, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s
", SDL_GetError() );
return -1;
}
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Surface *surface = SDL_LoadBMP("home.bmp");
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_SetRenderTarget(renderer, texture);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
// SDL_RenderDrawLine(renderer, 0, 0,320, 200);
//SDL_RenderDrawLine(renderer, 320, 0, 320, 480);
// SDL_RenderDrawLines(renderer, points, POINTS_COUNT);
SDL_RenderDrawRect(renderer, &rect);
SDL_RenderPresent(renderer);
while(1)
{
SDL_Event event;
if(SDL_PollEvent(&event) >= 0)
{
if(event.type == SDL_QUIT)
goto end;
else if(event.type == SDL_FINGERDOWN)
{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderDrawRect(renderer, &rect);
SDL_RenderPresent(renderer);
}
else if(event.type == SDL_FINGERUP)
{
SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
SDL_RenderDrawRect(renderer, &rect);
SDL_RenderPresent(renderer);
}
}
}
end:
//destory renderer
if (renderer) {
SDL_DestroyRenderer(renderer);
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0;
}
原作者:毛巾卷
|