我希望开发一些使用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 )
我找到了一个post,它引用了有关如何在不使用X的情况下构建SDL2的说明,但我希望有人能教我更多关于SDL如何在各种环境中找到显示器的信息,以及它是否有可能做我想做的事情。
几年前,我曾使用SDL 1.2在Beaglebone Black上运行Debian版本来制作全屏图形,但我似乎丢失了安装,也不记得它是如何设置的。我隐约记得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;
}
1条答案
按热度按时间lh80um4z1#
好了,让它在我的树莓派3与
2019-07-10-raspbian-buster-lite.img
工作,都与默认的Broadcom blobs和KMS/DRM后端:1.安装SDL 2建置相依性:
1.从Git获取最新的稳定SDL source tarball或标签(
release-2.0.10
),并将其提取到类似~/sdl-src
的位置1.运行SDL的
configure
脚本:下面是我的
configure
总结:请注意
Video drivers
列表中的rpi
和kmsdrm(dynamic)
条目:1.建置并安装SDL;在我的Rpi 3上花了大约4.5分钟:
1.构建测试程序:
1.(可选)如果要使用KMSDRM后端而不是默认的OpenGL ES blob,请启用“Full KMS”驱动程序:
1.运行测试程序:
可以使用环境变量覆盖默认的视频/渲染驱动程序选择:
我不得不用envars来帮助SDL加载KMSDRM后端:
下面是我一直在使用的测试程序: