我希望开发一些使用SDL2在7英寸RPi触摸屏上显示图形的代码,但我不想安装完整的桌面操作系统。我已经安装了Raspbian Buster Lite。当我尝试运行一些简单的测试代码时,会出现错误:
user@rpi4:~/01_hello_SDL $ ./hw
Window could not be created! SDL_Error: Could not initialize EGL
user@rpi4:~/01_hello_SDL $ sudo ./hw
error: XDG_RUNTIME_DIR not set in the environment.
Window could not be created! SDL_Error: Could not initialize EGL
我正在尝试创建窗口
SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL )
我找到了一篇文章,其中提到了如何在不使用X的情况下构建SDL2的说明,但是我希望有人可以更详细地告诉我SDL在各种环境中如何找到显示器,以及是否可能做到我想要做的事情。
几年前,我使用SDL 1.2在运行Debian版本的Beaglebone Black上进行全屏图形处理,但是我似乎已经失去了那个安装文件,并且不记得它是如何设置的。我依稀记得在fbdev周围存在一些问题,它不是加速图形,但那时无关紧要(尽管我现在希望获得加速图形,但这并不是关键)。
示例代码:
/*This source code copyrighted by Lazy Foo' Productions (2004-2019)
and may not be redistributed without written permission.*/
//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 480;
int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Wait two seconds
SDL_Delay( 2000 );
}
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0;
}
fb
设备,并在不到1毫秒的时间内更新整个1024x768屏幕... 在Raspi 4上,fb
设备会自动以“DRM模拟”方式启动,无需进行任何特殊操作。 - Mark Setchell