首页 > 解决方案 > 来自 ssh 会话的 pygame:如何在附加屏幕上显示?

问题描述

我想在 raspi 上使用 pygame 在连接到 raspi 的 hdmi 端口的屏幕​​上显示图片。我想通过 ssh 连接来做到这一点。

作为第一个测试,我尝试了测试可用驱动程序的非常基本(和经典)的脚本:

import os
import pygame

disp_no = os.getenv('DISPLAY')
print("I'm running under {}".format(disp_no))

drivers = ['directfb', 'fbcon', 'svgalib']

found = False
for driver in drivers:
    if not os.getenv('SDL_VIDEODRIVER'):
        os.putenv('SDL_VIDEODRIVER', driver)
        os.environ["SDL_FBDEV"] = "/dev/fb0"
    try:
        pygame.display.init()
        print('OK with',driver)
    except pygame.error:
        print('Driver: {0} failed.'.format(driver))
        continue
    found = True
    break

if not found:
   raise Exception('No suitable video driver found!')

这是我的测试结果:

  1. 来自 ssh 会话:找不到合适的视频驱动程序
  2. 以 root 身份从 ssh 会话:使用 directfb 可以
  3. 从 tty 控制台(使用连接到 raspi 的键盘):使用 directfb 可以

我的问题是:为什么情况 1 会导致失败。我想念什么,我该怎么办?

请注意 /dev/fb0 和所有 /dev/tty 的权限??设置为我可以在没有 root 的情况下读/写。另请注意,我没有运行 X 服务器。

标签: sshpygameraspbianframebuffertty

解决方案


推荐阅读